h5 写
import h5py
h5f = h5py.File(path + '/' + str(name) + str(num).split('.')[0] + '_ins.h5', 'w')
h5f.create_dataset('dataset_1', data=image_name)
h5f.create_dataset('dataset_2', data=np.array(mask_array))
h5f.close()
h5 读
h5f = h5py.File('D:/work/search_image/vgg_picspic/h5/allposter-featureCNN.h5', 'r')
feats = h5f['dataset_1'][:]
imgNames = h5f['dataset_2'][:]
h5f.close()
pickle 写
import pickle
mask_dict = {'image_name': image_name, 'mask_array': np.array(mask_array)}
with open(path + '/' + str(name) + str(num).split('.')[0] + '_ins.pkl', 'wb') as f:
pickle.dump(mask_dict, f)
pickle 读
with open(path + "16353126451_ins.pkl", 'rb') as f:
# 反序列化解析成列表a
a = pickle.load(f)
print(a, a.__class__) # [1, 2, 3] <class 'list'>
print(a['image_name'])