【发布时间】:2020-08-12 17:00:12
【问题描述】:
我创建了一个 H5PY 数据集,其中包含大约 210 万个实例。问题是我已经填写了除最后一行之外的所有行。我想删除最后一行,但不确定这样做是否可行或安全。
这是如何创建数据集的 sn-p:
shape = (dataset_length, args.batch_size, 2048, 1, 1)
with h5py.File(path, mode='a') as hdf5_file:
array_40 = hdf5_file.create_dataset(
f'{phase}_40x_arrays', shape, maxshape=(None, args.batch_size, 2048, 1, 1)
# either new or checkpointed file exists
# load file and create references to exisitng h5 datasets
with h5py.File(path, mode='r+') as hdf5_file:
array_40 = hdf5_file[f'{phase}_40x_arrays']
for i, (inputs40x, labels) in enumerate(dataloaders_dict):
inputs40x = inputs40x.to(device)
x40 = resnet(inputs40x)
array_40[batch_idx, ...] = x40.cpu()
hdf5_file.flush()
我不确定是否需要将所有实例复制到新数据集。我尝试调整大小,但没有奏效...
干杯,
【问题讨论】:
-
是的,有一个 dataset.resize() 方法。我以前用过(增加尺寸)。通过在轴 0 上设置
maxshape=None,您可以在调整大小时拥有无限的行数。您应该能够做到这一点:array_40.resize(array_40.shape[0]-1, axis=0)并少一行。