0
我在短时间内使用Tensorflow。这里是我的问题: 我加载AlexNet权做就可以了微调,所以我给大小50 的一批所以我定义:Tensorflow中占位符的形状
# Graph input
x = tf.placeholder(tf.float32, [50, 227, 227, 3])
y = tf.placeholder(tf.float32, [None, 40])
我给一批50张影像,并希望得到40输出类。
然后我定义我的模型
class Model:
@staticmethod
def alexnet(_X, _dropout):
# Layer 1 (conv-relu-pool-lrn)
conv1 = conv(_X, 11, 11, 96, 4, 4, padding='VALID', name='conv1')
conv1 = max_pool(conv1, 3, 3, 2, 2, padding='VALID', name='pool1')
norm1 = lrn(conv1, 2, 2e-05, 0.75, name='norm1')
# Layer 2 (conv-relu-pool-lrn)
conv2 = conv(norm1, 5, 5, 256, 1, 1, group=2, name='conv2')
conv2 = max_pool(conv2, 3, 3, 2, 2, padding='VALID', name='pool2')
norm2 = lrn(conv2, 2, 2e-05, 0.75, name='norm2')
# Layer 3 (conv-relu)
conv3 = conv(norm2, 3, 3, 384, 1, 1, name='conv3')
# Layer 4 (conv-relu)
conv4 = conv(conv3, 3, 3, 384, 1, 1, group=2, name='conv4')
# Layer 5 (conv-relu-pool)
conv5 = conv(conv4, 3, 3, 256, 1, 1, group=2, name='conv5')
pool5 = max_pool(conv5, 3, 3, 2, 2, padding='VALID', name='pool5')
# Layer 6 (fc-relu-drop)
fc6 = tf.reshape(pool5, [-1, 6*6*256])
fc6 = fc(fc6, 6*6*256, 4096, name='fc6')
fc6 = dropout(fc6, _dropout)
# Layer 7 (fc-relu-drop)
fc7 = fc(fc6, 4096, 4096, name='fc7')
fc7 = dropout(fc7, _dropout)
# Layer 8 (fc-prob)
fc8 = fc(fc7, 4096, 40, relu=False, name='fc8')
return fc8 # fc8 and fc7 (for transfer-learning)
,并创建
keep_var = tf.placeholder(tf.float32)
# Model
pred = Model.alexnet(x, keep_var)
我可以做培训,效果很好,但到了最后,我想举一个形象,但x占位符和y占位符被定义为50个图像,因此会引发错误。 这里是训练后,我的代码,只给出了一个形象:
x_test = tf.placeholder(tf.float32, [1, 227, 227, 3])
y_test = tf.placeholder(tf.float32, [None, 40])
img = loaded_img_train[0][:][:][:] # Only one image
label = loaded_lab_train[0][:] # Only one label
prediction = sess.run(pred, feed_dict={x_test: [img], y_test: [label], keep_var: 1.})
由此引出我这个错误:
InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'Placeholder' with dtype float and shape [50,227,227,3]
[[Node: Placeholder = Placeholder[dtype=DT_FLOAT, shape=[50,227,227,3], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
我不能想出如何养活输入大小我想要的。
我的锻炼是直接从花识别灵感与CNN
非常感谢您的帮助! 纪尧姆
我做到了,但我得到了另一个错误,当我确定我的卷积层: 'bias = tf.reshape(tf.nn.bias_add(conv,biasses), conv.get_shape()。as_list())' 它说:'TypeError:预期的二进制或Unicode字符串,得到None ' 它在conv.get_shap中e()我有问题。 – guillaumegg10
转化率被定义为: '卷积=拉姆达I,K:tf.nn.conv2d( I,K,[1,S_H,s_w,1],填充=填充) 与tf.variable_scope(名)作为范围: #为conv层的权重和偏差创建tf变量 kernel = make_var('weights',shape = [k_h,k_w,int(c_i)/ group,c_o])biasses = make_var('biasses' ,[c_o]) if group == 1: conv = convolve(input,kernel)' – guillaumegg10
我有点迷路我知道!我需要去练习 ! – guillaumegg10