我已經訓練與10 批量大小的卷積神經網絡然而,當測試,我想單獨和無法預知每個數據集的分類分批,這給了錯誤:批量訓練但在Tensorflow中測試單個數據項目?
Assign requires shapes of both tensors to match. lhs shape= [1,3] rhs shape= [10,3]
我理解是指10到batch_size
,3是我分類的類的數量。
我們不能使用批次進行培訓並單獨進行測試嗎?
更新:
訓練階段:
batch_size=10
classes=3
#vlimit is some constant : same for training and testing phase
X = tf.placeholder(tf.float32, [batch_size,vlimit ], name='X_placeholder')
Y = tf.placeholder(tf.int32, [batch_size, classes], name='Y_placeholder')
w = tf.Variable(tf.random_normal(shape=[vlimit, classes], stddev=0.01), name='weights')
b = tf.Variable(tf.ones([batch_size,classes]), name="bias")
logits = tf.matmul(X, w) + b
entropy = tf.nn.softmax_cross_entropy_with_logits(logits=logits, labels=Y, name='loss')
loss = tf.reduce_mean(entropy)
optimizer = tf.train.AdamOptimizer(learning_rate).minimize(loss)
測試階段:
batch_size=1
classes=3
X = tf.placeholder(tf.float32, [batch_size,vlimit ], name='X_placeholder')
Y = tf.placeholder(tf.int32, [batch_size, classes], name='Y_placeholder')
w = tf.Variable(tf.random_normal(shape=[vlimit, classes], stddev=0.01), name='weights')
b = tf.Variable(tf.ones([batch_size,classes]), name="bias")
logits = tf.matmul(X, w) + b
entropy = tf.nn.softmax_cross_entropy_with_logits(logits=logits, labels=Y, name='loss')
loss = tf.reduce_mean(entropy)
optimizer = tf.train.AdamOptimizer(learning_rate).minimize(loss)
我相信這應該是可能的。您可以添加示例代碼來顯示您已定義的佔位符(lhs,rhs)或變量等嗎? – dijksterhuis
更新了問題! – user5722540
兩個階段是否是同一個Tensorflow圖的一部分? – dijksterhuis