#coding=utf8
#author by fffupeng
#envirnment anaconda python 3.5 windows
#这是一个将mnist中的卷积改成mobilenet的思想
import tensorflow as tf
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)
#从截断的正态分布中输出随机值。
#生成的值服从具有指定平均值和标准偏差的正态分布,如果生成的值大于平均值2个标准偏差的值则丢弃重新选择。
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.conv2d(x,W,strides = [1,1,1,1],padding='SAME') #http://www.jianshu.com/p/05c4f1621c7e
#VALID不会添加新元素,SAME添加元素使得卷积前后尺寸不变
def max_pool_2x2(x):
return tf.nn.max_pool(x,ksize=[1,2,2,1],strides=[1,2,2,1],padding='SAME')
x = tf.placeholder(tf.float32,[None,784])
y_actual = tf.placeholder(tf.float32,[None,10])
x_image = tf.re