【发布时间】:2020-10-25 01:27:47
【问题描述】:
[在 Jupyter Lab 环境中运行] 在 TensorFlow 上训练我的 CNN 时:
history = model.fit(
train_generator,
steps_per_epoch=3,
epochs=5,
verbose = 1,
当我运行我的算法时,我得到一个'OOM when allocating tensor with shape'。
据我了解,这意味着我没有耗尽足够的 GPU 内存。如何连接 Jupyter 上的服务器以访问更多内存来运行我的训练 NN?
我正在使用以下包和代码来加载图像:
from tensorflow.keras.preprocessing.image import ImageDataGenerator
# Conduct pre-processing on the data to read and feed the images from the directories into the CNN
# Re-scale data as pixels have value of 0-255
train_datagen = ImageDataGenerator(rescale=1/255)
validation_datagen = ImageDataGenerator(rescale=1/255)
# Feed training dataset images in via batches of 250
train_generator = train_datagen.flow_from_directory (
'Users\cats-or-dogs\PetImages', # Directory with training set images
target_size=(300, 300), # Re-size target images
batch_size = 425, #mini-batch of 250 to make CNN more efficient
class_mode = 'binary'
)
【问题讨论】:
-
您使用过混合精度吗?它允许您设置相当大的批量大小。
-
@M.Innat - 请您解释一下这是什么意思以及如何做?
-
我加了答案,请看。
标签: tensorflow keras neural-network jupyter-notebook jupyter