获取pkl中数据_如何将数据放入我的数据集结构中列表.pkl”?

我试着用与列表.pkl在

这就是我目前所拥有的path = '/home/dell/thesis/neon/Images'

def PIL2array(img):

return numpy.array(img.getdata(),

numpy.uint8).reshape(img.size[1], img.size[0], 1)

def main():

fileList = [os.path.join(dirpath, f)

for dirpath, dirnames, files in os.walk(path)

for f in files if f.endswith('.jpg')]

print "Preparing your pickle files. Pls wait..."

t0 = time.time()

for file_ in fileList:

print file_

img = Image.open(file_)

arr = PIL2array(img)

cPickle.dump(arr,open(file_+"-prot0"+".pkl","wb"),protocol=0)

t1=time.time()

total = t1-t0

print "P(h)ickling execution time: %.2f sec" % total

# routine to recursively traverse a folder and save list of file names

pklList = [os.path.join(dirpath, f)

for dirpath, dirnames, files in os.walk(path)

for f in files if f.endswith('.pkl')]

#print "hi"

all_files = []

for file_ in pklList:

all_files += [file_]

train_share = 0.6

valid_share = 0.2

seed = 1

n_train = int(len(all_files) * train_share)

n_valid = int(len(all_files) * valid_share)

rng = np.random.RandomState(seed)

rng.shuffle(all_files)

train = all_files[:n_train]

valid = all_files[n_train:(n_train + n_valid)]

test = all_files[(n_train + n_valid):]

save_path = os.path.join(dirpath, '../datasets.pkl')

with open(save_path, 'w') as fout:

cPickle.dump((train, valid, test), fout)

filters = tables.Filters(complib='blosc', complevel=5)

hdf5_file = 'dataset.h5'

full_path = os.path.join(dirpath, hdf5_file)

h5file = tables.open_file(full_path, mode='w',

title='pics',

filters=filters)

save_path = os.path.join(dirpath, '../datasets.pkl')

with open(save_path, 'r') as fin:

files = cPickle.load(fin)

**for subfiles, subset in zip(files, ['train', 'valid', 'test']):

group = h5file.create_group(h5file.root, subset, subset)

X = h5file.create_vlarray(group, 'X', atom=tables.UInt8Atom(),

title='Data values',

expectedrows=len(subfiles), f filters=filters)

y = h5file.create_carray(group, 'y', atom=tables.UInt8Atom(),

title='Data targets',

shape=(len(subfiles),), filters=filters)

s = h5file.create_carray(group, 's', atom=tables.UInt32Atom(),

title='Data shapes',

shape=(len(subfiles), 3), filters=filters)**

for i, file in enumerate(subfiles):

full_path = os.path.join(dirpath, file)

with open(full_path, 'r') as fin:

image, label = cPickle.load(fin)

X.append(image.flatten())

y[i] = label

s[i] = np.array(image.shape)

if i % 50 == 0:

print '.. aggregated', i, 'from', subset

h5file.flush()

h5file.flush()

我强调了我面临问题的部分。

我一直收到以下错误:

总的来说

图像,标签=cPickle.load公司(财务)

值错误:太多的值无法解压缩

有人能帮我吗?在

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值