【问题标题】:How to get images filenames from minibatch?如何从小批量获取图像文件名?
【发布时间】:2017-01-05 14:59:34
【问题描述】:

我正在编写本教程:

https://github.com/Microsoft/CNTK/blob/master/Tutorials/CNTK_201B_CIFAR-10_ImageHandsOn.ipynb

测试/训练数据文件是简单的制表符分隔的文本文件,包含图像文件名和正确的标签,如下所示:

...\data\CIFAR-10\test\00000.png    3
...\data\CIFAR-10\test\00001.png    8
...\data\CIFAR-10\test\00002.png    8

假设我像这样创建一个小批量:

test_minibatch = reader_test.next_minibatch(10)

如何获取测试数据文件第一列中的图像文件名?

我尝试使用此代码:

orig_features = np.asarray(test_minibatch[features_stream_info].m_data)
print(orig_features)

但是,这会导致打印图像本身的字节。

【问题讨论】:

    标签: cntk


    【解决方案1】:

    通过图像阅读器加载图像时文件名丢失。

    一种可能的解决方案是使用复合阅读器同时加载文本格式的地图文件。我们在这里有一个带有 BrainScript 的复合阅读器示例: https://github.com/Microsoft/CNTK/tree/master/Examples/Image/Regression

    使用 Python,您可以执行以下操作:

    # read images
    image_source = ImageDeserializer(map_file)
    image_source.ignore_labels()
    image_source.map_features(features_stream_name,
        [ImageDeserializer.scale(width=image_width, height=image_height, channels=num_channels,
                                 scale_mode="pad", pad_value=114, interpolations='linear')])
    
    # read rois and labels
    roi_source = CTFDeserializer(roi_file)
    roi_source.map_input(rois_stream_name, dim=rois_dim, format="dense")
    label_source = CTFDeserializer(label_file)
    label_source.map_input(labels_stream_name, dim=label_dim, format="dense")
    
    # define a composite reader
    rc = ReaderConfig([image_source, roi_source, label_source], epoch_size=sys.maxsize)
    return rc.minibatch_source()
    

    【讨论】:

    • 可能是一个解决方案。如何配置 CTFDeserializer 来读取原始地图文件,该文件包含文件名和标签,由制表符分隔?
    猜你喜欢
    • 2018-04-25
    • 1970-01-01
    • 2018-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-12
    • 1970-01-01
    相关资源
    最近更新 更多