评估张量流模型并得到错误类型错误:不可哈希类型:'numpy.ndarray'



我正在尝试弄清楚如何使用一些测试数据评估模型。我的数据以以下方式结构:

/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()

看起来像

result=sess.run(labelBatch_test, feed_dict={imageBatch_test})

应该是

result=sess.run(labelBatch_test, feed_dict={X: imageBatch_test})

相关内容

最新更新