import tensorflow as tf def _int64_feature(value): return tf.train.Feature(int64_list=tf.train.Int64List(value=[value])) num_shards = 2 instances_per_shard = 2 for i in range(num_shards): filename = ('E:\\temp\\data.tfrecords-%.5d-of-%.5d' % (i, num_…
import tensorflow as tf queue = tf.FIFOQueue(100,"float") enqueue_op = queue.enqueue([tf.random_normal([1])]) qr = tf.train.QueueRunner(queue, [enqueue_op] * 5) tf.train.add_queue_runner(qr) out_tensor = queue.dequeue() with tf.Session() as sess…
import tensorflow as tf q = tf.FIFOQueue(2, "int32") init = q.enqueue_many(([0, 10],)) x = q.dequeue() y = x + 1 q_inc = q.enqueue([y]) with tf.Session() as sess: init.run() for _ in range(5): v, _ = sess.run([x, q_inc]) print(v) import time imp…
#加载TF并导入数据集 import tensorflow as tf from tensorflow.contrib import rnn from tensorflow.examples.tutorials.mnist import input_data mnist = input_data.read_data_sets("E:\\MNIST_data\\", one_hot=True) #设置训练的超参数,学习率 训练迭代最大次数,输入数据的个数 learning_rate= 0…
import tensorflow as tf import numpy as np from tensorflow.examples.tutorials.mnist import input_data #设置输入参数 batch_size = 128 test_size = 256 # 初始化权值与定义网络结构,建构一个3个卷积层和3个池化层,一个全连接层和一个输出层的卷积神经网络 # 首先定义初始化权重函数 def init_weights(shape): return tf.Variabl…
#训练过程的可视化 ,TensorBoard的应用 #导入模块并下载数据集 import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data #设置超参数 max_step=1000 learning_rate=0.001 dropout=0.9 # 用logdir明确标明日志文件储存路径 #训练过程中的数据储存在E:\\MNIST_data\\目录中,通过这个路径指定--log_dir data…
import numpy as np import tensorflow as tf import matplotlib.pyplot as plt def add_layer(inputs, in_size, out_size, activation_function = None): #构建权重: in_sizeXout_size大小的矩阵 weights = tf.Variable(tf.random_normal([in_size, out_size]))#生成随机数 #构建偏置: 1X…
import numpy as np import tensorflow as tf import matplotlib.pyplot as plt def distort_color(image, color_ordering=0): ''' 随机调整图片的色彩,定义两种处理顺序. ''' if color_ordering == 0: image = tf.image.random_brightness(image, max_delta=32./255.) image = tf.image.…
import tensorflow as tf tf.reset_default_graph() # 配置神经网络的参数 INPUT_NODE = 784 OUTPUT_NODE = 10 IMAGE_SIZE = 28 NUM_CHANNELS = 1 NUM_LABELS = 10 # 第一层卷积层的尺寸和深度 CONV1_DEEP = 32 CONV1_SIZE = 5 # 第二层卷积层的尺寸和深度 CONV2_DEEP = 64 CONV2_SIZE = 5 # 全连接层的节点个数 FC…
import tensorflow as tf from tensorflow.python.framework import graph_util v1 = tf.Variable(tf.constant(1.0, shape=[1]), name = "v1") v2 = tf.Variable(tf.constant(2.0, shape=[1]), name = "v2") result = v1 + v2 init_op = tf.global_varia…
import tempfile import tensorflow as tf train_files = tf.train.match_filenames_once("E:\\output.tfrecords") test_files = tf.train.match_filenames_once("E:\\output_test.tfrecords") # 解析一个TFRecord的方法. def parser(record): features = tf.pa…
import tensorflow as tf files = tf.train.match_filenames_once("E:\\MNIST_data\\output.tfrecords") filename_queue = tf.train.string_input_producer(files, shuffle=False) # 读取文件. reader = tf.TFRecordReader() _,serialized_example = reader.read(filen…
import numpy as np import tensorflow as tf import matplotlib.pyplot as plt def distort_color(image, color_ordering=0): if color_ordering == 0: image = tf.image.random_brightness(image, max_delta=32./255.) image = tf.image.random_saturation(image, low…
# -*- coding: utf-8 -*- import glob import os.path import numpy as np import tensorflow as tf from tensorflow.python.platform import gfile import tensorflow.contrib.slim as slim import tensorflow.contrib.slim.python.slim.nets.inception_v3 as inceptio…
import glob import os.path import numpy as np import tensorflow as tf from tensorflow.python.platform import gfile import tensorflow.contrib.slim as slim # 因为slim.nets包在 tensorflow 1.3 中有一些问题,所以这里为了方便 # 我们将slim.nets.inception_v3中的代码拷贝到了同一个文件夹下. # imp…
import glob import os.path import numpy as np import tensorflow as tf from tensorflow.python.platform import gfile # 原始输入数据的目录,这个目录下有5个子目录,每个子目录底下保存这属于该 # 类别的所有图片. INPUT_DATA = 'F:\\TensorFlowGoogle\\201806-github\\datasets\\flower_photos\\' # 输出文件地址…
import glob import os.path import numpy as np import tensorflow as tf from tensorflow.python.platform import gfile # 原始输入数据的目录,这个目录下有5个子目录,每个子目录底下保存这属于该 # 类别的所有图片. INPUT_DATA = 'F:\\TensorFlowGoogle\\201806-github\\datasets\\flower_photos\\' # 输出文件地址…
import glob import os.path import numpy as np import tensorflow as tf from tensorflow.python.platform import gfile import tensorflow.contrib.slim as slim # 加载通过TensorFlow-Slim定义好的inception_v3模型. import tensorflow.contrib.slim.python.slim.nets.incepti…
import os import glob import os.path import numpy as np import tensorflow as tf from tensorflow.python.platform import gfile # 原始输入数据的目录,这个目录下有5个子目录,每个子目录底下保存这属于该 # 类别的所有图片. INPUT_DATA = 'F:\\TensorFlowGoogle\\201806-github\\datasets\\flower_photos'…
import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data INPUT_NODE = 784 # 输入节点 OUTPUT_NODE = 10 # 输出节点 LAYER1_NODE = 500 # 隐藏层数 BATCH_SIZE = 100 # 每次batch打包的样本个数 # 模型相关的参数 LEARNING_RATE_BASE = 0.8 LEARNING_RATE_DECAY = 0.9…
import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data INPUT_NODE = 784 # 输入节点 OUTPUT_NODE = 10 # 输出节点 BATCH_SIZE = 100 # 每次batch打包的样本个数 # 模型相关的参数 LEARNING_RATE_BASE = 0.01 LEARNING_RATE_DECAY = 0.99 REGULARAZTION_RATE = 0…
import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data INPUT_NODE = 784 # 输入节点 OUTPUT_NODE = 10 # 输出节点 LAYER1_NODE = 500 # 隐藏层数 BATCH_SIZE = 100 # 每次batch打包的样本个数 # 模型相关的参数 LEARNING_RATE_BASE = 0.01 LEARNING_RATE_DECAY = 0.…
import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data INPUT_NODE = 784 # 输入节点 OUTPUT_NODE = 10 # 输出节点 LAYER1_NODE = 500 # 隐藏层数 BATCH_SIZE = 100 # 每次batch打包的样本个数 # 模型相关的参数 LEARNING_RATE = 0.1 REGULARAZTION_RATE = 0.0001 TR…
import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data INPUT_NODE = 784 # 输入节点 OUTPUT_NODE = 10 # 输出节点 LAYER1_NODE = 500 # 隐藏层数 BATCH_SIZE = 100 # 每次batch打包的样本个数 # 模型相关的参数 LEARNING_RATE_BASE = 0.8 LEARNING_RATE_DECAY = 0.9…
import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data INPUT_NODE = 784 # 输入节点 OUTPUT_NODE = 10 # 输出节点 LAYER1_NODE = 500 # 隐藏层数 BATCH_SIZE = 100 # 每次batch打包的样本个数 # 模型相关的参数 LEARNING_RATE_BASE = 0.8 LEARNING_RATE_DECAY = 0.9…
import tensorflow as tf from numpy.random import RandomState batch_size = 8 w1= tf.Variable(tf.random_normal([2, 3], stddev=1, seed=1)) w2= tf.Variable(tf.random_normal([3, 1], stddev=1, seed=1)) x = tf.placeholder(tf.float32, shape=(None, 2), name="…
import tensorflow as tf w1= tf.Variable(tf.random_normal([2, 3], stddev=1, seed=1)) w2= tf.Variable(tf.random_normal([3, 1], stddev=1, seed=1)) x = tf.constant([[0.7, 0.9]]) a = tf.matmul(x, w1) y = tf.matmul(a, w2) sess = tf.Session() sess.run(w1.in…
import tensorflow as tf g1 = tf.Graph() with g1.as_default(): v = tf.get_variable("v", [1], initializer = tf.zeros_initializer()) # 设置初始值为0 g2 = tf.Graph() with g2.as_default(): v = tf.get_variable("v", [1], initializer = tf.ones_initi…
import os import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data os.environ[' batch_size = 128 # batch容量 display_step = 1 # 展示间隔 learning_rate = 0.01 # 学习率 training_epochs = 20 # 训练轮数,1轮等于n_samples/batch_size example_to_sh…
import os import numpy as np import tensorflow as tf import matplotlib.pyplot as plt from tensorflow.examples.tutorials.mnist import input_data os.environ[' learning_rate = 0.01 # 学习率 training_epochs = 20 # 训练轮数,1轮等于n_samples/batch_size batch_size =…