簡體   English   中英

使用predict_generator和VGG16的內存錯誤

[英]Memory Error using predict_generator and VGG16

我正在嘗試在我自己的數據集上應用轉移學習,該數據集存在於33.000個訓練圖像中(共1,4GB)。 在Keras(2.2.0)中使用predict_generator進行預測時,遇到了內存錯誤。 當查看我的任務管理器時,我可以看到內存正在緩慢工作,直到我的Tesla K80(1GPU)的5GB最大VRAM。 我正在使用以下代碼:

#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_size_train )。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM