原因是因為keras在建立網格是, 將數據流定義為Layer和Tensor會產生不兼容的現象, 因此會有這種錯誤.
只需要將我們tensor要進行的運算用keras提供的Lambda封裝一下就可以將Tensor類型轉化為為Layer類型.
出現錯誤提示的代碼:
def TotalModel(input_shape, noise_model, avo_model, verbose = 1):
noise_input = Input(input_shape)
noise_output = noise_model(noise_input)
avo_output = avo_model(noise_input)
total_output =avo_output + noise_output
total = Model(inputs = noise_input, outputs = total_output)
if verbose == 1:
print()
total.summary()
return total
修改為:
def TotalModel(input_shape, noise_model, avo_model, verbose = 1):
noise_input = Input(input_shape)
noise_output = noise_model(noise_input)
avo_output = avo_model(noise_input)
total_output = Lambda(lambda x: x[0] + x[1])([avo_output, noise_output])
total = Model(inputs = noise_input, outputs = total_output)
if verbose == 1:
print()
total.summary()
return total
參考鏈接:
https://blog.csdn.net/scythe666/article/details/79962836
https://codeday.me/bug/20190131/581332.html