Google Colab未实现模型训练

时间:2020-08-20 15:16:19

标签: google-colaboratory

我尝试了几次以在Google Colab上训练以下模型,但该模型永久断开连接(在5或6个时期),并且永远无法完成训练。我还尝试了单击按钮连接但不起作用时维护会话的JavaScript函数。请问如何解决此问题?

classifier = Sequential()

classifier.add(Conv2D(6, (3, 3), input_shape = (30, 30, 3), data_format="channels_last", activation = 'relu'))
classifier.add(MaxPooling2D(pool_size = (2, 2)))

classifier.add(Conv2D(6, (3, 3), activation = 'relu'))
classifier.add(MaxPooling2D(pool_size = (2, 2)))

classifier.add(Flatten())

classifier.add(Dense(units = 128, activation = 'relu'))
classifier.add(Dense(units = 64, activation = 'relu'))
classifier.add(Dense(units = 1, activation = 'sigmoid'))

opt = Adam(learning_rate = 0.001, beta_1 = 0.9, beta_2 = 0.999, epsilon = 1e-08, decay = 0.0)
classifier.compile(optimizer = opt, loss = 'binary_crossentropy', metrics = ['accuracy', precision, recall, fmeasure])

from keras.preprocessing.image import ImageDataGenerator

train_datagen = ImageDataGenerator(rescale = 1./255,
                                   horizontal_flip = True,
                                   vertical_flip = True,
                                   rotation_range = 180)

validation_datagen = ImageDataGenerator(rescale = 1./255)

training_set = train_datagen.flow_from_directory('/home/dataset/training_set',
                                                 target_size = (30, 30),
                                                 batch_size = 32,
                                                 class_mode = 'binary')

validation_set = validation_datagen.flow_from_directory('/home/dataset/validation_set',
                                                        target_size = (30, 30),
                                                        batch_size = 32,
                                                        class_mode = 'binary')

history = classifier.fit_generator(training_set,
                                   steps_per_epoch = 208170,
                                   epochs = 25,
                                   validation_data = validation_set,
                                   validation_steps = 89140)

1 个答案:

答案 0 :(得分:0)

Colab将在8-9小时后自动关闭笔记本电脑,因此您应在每次进入Google驱动器后检查模型