tensorflow - 如何在 TF-Slim 的 eval_image_classifier.py 中获取错误分类的文件?

标签 tensorflow tf-slim

我正在使用 script TF-Slim 附带的,用于验证我训练的模型。它工作正常,但我想获得错误分类文件的列表。

脚本使用了https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/slim/python/slim/evaluation.py但即使在那里,我也找不到任何打印错误分类文件的选项。

我怎样才能做到这一点?

最佳答案

在高层次上,您需要做 3 件事:

1) 从数据加载器获取文件名。如果您使用的是来自 tfrecords 的 tf-slim 数据集,文件名很可能未存储在 tfrecord 中,因此您可能在那里运气不佳。但是,如果您使用 tf.WholeFileReader 直接从文件系统使用图像文件,那么您可以在形成批处理的位置获取文件名的张量:

def load_data():
    train_image_names = ... # list of filenames
    filename_queue = tf.train.string_input_producer(train_image_names)
    reader = tf.WholeFileReader()
    image_filename, image_file = reader.read(filename_queue)
    image = tf.image.decode_jpeg(image_file, channels=3)

    .... # load your labels from somewhere

    return image_filename, image, label


 # in your eval code
 image_fn, image, label = load_data()

 filenames, images, labels = tf.train.batch(
                                [image_fn, image, label],
                                batch_size=32,
                                num_threads=2,
                                capacity=100,
                                allow_smaller_final_batch=True)

2) 在进行推理后用你的结果掩盖你的文件名张量:

logits = my_network(images)
preds = tf.argmax(logits, 1)
mislabeled = tf.not_equal(preds, labels)
mislabeled_filenames = tf.boolean_mask(filenames, mislabeled)

3) 将所有这些放入您的 eval_op:

eval_op = tf.Print(eval_op, [mislabeled_filenames])

slim.evaluation.evaluate_once(
                        .... # other options 
                        eval_op=eval_op,
                        .... # other options)

不幸的是,我没有测试这个的设置。让我知道它是否有效!

关于tensorflow - 如何在 TF-Slim 的 eval_image_classifier.py 中获取错误分类的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43065063/

相关文章:

python - 为什么 validation_freq 不适用于 Keras 模型拟合?

python - 如何使用 Keras 中保存的模型来预测和分类图像?

python - 如何通过TensorFlow-Slim VGG Pre-Trained Net批量传递图像?

python - 什么是 DT_VARIANT 张量?

python - Tensorflow (Keras) 和多处理导致 GPU 内存不足

python - Tensorflow CNN训练图像大小不一

python - 在没有 slim.learning.train() 的情况下使用 Tensorflow TF-Slim

model - Tensorflow Slim 恢复模型并预测

带有 is_training True 和 False 的 Tensorflow (tf-slim) 模型