获取pkl中数据,Python - 读取pickle数据的索引

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.

解决方案

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值