Python 合并hdf5检查点文件
Im使用以下代码组合keras生成的所有hdf5文件Python 合并hdf5检查点文件,python,keras,Python,Keras,Im使用以下代码组合keras生成的所有hdf5文件 import h5py output_file = h5py.File('output.h5', 'w') #keep track of the total number of rows total_rows = 0 import os file_list = os.listdir(os.getcwd()) for n, f in enumerate(file_list): your_data = h5py.File(n, 'r+
import h5py
output_file = h5py.File('output.h5', 'w')
#keep track of the total number of rows
total_rows = 0
import os
file_list = os.listdir(os.getcwd())
for n, f in enumerate(file_list):
your_data = h5py.File(n, 'r+')
total_rows = total_rows + your_data.shape[0]
total_columns = your_data.shape[1]
if n == 0:
#first file; create the dummy dataset with no max shape
create_dataset = output_file.create_dataset("Name", (total_rows, total_columns), maxshape=(None, None))
#fill the first section of the dataset
create_dataset[:,:] = your_data
where_to_start_appending = total_rows
else:
#resize the dataset to accomodate the new data
create_dataset.resize(total_rows, axis=0)
create_dataset[where_to_start_appending:total_rows, :] = your_data
where_to_start_appending = total_rows
output_file.close()
它抛出以下错误
应为str字节或osPathLike对象
为什么会这样?我如何才能合并来自keras的所有hdf5数据集?您正在像处理数据集一样处理hdf5文件
f = h5py.File(n, 'r+')
your_data=f["Name_of_Dataset"] #open a dataset
total_rows = total_rows + your_data.shape[0]
如果不知道数据集的名称,可以按如下方式获取
Dataset_Names=f.keys()
您还可以通过根据访问模式设置块大小来提高性能。现在有了自动分块,如果使用可调整大小的数据集,默认情况下会启用自动分块