吴裕雄--天生自然深度学习TensorBoard可视化:projector_MNIST
摘要:import os import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data from tensorflow.contrib.tensorboard.plugins import projector INPUT_NODE = 784 OUTPUT_NODE = 10 LAYER1_NODE
阅读全文
吴裕雄--天生自然深度学习TensorBoard可视化:命名空间
摘要:# 1. 不同的命名空间。 import tensorflow as tf with tf.variable_scope("foo"): a = tf.get_variable("bar", [1]) print(a.name) with tf.variable_scope("bar"): b = tf.get_variable("bar", [1]) pri...
阅读全文
吴裕雄--天生自然TensorFlow高层封装:Estimator-自定义模型
摘要:# 1. 自定义模型并训练。 import numpy as np import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data tf.logging.set_verbosity(tf.logging.INFO) def lenet(x, is_training): x = tf.reshape
阅读全文
吴裕雄--天生自然TensorFlow高层封装:Estimator-DNNClassifier
摘要:# 1. 模型定义。 import numpy as np import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data tf.logging.set_verbosity(tf.logging.INFO) mnist = input_data.read_data_sets("F:\\Tensor
阅读全文
吴裕雄--天生自然TensorFlow高层封装:Keras-TensorFlow API
摘要:# 1. 模型定义。 import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data mnist_data = input_data.read_data_sets('F:\\TensorFlowGoogle\\201806-github\\datasets\\MNIST_data', one_...
阅读全文
吴裕雄--天生自然TensorFlow高层封装:Keras-多输入输出
摘要:# 1. 数据预处理。 import keras from keras.models import Model from keras.datasets import mnist from keras.layers import Input, Dense from tflearn.layers.core import fully_connected num_classes = 10 img_ro...
阅读全文
吴裕雄--天生自然TensorFlow高层封装:Keras-返回值
摘要:# 1. 数据预处理。 import keras from keras.models import Model from keras.datasets import mnist from keras.layers import Input, Dense from tflearn.layers.core import fully_connected num_classes = 10 img_ro...
阅读全文
吴裕雄--天生自然TensorFlow高层封装:Keras-RNN
摘要:# 1. 数据预处理。 from keras.layers import LSTM from keras.datasets import imdb from keras.models import Sequential from keras.preprocessing import sequence from keras.layers import Dense, Embedding max_fea
阅读全文
吴裕雄--天生自然TensorFlow高层封装:Keras-CNN
摘要:# 1. 数据预处理 import keras from keras import backend as K from keras.datasets import mnist from keras.models import Sequential from keras.layers import Dense, Flatten, Conv2D, MaxPooling2D num_classes =
阅读全文
吴裕雄--天生自然TensorFlow高层封装:使用TFLearn处理MNIST数据集实现LeNet-5模型
摘要:# 1. 通过TFLearn的API定义卷机神经网络。 import tflearn import tflearn.datasets.mnist as mnist from tflearn.layers.conv import conv_2d, max_pool_2d from tflearn.layers.estimator import regression from tflearn.laye
阅读全文
吴裕雄--天生自然TensorFlow高层封装:使用TensorFlow-Slim处理MNIST数据集实现LeNet-5模型
摘要:# 1. 通过TensorFlow-Slim定义卷机神经网络 import numpy as np import tensorflow as tf import tensorflow.contrib.slim as slim from tensorflow.examples.tutorials.mnist import input_data # 通过TensorFlow-Slim来定义LeN...
阅读全文
吴裕雄--天生自然 pythonTensorFlow自然语言处理:Attention模型--测试
摘要:import sys import codecs import tensorflow as tf # 1.参数设置。 # 读取checkpoint的路径。9000表示是训练程序在第9000步保存的checkpoint。 CHECKPOINT_PATH = "F:\\temp\\attention_ckpt-9000" # 模型参数。必须与训练时的模型参数保持一致。 HIDDEN_SIZE =...
阅读全文
吴裕雄--天生自然 pythonTensorFlow自然语言处理:Seq2Seq模型--训练
摘要:import tensorflow as tf # 1.参数设置。 # 假设输入数据已经用9.2.1小节中的方法转换成了单词编号的格式。 SRC_TRAIN_DATA = "F:\\TensorFlowGoogle\\201806-github\\TensorFlowGoogleCode\\Chapter09\\train.en" # 源语言输入文件。 TRG_TRAIN_DAT...
阅读全文
吴裕雄--天生自然 pythonTensorFlow自然语言处理:PTB 语言模型
摘要:import numpy as np import tensorflow as tf # 1.设置参数。 TRAIN_DATA = "F:\TensorFlowGoogle\\201806-github\\TensorFlowGoogleCode\\Chapter09\\ptb.train" # 训练数据路径。 EVAL_DATA = "F:\TensorFlowGoogle...
阅读全文
吴裕雄--天生自然 pythonTensorFlow自然语言处理:文本数据预处理--生成训练文件
摘要:import sys import codecs # 1. 参数设置 MODE = "PTB_TRAIN" # 将MODE设置为"PTB_TRAIN", "PTB_VALID", "PTB_TEST", "TRANSLATE_EN", "TRANSLATE_ZH"之一。 if MODE == "PTB_TRAIN": # PTB训练数据 RAW_DATA = "F:\\TensorFlowGoog
阅读全文
吴裕雄--天生自然 pythonTensorFlow自然语言处理:文本数据预处理--生成词汇表
摘要:import codecs import collections from operator import itemgetter # 1. 设置参数。 MODE = "PTB" # 将MODE设置为"PTB", "TRANSLATE_EN", "TRANSLATE_ZH"之一。 if MODE == "PTB": # PTB数据处理 RAW_DATA =...
阅读全文
吴裕雄--天生自然 pythonTensorFlow自然语言处理:交叉熵损失函数
摘要:import tensorflow as tf # 1. sparse_softmax_cross_entropy_with_logits样例。 # 假设词汇表的大小为3, 语料包含两个单词"2 0" word_labels = tf.constant([2, 0]) # 假设模型对两个单词预测时,产生的logit分别是[2.0, -1.0, 3.0]和[1.0, 0.0, -0.5] pr...
阅读全文
吴裕雄--天生自然 Tensorflow卷积神经网络:花朵图片识别
摘要:import os import numpy as np import matplotlib.pyplot as plt from PIL import Image, ImageChops from skimage import color,data,transform,io #获取所有数据文件夹名称 fileList = os.listdir("F:\\data\\flowers") tra...
阅读全文
吴裕雄--天生自然 神经网络人工智能项目:基于深度学习TensorFlow框架的图像分类与目标跟踪报告(续三)
摘要:1、再次认真思考之后,不再将图片灰度化,图片的通道数仍然保持是3,为了加快运行的速度,并且相应地把图片的尺寸改成了32*32。为了节省时间这里也加入了TensorBoard可视化代码。具体代码如下: 代码运行结果如下(部分输出): 可以看到现在代码的结果非常好了,训练准确率也明显高出了许多,达到了9
阅读全文