在尝试通过更改最后一个 fc 层来为我自己的数据集微调 inception_V3 时
last_layer =nn.Linear(n_inputs, len(classes))
inception_v3.fc = last_layer
Run Code Online (Sandbox Code Playgroud)
之后,当我训练时,它在这个位置上出现了这个错误
# on training loop
output = inception_v3(data)
# calculate the batch loss
loss = criterion(output, target)
Run Code Online (Sandbox Code Playgroud)
错误是
AttributeError: 'tuple' object has no attribute 'log_softmax'
Run Code Online (Sandbox Code Playgroud) 我试图组合两个模型以将输出连接到一个新模型,以便我可以像这样获得两个模型的预测
model_age = load_model('age.h5')
# model_age.get_layer(name= 'model').name='predictions_1'
model_gender = load_model('gender.h5')
# model_gender.get_layer(name='model_1').name='predictions_2'
x = Input(shape=[100, 100, 3])
y_age = model_age(x)
y_gen = model_gender(x)
model = Model(inputs=x, outputs=[y_age, y_gen])
data = cv2.imread(image)
p_age, p_gender = model.predict(data)
print(p_age)
print(p_gender)
Run Code Online (Sandbox Code Playgroud)
但这个错误不断发生,说
RuntimeError: (u'The name "model_1" is used 2 times in the model. All
layer names should be unique. Layer names: ', ['input_1', u'model_1',
u'model_1'])
Run Code Online (Sandbox Code Playgroud)
尝试使用上面评论的代码解决这个问题,但说这些模型没有名为“model_1”的层