概念
补
代码
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
import os ##忽略AVX扩展警告
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
mnist = input_data.read_data_sets('MNIST_data', one_hot=True)
# 每个批次的大小
batch_size = 100
# 计算一共有多少个批次
n_batch = mnist.train.num_examples // batch_size
# 初始化权值
#shape为形状,将权值的形状传过来
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):
# x input tensor of shape '[batch,in_height,in_width,in_channles]' #批次,图片的长和宽,通道数(黑白为1,彩色为3)
# W filter / kernel tensor of shape [filter_height,filter_width,in_channels,out_channels] #W为一个滤波器
# `strides[0] = strides