话不多说,代码全套完整,亲测实用NB666
import numpy as np
import matplotlib.pyplot as plt
import h5py
import os
def createData(path):
pics = os.listdir(path)
all_data = []
for item in pics:
try:
all_data.append(plt.imread(path+item).tolist())
# all_data.append(plt.imread(path+'/'+item).tolist())
except Exception as pic_wrong:
print(item+" pic wrong")
return all_data
def createSet(hf, name, tip, data):
hf.create_dataset(name, data=data)
t = [[tip]*len(data)]
hf.create_dataset(name + '_tip', data=t)
if __name__ == '__main__':
file_train_name="D:/Pictures/zhenhua/temp001/data_train.h5"
hf = h5py.File(file_train_name, 'w')
all_data = createData('D:/Pictures/zhenhua/temp2/')
createSet(hf, 'train_set_1', 1, all_dat