def prepare_h5py(train_image, train_label, test_image,
test_label, data_dir, shape=None):
image = np.concatenate((train_image, test_image), axis=0).astype(np.uint8)
label = np.concatenate((train_label, test_label), axis=0).astype(np.uint8)
print('Preprocessing data...')
import progressbar
bar = progressbar.ProgressBar(
maxval=100, widgets=[progressbar.Bar('=', '[', ']'),
' ', progressbar.Percentage()]
)
bar.start()
f = h5py.File(os.path.join(data_dir, 'data.hy'), 'w')
with open(os.path.join(data_dir, 'id.txt'), 'w') as data_id:
for i in range(image.shape[0]):
if i % (image.shape[0] / 100) == 0:
bar.update(i / (image.shape[0] / 100))
grp = f.create_group(str(i))
data_id.write('{}\n'.format(i))
if shape:
grp['image'] = np.reshape(image[i], shape, order='F')
else:
grp['image'] = image[i]
label_vec = np.zeros(10)
label_vec[label[i] % 10] = 1
grp['label'] = label_vec.astype(np.bool)
bar.finish()
f.close()
return
download.py 文件源码
python
阅读 21
收藏 0
点赞 0
评论 0
评论列表
文章目录