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…
#加载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…
#训练过程的可视化 ,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 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…
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 tensorflow as tf v1 = tf.Variable(tf.random_normal([1], stddev=1, seed=1)) v2 = tf.Variable(tf.random_normal([1], stddev=1, seed=1)) result = v1 + v2 init_op = tf.global_variables_initializer() saver = tf.train.Saver() with tf.Session() as ses…
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…