我已经训练了一个卷积神经网络(CNN),其中包含我在二进制文件中的以下数据(标签,文件名,数据(像素)):
[array([2, 1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0]), array(['10_c.jpg', '10_m.jpg', '10_n.jpg', '1_c.jpg', '1_m.jpg', '1_n.jpg', '2_c.jpg', '2_m.jpg', '2_n.jpg', '3_c.jpg', '3_m.jpg', '3_n.jpg', '4_c.jpg', '4_m.jpg', '4_n.jpg', '5_c.jpg', '5_m.jpg', '5_n.jpg', '6_c.jpg', '6_m.jpg', '6_n.jpg', '7_c.jpg', '7_m.jpg', '7_n.jpg', '8_c.jpg', '8_m.jpg', '8_n.jpg', '9_c.jpg', '9_m.jpg', '9_n.jpg'], dtype='每批包含所有图像,并运行30个epohs:
EPOCH 0 0 0.476923 DONE WITH EPOCH EPOCH 1 0 0.615385 DONE WITH EPOCH EPOCH 2 0 0.615385 DONE WITH EPOCH EPOCH 3 0 0.538462 DONE WITH EPOCH EPOCH 4 0 0.384615 DONE WITH EPOCH ... ... EPOCH 28 0 0.615385 DONE WITH EPOCH EPOCH 29 0 0.692308 DONE WITH EPOCH我的问题是我想尝试新的图像(测试),并想知道返回的类(0,1,2).在这种情况下我该怎么办?换句话说,我训练了CNN,但是如何测试呢?
编辑-1
对于评估准确度点,我在测试20张图像时得到以下结果:
EPOCH 0 0 1.0 DONE WITH EPOCH EPOCH 1 0 1.0 DONE WITH EPOCH EPOCH 2 0 1.0 DONE WITH EPOCH EPOCH 3 0 1.0 DONE WITH EPOCH EPOCH 4 0 1.0 DONE WITH EPOCH EPOCH 5 0 1.0 DONE WITH EPOCH EPOCH 6 0 1.0 DONE WITH EPOCH EPOCH 7 0 1.0 DONE WITH EPOCH EPOCH 8 0 1.0 DONE WITH EPOCH EPOCH 9 0 1.0 DONE WITH EPOCH EPOCH 10 0 1.0 DONE WITH EPOCH EPOCH 11 0 1.0 DONE WITH EPOCH EPOCH 12 0 1.0 DONE WITH EPOCH EPOCH 13 0 1.0 DONE WITH EPOCH EPOCH 14 0 1.0 DONE WITH EPOCH EPOCH 15 0 1.0 DONE WITH EPOCH EPOCH 16 0 1.0 DONE WITH EPOCH EPOCH 17 0 1.0 DONE WITH EPOCH EPOCH 18 0 1.0 DONE WITH EPOCH EPOCH 19 0 1.0 DONE WITH EPOCH EPOCH 20 0 1.0 DONE WITH EPOCH EPOCH 21 0 1.0 DONE WITH EPOCH EPOCH 22 0 1.0 DONE WITH EPOCH EPOCH 23 0 1.0 DONE WITH EPOCH EPOCH 24 0 1.0 DONE WITH EPOCH EPOCH 25 0 1.0 DONE WITH EPOCH EPOCH 26 0 1.0 DONE WITH EPOCH EPOCH 27 0 1.0 DONE WITH EPOCH EPOCH 28 0 1.0 DONE WITH EPOCH EPOCH 29 0 1.0 DONE WITH EPOCH在应用获取网络为测试数据生成的标签时,我得到以下内容:
EPOCH 0 0 0.0 DONE WITH EPOCH EPOCH 1 0 0.0 DONE WITH EPOCH EPOCH 2 0 0.0 DONE WITH EPOCH EPOCH 3 0 0.0 DONE WITH EPOCH EPOCH 4 0 0.0 DONE WITH EPOCH EPOCH 5 0 0.0 DONE WITH EPOCH EPOCH 6 0 0.0 DONE WITH EPOCH EPOCH 7 0 0.0 DONE WITH EPOCH EPOCH 8 0 0.0 DONE WITH EPOCH EPOCH 9 0 0.0 DONE WITH EPOCH EPOCH 10 0 0.0 DONE WITH EPOCH EPOCH 11 0 0.0 DONE WITH EPOCH EPOCH 12 0 0.0 DONE WITH EPOCH EPOCH 13 0 0.0 DONE WITH EPOCH EPOCH 14 0 0.0 DONE WITH EPOCH EPOCH 15 0 0.0 DONE WITH EPOCH EPOCH 16 0 0.0 DONE WITH EPOCH EPOCH 17 0 0.0 DONE WITH EPOCH EPOCH 18 0 0.0 DONE WITH EPOCH EPOCH 19 0 0.0 DONE WITH EPOCH EPOCH 20 0 0.0 DONE WITH EPOCH EPOCH 21 0 0.0 DONE WITH EPOCH EPOCH 22 0 0.0 DONE WITH EPOCH EPOCH 23 0 0.0 DONE WITH EPOCH EPOCH 24 0 0.0 DONE WITH EPOCH EPOCH 25 0 0.0 DONE WITH EPOCH EPOCH 26 0 0.0 DONE WITH EPOCH EPOCH 27 0 0.0 DONE WITH EPOCH EPOCH 28 0 0.0 DONE WITH EPOCH EPOCH 29 0 0.0 DONE WITH EPOCH为什么我得到
0
或1
?这些值是否有意义(即没有分数)?编辑-2
为了获得网络为测试数据生成的标签,在打印出标签值和每个时代的准确性时,我得到了以下内容(标签总是如此
0
,尽管我期待0
或者2
只是,并且准确性如下1
):EPOCH 0 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] 1.0 DONE WITH EPOCH EPOCH 1 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] 1.0 DONE WITH EPOCH EPOCH 2 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] 1.0 DONE WITH EPOCH EPOCH 3 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] 1.0 DONE WITH EPOCH EPOCH 4 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] 1.0 DONE WITH EPOCH EPOCH 5 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] 1.0 DONE WITH EPOCH ..... ..... EPOCH 28 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] 1.0 DONE WITH EPOCH EPOCH 29 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] 1.0 DONE WITH EPOCH谢谢.
1> Miriam Farbe..:一般讨论;一般交流
通常,为了测试神经网络,您需要获取未用于训练的新标记数据,在此数据上应用网络(即应用前馈过程),并评估结果的准确性(与你知道的真实标签相比).
如果您没有这样的新数据(也就是说,如果您使用了所有数据进行培训)并且无法生成新数据,我建议您将您的培训数据与培训和测试分开,然后重新运行培训程序从一开始就对训练数据.重要的是,测试数据将是未使用的数据,以便能够评估模型的性能.
评估准确性
现在,假设您正在讨论此问题中的网络,您可以执行类似的操作来衡量测试数据的准确性:
accuracy_test = sess.run(accuracy, feed_dict={x: test_data, y: test_onehot_vals})其中,
test_data
和test_onehot_vals
是你测试的照片(以及相应的标签).回想一下,对于培训,您运行以下内容:
_, accuracy_val = sess.run([train_op, accuracy], feed_dict={x: batch_data, y: batch_onehot_vals})请注意,我没有
train_op
在评估中使用accuracy_test
.这是因为当你测试你的表现时,你不会优化权重或类似的东西(train_op
确实如此).您只需应用当前拥有的网络即可.获取网络为测试数据生成的标签
最后,如果您想要测试数据的实际标签,则需要获取其值
tf.argmax(model_op, 1)
.因此,您可以将其设置为单独的变量,例如在行的正上方correct_pred = tf.equal(tf.argmax(model_op, 1), tf.argmax(y,1))你可以做:
res_model=tf.argmax(model_op, 1) correct_pred = tf.equal(res_model, tf.argmax(y,1))然后评估它
accuracy_test
如下:res, accuracy_test = sess.run([res_model,accuracy], feed_dict={x: test_data, y: test_onehot_vals}).在未标记的数据上应用网络
完成网络测试后,假设您对结果感到满意,您可以继续并在新的和未标记的数据上应用网络.例如通过做
res_new = sess.run(res_model, feed_dict={x: new_data})
.请注意,为了生成
res_model
(这基本上意味着只在输入上应用网络),您不需要任何标签,因此您不需要y
feed_dict中的值.res_new
将是新标签.