我试图弄清楚如何使用一些测试数据来评估模型。我的数据采用以下方式构建:
/home/user/images/image1.jpg label1
/home/user/images/image2.jpg label1
/home/user/images/image3.jpg label2
以下是我尝试使用的代码。请注意,我获取测试数据labelBatch_test, imageBatch_test,
的方式与我在下面的代码中获取培训数据的方式相同。
def readSample(queue):
label = queue[1]
file_contents = tf.read_file(queue[0])
example = tf.image.decode_jpeg(file_contents, channels=3)
return example, label
def Main():
images = tf.convert_to_tensor(imagePaths, dtype=tf.string)
labels = tf.convert_to_tensor(labels, dtype=tf.int32)
input_queue = tf.train.slice_input_producer([images, labels], shuffle=True)
image, label = readSample(input_queue)
resizedImage = tf.image.resize_images(image,RESIZE)
image = tf.random_crop(resizedImage,CROP_SIZE)
image_batch, label_batch = tf.train.batch([image, label], batch_size=BATCH_SIZE)
with tf.name_scope('CNN'):
X = tf.placeholder(tf.float32,shape=FINAL_SIZE)
Y = tf.placeholder(tf.int32,shape=[None])
....
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
sess.run(tf.local_variables_initializer())
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
writer = tf.summary.FileWriter("log", sess.graph)
for i in range(75):
[imageBatch, labelBatch] = sess.run([image_batch,label_batch])
summary, _, lossVal = sess.run([merged,opt,loss],feed_dict={X: imageBatch, Y: labelBatch})
writer.add_summary(summary,i)
print('Loss {0:.2f}'.format(lossVal))
# trying to evaluate the model below using the test data
result=sess.run(labelBatch_test, feed_dict={imageBatch_test})
writer.flush()
writer.close()
coord.request_stop()
coord.join(threads)
Main()
答案 0 :(得分:0)
好像是
result=sess.run(labelBatch_test, feed_dict={imageBatch_test})
应该是
result=sess.run(labelBatch_test, feed_dict={X: imageBatch_test})