import tensorflow.compat.v1 as tf # 兼容本地2.6的tensorflow环境下使用1.0的tensorflow
tf.compat.v1.disable_eager_execution()
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
def weight_variable(shape):
initial = tf.truncated_normal(shape, stddev=0.1)
return tf.Variable(initial)
def bias_variable(shape):
initial = tf.constant(0.1, shape=shape)
return tf.Variable(initial)
def conv2d(x, W):
return tf.nn.max_pool(x,ksize=[1, 1, 1, 1],padding='SAME')
def max_pool_2x2(x):
return tf.nn.max_pool(x,ksize=[1, 2, 2, 1],
strides=[1, 2, 2, 1],padding='SAME')
def deepnn(x):
x_image = tf.reshape(x,[-1, 28, 28, 1])
W_conv1 = weight_variable([5, 5, 1, 32])
b_conv1 = bias_variable([32])
h_conv1 = tf.nn.relu(conv2d(x_image, W_conv1) + b_conv1)
h_pool1 = max_pool_2x2(h_conv1)
W_conv2 = weight_variable([5, 5, 32, 64])
b_conv2 = weight_variable([64])
h_conv2 =
最新发布