【发布时间】:2017-04-11 15:04:43
【问题描述】:
我正在建立自己的 CNN
卷积层和全连接层之间
我需要知道卷积层输出的大小,即
width_feature map * height_feature map * number_feature map
这样我就可以知道这两层之间的权重形状,也就是
[number_neuron_output of convolution layer , number_neuron_1st full connect layer].
我想要做的是得到 [width_feature map,height_feature,map*number_feature map] 自动,因此可以使用它来建立卷积层和全连接层之间的连接
我试过了
def add_convtofully_layer(self,size_out,data_in):
shape_in=tf.shape(data_in)#[batch,H,W,C]
data_re=tf.reshape(data_in,[-1,shape_in[1]*shape_in[2]*shape_in[3]])
W=self.weight_NN(shape_in[1]*shape_in[2]*shape_in[3],size_out)
B=self.bias_NN(size_out)
data_drop=tf.nn.dropout(data_re,self.drop)
result=tf.nn.relu(tf.matmul(data_drop,W)+B)
return result
def weight_NN(self,w_in,w_out):
W=tf.Variable(tf.truncated_normal([w_in,w_out],stddev=0.1),name='weight')
return W
def bias_NN(self,out):
B=tf.Variable(tf.constant(0.0,dtype=tf.float32,shape=[out]),name='bias')
return B
但只收到消息
ValueError: initial_value 必须具有指定的形状:Tensor("Fully_connect_layer1/truncated_normal:0", shape=(?, 150), dtype=float32)
有没有办法使用 Tensorflow 来做到这一点?或者唯一的方法是我需要先自己计算?
谢谢!
【问题讨论】:
标签: python tensorflow conv-neural-network