无效参数错误:图形执行错误

发布于 2025-01-19 10:03:12 字数 2007 浏览 2 评论 0原文

我的代码:

训练期间将使用的回调

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(最近一次调用最后)在<模块>()中 1 #第一个周期 2 ----> 3history1=model.fit(train_generator,epochs=5,callbacks=[early_stopping],validation_data=val_generator)

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 cycle
history1 = 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜吻♂芭芘 2025-01-26 10:03:12

我已经找到了这个问题的解决方案。最终的 Dense 层数(输出类)存在问题。我已将值从 120 更改为 7,因为我有 7 个输出类; &纪元现在正在正常运行......

head_model = Dense(120, activation='softmax')(head_model) -> old
head_model = Dense(7, activation='softmax')(head_model) -> edited

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...

head_model = Dense(120, activation='softmax')(head_model) -> old
head_model = Dense(7, activation='softmax')(head_model) -> edited
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文