Python - Reading the indices of pickled data

末鹿安然 提交于 2019-12-11 04:49:02

问题


Having the following 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]

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]

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.

Thanks.


回答1:


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


来源:https://stackoverflow.com/questions/42966741/python-reading-the-indices-of-pickled-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!