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