无效参数错误:图形执行错误
我的代码:
训练期间将使用的回调
early_stopping = EarlyStopping(monitor='val_loss', mode = 'min', Patient=10)
checkpoint = ModelCheckpoint(filepath = './weights.hdf5', verbose=1, save_best_only=True)\
base_model = Xception(weights="imagenet", include_top=False, input_tensor=Input (形状=(224, 224, 3)))
base_model.summary()
base_model.layers 中的层:
layer.trainable = False
head_model = AveragePooling2D(pool_size=(4, 4))(base_model.output)
head_model = Flatten(name='flatten')(head_model)
head_model = Dense(1024,activation='relu')(head_model)
head_model = Dropout(0.3)(head_model)
head_model = Dense(512,activation='relu')(head_model)
head_model = Dropout(0.3)(head_model)
head_model = Dense(120,activation='softmax')(head_model)
model = Model(inputs=base_model.input,outputs=head_model)
优化器=SGD(learning_rate=0.1,动量=0.9,衰减=0.01)
model.compile(loss="categorical_crossentropy", optimizationr=optimizer,metrics=["accuracy"])
#第一个周期 history1 = model.fit(train_generator,epochs=5,callbacks=[checkpoint],validation_data=val_generator)
我收到以下错误:
InvalidArgumentError Traceback(最近一次调用最后)
InvalidArgumentError:图形执行错误:
在节点“categorical_crossentropy/softmax_cross_entropy_with_logits”处检测到(最近一次调用最后):
模型将是训练3个周期。在第一个周期中,只有添加到网络“head_model”的分类器层才能以相对较高的学习率进行训练。在第二个周期中,异常模型的一半层将被解冻,而在第三个周期中,所有层将被解冻。在第二个和第三个周期中,优化器的学习率将会降低。
#first Cycle
history1 = model.fit(train_generator, epochs=5,validation_data=val_generator,callbacks=[checkpoint])
在第一个周期本身出现错误...
My code:
callbacks that will be used during training
early_stopping = EarlyStopping(monitor='val_loss', mode = 'min', patience=10)
checkpoint = ModelCheckpoint(filepath = './weights.hdf5', verbose=1, save_best_only=True)\
base_model = Xception(weights="imagenet", include_top=False, input_tensor=Input(shape=(224, 224, 3)))
base_model.summary()
for layer in base_model.layers:
layer.trainable = False
head_model = AveragePooling2D(pool_size=(4, 4))(base_model.output)
head_model = Flatten(name='flatten')(head_model)
head_model = Dense(1024, activation='relu')(head_model)
head_model = Dropout(0.3)(head_model)
head_model = Dense(512, activation='relu')(head_model)
head_model = Dropout(0.3)(head_model)
head_model = Dense(120, activation='softmax')(head_model)
model = Model(inputs=base_model.input, outputs=head_model)
optimizer = SGD(learning_rate=0.1, momentum=0.9, decay=0.01)
model.compile(loss="categorical_crossentropy", optimizer=optimizer, metrics=["accuracy"])
#first cyclehistory1 = model.fit(train_generator, epochs=5, callbacks=[checkpoint], validation_data=val_generator)
I get the following Errors:
InvalidArgumentError Traceback (most recent call last)
<ipython-input-67-9f6b46dd1195> in <module>()
1 #first cycle
2
----> 3 history1 = model.fit(train_generator, epochs=5, callbacks=[early_stopping], validation_data=val_generator)
InvalidArgumentError: Graph execution error:
Detected at node 'categorical_crossentropy/softmax_cross_entropy_with_logits' defined at (most recent call last):
The model will be trained in 3 cycles. In the first cycle, only the added classifier's layers to the network "head_model" will be trainable with a relatively high learning rate. During the second cycle, half of the exception model's layers will be unfrozen while in the third cycle all of the layers will be unfrozen. During the second and third cycles, the learning rate of the optimizer will be reduced.
#first cycle
history1 = model.fit(train_generator, epochs=5, validation_data=val_generator, callbacks=[checkpoint])
Getting an error in the first cycle itself...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经找到了这个问题的解决方案。最终的 Dense 层数(输出类)存在问题。我已将值从 120 更改为 7,因为我有 7 个输出类; &纪元现在正在正常运行......
I have found the solution to this problem. There's a problem with the final Dense layer number (output classes). I have changed the value from 120 to 7, as I had 7 output classes; & the epochs are running properly now...