卷积的使用

来源:互联网 发布:返利网淘宝卖家知道吗 编辑:程序博客网 时间:2024/05/19 16:51

使用tensorflow的框架在mnist上实现两个卷积层一个全链接层构建的卷积网络

“`
from tensorflow.examples.tutorials.mnist import input_data
import tensorflow as tf
mnist = input_data.read_data_sets(“MNIST_data/”,one_hot=Ture)
sess = tf.InteractiveSession()

创建默认的Interactive Session。

def weight_variable(shape):
inital = tf.truncated_normal(shape, stddev=0.1)
return tf.Varilable(initial)
def bias_variable(shape):
inital = tf.constant(0.1,shape=shape)
return tf.Varilable(initial)
#本次使用ReLU所以标准差为0.1也给偏置增加小一点的0.1用来避免死亡节点,同时也不能将池化层和卷积层分开不能重复使用避免创建函数的重复定义出现歧义覆盖,输入参数x和权重w的参数。RGB只有灰色所以设置为1,彩色就是3.padding是边界处理使用SAME代表加上padding让卷积的输入和输出与SAME在格式尺寸上一样(一般是150x150像素)
dev conv2d(x,w)

“`