【发布时间】:2018-12-31 00:00:27
【问题描述】:
我正在尝试在我自己的数据集上应用迁移学习,该数据集存在于 33.000 张训练图像(总共 1.4GB)中。在使用 Keras (2.2.0) 中的 predict_generator 进行预测时,我遇到了内存错误。在查看我的任务管理器时,我可以看到内存正在慢慢达到我的 Tesla K80 (1GPU) 的最大 VRAM 5GB。我正在使用以下代码:
#Train
print('train dataset:')
datagen = ImageDataGenerator(preprocessing_function=preprocess_input)
train_generator = datagen.flow_from_directory(
train_data_dir,
target_size=(img_width, img_height),
batch_size=batch_size,
class_mode=None,
shuffle=False)
num_classes = len(train_generator.class_indices)
nb_train_samples = len(train_generator.filenames)
predict_size_train = int(math.ceil(nb_train_samples / batch_size))
VGG16_bottleneck_features_train = model.predict_generator(train_generator, predict_size_train, verbose=1)
np.save('XVGG16_bottleneck_features_train.npy', VGG16_bottleneck_features_train)
我已经尝试了很多东西,但我似乎无法让它对我有用。我已经阅读了许多建议使用批处理的解决方案,但我认为我的 predict_generator 已经以批处理形式接收数据?这里是否有人可以验证这不适用于我的系统,或者是否有其他解决方案?
【问题讨论】:
标签: python memory machine-learning keras computer-vision