为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕容708150 2021-07-14 17:13:20
我正在尝试使用带有 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)


查看完整回答
反对 回复 2021-07-21
  • 1 回答
  • 0 关注
  • 175 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号