继续训练卷积神经网络

我有一个已经训练了75个周期的模型。我使用model.save()保存了这个模型。训练的代码如下:

from keras.preprocessing.image import ImageDataGeneratorfrom keras.models import Sequential, load_modelfrom keras.layers import Conv2D, MaxPooling2Dfrom keras.layers import Activation, Dropout, Flatten, Densefrom keras import backend as K# dimensions of our images.img_width, img_height = 320, 240train_data_dir = 'dataset/Training_set'validation_data_dir = 'dataset/Test_set'nb_train_samples = 4000  #totalnb_validation_samples = 1000  # totalepochs = 25batch_size = 10if K.image_data_format() == 'channels_first':    input_shape = (3, img_width, img_height)else:    input_shape = (img_width, img_height, 3)model = Sequential()model.add(Conv2D(32, (3, 3), input_shape=input_shape))model.add(Activation('relu'))model.add(MaxPooling2D(pool_size=(2, 2)))model.add(Conv2D(32, (3, 3)))model.add(Activation('relu'))model.add(MaxPooling2D(pool_size=(2, 2)))model.add(Conv2D(64, (3, 3)))model.add(Activation('relu'))model.add(MaxPooling2D(pool_size=(2, 2)))model.add(Flatten())model.add(Dense(64))model.add(Activation('relu'))model.add(Dropout(0.5))model.add(Dense(1))model.add(Activation('sigmoid'))model.compile(loss='binary_crossentropy',              optimizer='rmsprop',              metrics=['accuracy'])# this is the augmentation configuration we will use for trainingtrain_datagen = ImageDataGenerator(    rescale=1. / 255,    shear_range=0.2,    zoom_range=0.2,    horizontal_flip=True)# this is the augmentation configuration we will use for testing:# only rescalingtest_datagen = ImageDataGenerator(rescale=1. / 255)train_generator = train_datagen.flow_from_directory(    train_data_dir,    target_size=(img_width, img_height),    batch_size=batch_size,    class_mode='binary')validation_generator = test_datagen.flow_from_directory(    validation_data_dir,    target_size=(img_width, img_height),    batch_size=batch_size,    class_mode='binary')model.fit_generator(    train_generator,    steps_per_epoch=nb_train_samples // batch_size,    epochs=epochs,    validation_data=validation_generator,    validation_steps=5)model.save('model1.h5')

如何重新开始训练?我是否只需再次运行这段代码?还是需要做一些修改?如果需要,具体应该做哪些修改?

我读了一些帖子并试图理解其中的一些内容。我在这里读到:加载已训练的Keras模型并继续训练


回答:

你可以简单地通过以下方式加载你的模型:

from keras.models import load_modelmodel = load_model('model1.h5')

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注