自定义和预训练模型的集合给出了运行时错误

我正在尝试使用带有 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。集成定义需要如何修改?


慕容708150
浏览 176回答 1
1回答

慕妹3146593

问题是 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 modelensemble_model = ensemble(models)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python