我正在编写本教程:
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
如何从小批量中提取原始标签?
我试过这段代码:
reader_test = MinibatchSource(ImageDeserializer('test_map.txt', StreamDefs(
features = StreamDef(field='image', transforms=transforms), # first column in map file is referred to as 'image'
labels = StreamDef(field='label', shape=num_classes) # and second as 'label'
)))
test_minibatch = reader_test.next_minibatch(10)
labels_stream_info = reader_test['labels']
orig_label = test_minibatch[labels_stream_info].value
print(orig_label)
<cntk.cntk_py.Value; proxy of <Swig Object of type 'CNTK::ValuePtr *' at 0x0000000007A32C00> >
但是,正如您在上面看到的,结果不是带有标签的数组。
获取标签的正确代码是什么?
此代码有效,但随后它使用不同的文件格式而不是 ImageDeserializer。
文件格式:
|labels 0 0 1 0 0 0 |features 0
|labels 1 0 0 0 0 0 |features 457
工作代码:
mb_source = text_format_minibatch_source('test_map2.txt', [
StreamConfiguration('features', 1),
StreamConfiguration('labels', num_classes)])
test_minibatch = mb_source.next_minibatch(2)
labels_stream_info = mb_source['labels']
orig_label = test_minibatch[labels_stream_info].value
print(orig_label)
[[[ 0. 0. 1. 0. 0. 0.]]
[[ 1. 0. 0. 0. 0. 0.]]]
使用 ImageDeserializer 时如何获取输入中的标签?