[英]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.