Python - 读取pickle数据的索引 [英] Python - Reading the indices of pickled data
问题描述
拥有以下腌制数据:
[array([[[148, 124, 115],
[150, 127, 116],
[154, 129, 121],
...,
[159, 142, 133],
[159, 142, 133],
[161, 145, 142]]]), array([1])]
我能够检索数据
和标签
,如下所示:
I was able to retrieve the data
and label
, as follows:
data = batch[0]
labels = batch[1]
在这种情况下,在为数据和标签分别创建 print
时,我有以下输出:
In which case, I had the following output when making a print
for both data and label, separately:
[[[148 124 115]
[150 127 116]
[154 129 121]
...,
[159 142 133]
[159 142 133]
[161 145 142]]]
[1]
当我的批处理文件现在看起来如下,因为我添加了一个新图像,我没有弄清楚如何读取第二个图像及其标签。我似乎无法理解这里如何将pickle文件编入索引:
When my batch file now looks as follows as I added a new image, I didn't figure out how to read the 2nd image and its label. It seems I cannot understand how the pickled file is indexed here:
[array([[[148, 124, 115],
[150, 127, 116],
[154, 129, 121],
...,
[159, 142, 133],
[159, 142, 133],
[161, 145, 142]],
[[165, 136, 145],
[176, 137, 141],
[178, 138, 144],
...,
[199, 163, 171],
[202, 163, 167],
[200, 158, 163]]]), array([1, 1])]
如何迭代这样的腌制文件?该文件是如何编入索引的?特别是我想添加更多图像及其标签。
How can I iterate through such pickled file? How is the file indexed? Especially that I would like to add more images along with their labels.
谢谢。
推荐答案
你的数据被腌制的方式,两个图像最终在同一个数组中,因此你必须相应地索引:
The way your data is pickled, the two images end up in the same array and thus you have to index accordingly:
batch[0][0] #this will give the first image
batch[0][1] #this will give the second image
batch[1][0] #this will give the first label
batch[1][1] #this will give the second label
这篇关于Python - 读取pickle数据的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!