简体   繁体   English

Session 在时间分布式 CNN 的第一个纪元开始时在 Google Colab 中崩溃 model

[英]Session Crashed in Google Colab at the begining of first epoch in TimeDistributed CNN model

I'm working with video classification of 5 classes and using TimeDistributed CNN model in Google Colab platform.我正在处理 5 个类的视频分类,并在Google Colab平台中使用TimeDistributed CNN model。 The train dataset contains 80 videos containing 75 frames each.训练数据集包含80 个视频,每个视频包含75 帧 The validation dataset contains 20 videos containing 75 frames each.验证数据集包含20 个视频,每个视频包含75 帧 So,in total I'm working with 100 videos.The batch size I used is 64 .所以,我总共处理了100 个视频。我使用的批量大小是64 But,at the beginning of first epoch, session gets crashed and ram usage gets full.但是,在第一个 epoch 开始时, session崩溃并且 ram 使用率已满。 What should I need to modify to avoid this problem?我需要修改什么来避免这个问题?

model = tf.keras.models.Sequential([

    tf.keras.layers.TimeDistributed(Conv2D(64, (3,3), padding='same', activation='relu'),input_shape=(75,128, 128, 3)),
    tf.keras.layers.TimeDistributed(MaxPooling2D((2, 2))),
    tf.keras.layers.TimeDistributed(Conv2D(64, (3,3), padding='same', activation='relu')),
    tf.keras.layers.TimeDistributed(MaxPooling2D((2, 2))),
    tf.keras.layers.TimeDistributed(Conv2D(128, (3,3), padding='same', activation='relu')),
    tf.keras.layers.TimeDistributed(Conv2D(128, (3,3), padding='same', activation='relu')),
    tf.keras.layers.TimeDistributed(MaxPooling2D((2, 2))),
    tf.keras.layers.Flatten(),
    tf.keras.layers.Dense(5, activation='softmax')
])

from tensorflow.keras.optimizers import Adam

model.compile(loss='categorical_crossentropy',
              optimizer=Adam(lr=0.0001),
              metrics=['accuracy'])

history = model.fit_generator(
      train_generator,
      validation_data=validation_generator, 
      validation_steps=1500//64, 
      shuffle=False,    
      steps_per_epoch=8,  
      epochs=5,
      verbose=1)

The message that I get:我得到的信息:

WARNING:tensorflow:From <ipython-input-11-c79b34d1df07>:8: Model.fit_generator (from tensorflow.python.keras.engine.training) is deprecated and will be removed in a future version.
Instructions for updating:
Please use Model.fit, which supports generators.
Epoch 1/5

And then,a popup arises and tells me session crashed??然后,出现一个弹出窗口并告诉我 session 崩溃了? Can anyone help??有人可以帮忙吗??

Google colab has a very limited ~11 Gb memory for both your data and model. Google colab 为您的数据和 model 提供了非常有限的 ~11 Gb memory。 From the details, it's pretty obvious it is a memory issue and not related to model itself.从细节来看,很明显这是一个 memory 问题,与 model 本身无关。

You can try reduce your dataset so that the memory is not exhausted also add your data processing pipeline for a better look.您可以尝试减少数据集,以便 memory 不会用尽,还可以添加数据处理管道以获得更好的外观。

You could try a tensorflow's Dataset module.您可以尝试使用 tensorflow 的 Dataset 模块。 For example, instead of passing a array of images, you pass a list of image path's, the dataset generator at the time of training will only partially load 1 batch of images at a time.例如,不是传递图像数组,而是传递图像路径列表,训练时的数据集生成器一次只会部分加载 1 批图像。 This way you won't overwhelm the memory.这样您就不会压倒 memory。 Here's an example这是一个例子

def preprocess_image(filename):
    """
    Load the specified file as a JPEG image, preprocess it and
    resize it to the target shape.
    """

    image_string = tf.io.read_file(filename)
    image = tf.image.decode_jpeg(image_string, channels=3)
    image = tf.image.convert_image_dtype(image, tf.float32)
    image = tf.image.resize(image, target_shape)
    return image

images = [str(os.path.join(images_path ,f)) for f in os.listdir(images_path)]
dataset = tf.data.Dataset.from_tensor_slices(images)
dataset = dataset.shuffle(buffer_size=1024)
dataset = dataset.map(preprocess_image)

source: https://keras.io/examples/vision/siamese_network/来源: https://keras.io/examples/vision/siamese_network/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么 Google Colab 只训练第一个纪元(keras)的两个第一步? - Why Google Colab only train the 2 first steps of the first epoch (keras)? Keras 使用 TimeDistributed 预训练 CNN - Keras pretrain CNN with TimeDistributed StyleGAN2 在 Google Colab 训练开始时“您的 session 在使用所有可用 RAM 后崩溃” - StyleGAN2 "Your session crashed after using all available RAM" at the start of training in Google Colab 不知道为什么在谷歌 colab 的 CNN 上出现错误 - Not sure why getting error on CNN in google colab 尝试使用 tf.keras.utils.plot_model 时,带有 TimeDistributed Layers 的 CNN-LSTM 表现异常 - CNN-LSTM with TimeDistributed Layers behaving weirdly when trying to use tf.keras.utils.plot_model 使用 CNN+LSTM 模型和 TimeDistributed 层包装器进行 Keras 时间序列预测 - Keras time series prediction with CNN+LSTM model and TimeDistributed layer wrapper 使用 Keras 训练 CNN-LSTM 时卡在第一个 epoch - Stuck in the first epoch when training the CNN-LSTM using Keras Keras CNN model 精度没有随着时间的推移而提高和降低? - Keras CNN model accuracy not improving and decreasing over epoch? TimeDistributed 层的 CNN-LSTM 时间序列输入 - CNN-LSTM Timeseries input for TimeDistributed layer 在 Google Colab CPU 中训练神经网络 - 第二个纪元未开始 - Training neural network in Google Colab CPU - second epoch does not start
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM