tensorflow搭建CNN用到的函数-以交通信号识别为例
代码链接:https://medium.com/@waleedka/traffic-sign-recognition-with-tensorflow-629dffc391a6
tf.Variable()
tf.truncated_normal(shape, mean, stddev) :shape表示生成张量的维度,mean是均值,stddev是标准差。
tf.constant(value,dtype=None,shape=None,name=’Const’)
创建一个常量tensor,按照给出value来赋值,可以用shape来指定其形状。value可以是一个数,也可以是一个list。
创建一个常量tensor,按照给出value来赋值,可以用shape来指定其形状。value可以是一个数,也可以是一个list。
tf.nn.con2d(x,W,strides,padding):输入为4维batch[n,x,y,m],n个x*y,m通道的图片(矩阵)
卷积结果:padding参数为SAME时,输出的维度:x.shape[0]不变,尺寸变为下图,通道数(x.shape[3])变为卷积核个数,即W.shape[3]
tf.nn.max_pool(x,ksize,strides,padding)
池化结果:padding参数为SAME时,输出的shape:x.shape[0]不变,尺寸与ksize和strides有关,x.shape[3]不变
tf.reshape(tensor,shape):
tf.nn.softmax(x):将向量x以softmax形式变为概率表示
tf.argmax(x,axis):以axis所示的轴,找出x中最大值的下标.eg:输入为[m,n],axis为0,时,输出的shape为[n],为1时,输出shape为[m].
tf.equal(A,B):返回boolean值,维度与A,B相同
tf.cast(x,dype),将x类型变为dtype所示类型
tf.reduce_mean(input_tensor,reduction_indices):对input_tensor按照轴reduction_indices求均值
tf.nn.sparse_softmax_cross_entropy_with_logits(logits,labels):
出现shape[-1,32,32,3] has negtive dimension错误时,可能是因为placeholder没有被正确feed,检查是否需要placeholder处未进行feed或不需要placeholder处进行了feed
random.sample(m,n),在[0,m)中随机取n个数字