我正在尝试使用带有 Tensorflow 后端的 Keras(TF:1.9.0 和 Keras:2.1.6)为医学图像分类任务创建一个自定义 CNN 和预训练 VGG16 的集合。在创建集成定义之前,代码运行良好。在定义整体时,我收到以下错误:RuntimeError: Graph disconnected: cannot obtain value for tensor Tensor("input_7:0", shape=(?, 224, 224, 3), dtype=float32) at layer "input_7". The following previous layers were accessed without issue: []我不确定我是否可以通过model_input这种方式传递给预训练的 VGG16。集成定义需要如何修改?
1 回答

慕妹3146593
TA贡献1820条经验 获得超9个赞
问题是 VGG 模型的输入不是由 的输入层馈送的ensemble_model。要解决此问题,您需要修改定义ensemble_model并创建一个新的输入层,然后将其传递给两个模型:
def ensemble(models):
input_img = Input(shape=input_shape)
outputs = [model(input_img) for model in models] # get the output of model given the input image
y = Average()(outputs)
model = Model(inputs=input_img, outputs=y, name='ensemble')
return model
ensemble_model = ensemble(models)
添加回答
举报
0/150
提交
取消