我正在尝试为回归问题创建一个 ResNet50 模型,输出值范围从 -1 到 1。
我省略了 classes 参数,在我的预处理步骤中,我将图像大小调整为 224,224,3。
我尝试创建模型
def create_resnet(load_pretrained=False):
if load_pretrained:
weights = 'imagenet'
else:
weights = None
# Get base model
base_model = ResNet50(weights=weights)
optimizer = Adam(lr=1e-3)
base_model.compile(loss='mse', optimizer=optimizer)
return base_model
Run Code Online (Sandbox Code Playgroud)
然后创建模型,打印摘要并使用 fit_generator 进行训练
history = model.fit_generator(batch_generator(X_train, y_train, 100, 1),
steps_per_epoch=300,
epochs=10,
validation_data=batch_generator(X_valid, y_valid, 100, 0),
validation_steps=200,
verbose=1,
shuffle = 1)
Run Code Online (Sandbox Code Playgroud)
我得到一个错误,虽然说
ValueError: Error when checking target: expected fc1000 to have shape (1000,) but got array with shape (1,)
Run Code Online (Sandbox Code Playgroud)
查看模型摘要,这是有道理的,因为最终 Dense 层的输出形状为 (None, 1000)
fc1000 …Run Code Online (Sandbox Code Playgroud)