我正在尝试将瓶颈值保存到新创建的hdf5文件中.
瓶颈值分批形成(120,10,10,2048).
保存一个单独的批次占用超过16个演出,python似乎在那一批冻结.根据最近的调查结果(见更新,似乎hdf5占用大内存是可以的,但冻结部分似乎是一个小故障.
我只是试图保存前两批用于测试目的,而且仅用于测试
训练数据集(再次,这是一个测试运行),但我甚至无法通过第一批.它只是在第一批停止并且不循环到下一次迭代.如果我尝试检查hdf5,资源管理器将变得缓慢,Python将冻结.如果我试图杀死Python(即使没有检查hdf5文件),Python也无法正常关闭并强制重启.
这是相关的代码和数据:
总数据点约为90,000 ish,分批发布120个.
Bottleneck shape is (120,10,10,2048)
所以我试图保存的第一批是(120,10,10,2048)
以下是我尝试保存数据集的方法:
with h5py.File(hdf5_path, mode='w') as hdf5:
hdf5.create_dataset("train_bottle", train_shape, np.float32)
hdf5.create_dataset("train_labels", (len(train.filenames), params['bottle_labels']),np.uint8)
hdf5.create_dataset("validation_bottle", validation_shape, np.float32)
hdf5.create_dataset("validation_labels",
(len(valid.filenames),params['bottle_labels']),np.uint8)
#this first part above works fine
current_iteration = 0
print('created_datasets')
for x, y in train:
number_of_examples = len(train.filenames) # number of images
prediction = model.predict(x)
labels = y
print(prediction.shape) # (120,10,10,2048)
print(y.shape) # (120, 12)
print('start',current_iteration*params['batch_size']) # 0
print('end',(current_iteration+1) * params['batch_size']) # 120
hdf5["train_bottle"][current_iteration*params['batch_size']: (current_iteration+1) * params['batch_size'],...] = prediction
hdf5["train_labels"][current_iteration*params['batch_size']: (current_iteration+1) * params['batch_size'],...] = labels
current_iteration += 1
print(current_iteration)
if current_iteration == 3:
break
这是print语句的输出:
(90827, 10, 10, 2048) # print(train_shape)
(6831, 10, 10, 2048) # print(validation_shape)
created_datasets
(120, 10, 10, 2048) # print(prediction.shape)
(120, 12) #label.shape
start 0 #start of batch
end 120 #end of batch
# Just stalls here instead of printing `print(current_iteration)`
它只是在这里暂停(20分钟),并且hdf5文件的大小逐渐增大(现在大约20演出,在我强行杀死之前).实际上我甚至不能用任务管理器强制杀死,我必须重新启动操作系统,在这种情况下实际杀死Python.
更新
在玩了我的代码之后,似乎有一个奇怪的错误/行为.
相关部分在这里:
hdf5["train_bottle"][current_iteration*params['batch_size']: (current_iteration+1) * params['batch_size'],...] = prediction
hdf5["train_labels"][current_iteration*params['batch_size']: (current_iteration+1) * params['batch_size'],...] = labels
如果我运行其中任何一行,我的脚本将完成迭代,并按预期自动中断.因此,如果我运行 – 或者没有冻结.它发生得相当快 – 不到一分钟.
如果我跑第一行(‘train_bottle’),我的记忆大约需要69-72个演出,即使它只有几个批次.如果我尝试更多批次,内存是相同的.所以我假设train_bottle根据我分配数据集的大小参数决定存储,而不是实际填充时.
所以尽管有72场演出,它的运行速度相当快(一分钟).
如果我运行第二行train_labels,我的内存占用几兆字节.
迭代没有问题,并且执行break语句.
但是,现在问题就出现了,如果我尝试运行这两行(在我的情况下是必要的,因为我需要同时保存’train_bottle’和’train_labels’),我在第一次迭代时遇到冻结,并且它即使在20分钟后,也不会继续第二次迭代. Hdf5文件正在慢慢增长,但是如果我尝试访问它,Windows资源管理器会慢慢变成蜗牛而我无法关闭Python – 我必须重新启动操作系统.
所以我不确定在尝试运行这两行时问题是什么 – 好像我运行内存饥饿的train_data行,如果工作完美并在一分钟内结束.