我正在嘗試使用帶有 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
提交
取消