使用Keras VGGFace框架训练CNN时,Epoch无法开始

我正在尝试使用Keras框架的VGG Face实现来训练我自己的数据集,该数据集包含12类人脸图像。我对训练集中数据量较少的某些类别进行了数据增强处理。

在使用resnet50进行微调后,当我尝试训练模型时,模型卡在了epoch阶段,即它无法开始训练,而是持续显示Epoch 1/50。看起来是这样的:

Layer (type)                 Output Shape              Param #   =================================================================model_1 (Model)              (None, 12)                23585740  =================================================================Total params: 23,585,740Trainable params: 23,532,620Non-trainable params: 53,120_________________________________________________________________Found 1774 images belonging to 12 classes.Found 313 images belonging to 12 classes.Epoch 1/50

这是我的代码:

train_data_path = 'dataset_cfps/train'validation_data_path = 'dataset_cfps/validation'#Parametresimg_width, img_height = 224, 224vggface = VGGFace(model='resnet50', include_top=False, input_shape=(img_width, img_height, 3))#vgg_model = VGGFace(include_top=False, input_shape=(224, 224, 3))last_layer = vggface.get_layer('avg_pool').outputx = Flatten(name='flatten')(last_layer)out = Dense(12, activation='sigmoid', name='classifier')(x)custom_vgg_model = Model(vggface.input, out)# Create the modelmodel = models.Sequential()# Add the convolutional base modelmodel.add(custom_vgg_model)# Add new layers# model.add(layers.Flatten())# model.add(layers.Dense(1024, activation='relu'))# model.add(BatchNormalization())# model.add(layers.Dropout(0.5))# model.add(layers.Dense(12, activation='sigmoid'))# Show a summary of the model. Check the number of trainable parametersmodel.summary()train_datagen = ImageDataGenerator(      rescale=1./255,      rotation_range=20,      width_shift_range=0.2,      height_shift_range=0.2,      horizontal_flip=True,      fill_mode='nearest')validation_datagen = ImageDataGenerator(rescale=1./255)train_batchsize = 16val_batchsize = 16train_generator = train_datagen.flow_from_directory(        train_data_path,        target_size=(img_width, img_height),        batch_size=train_batchsize,        class_mode='categorical')validation_generator = validation_datagen.flow_from_directory(        validation_data_path,        target_size=(img_width, img_height),        batch_size=val_batchsize,        class_mode='categorical',        shuffle=True)# Compile the modelmodel.compile(loss='categorical_crossentropy',              optimizer=optimizers.SGD(lr=1e-3),              metrics=['acc'])# Train the modelhistory = model.fit_generator(      train_generator,      steps_per_epoch=train_generator.samples/train_generator.batch_size ,      epochs=50,      validation_data=validation_generator,      validation_steps=validation_generator.samples/validation_generator.batch_size,      verbose=1)# Save the modelmodel.save('facenet_resnet.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中创建了一个多类分类项目。该项目可以对…

发表回复

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