gpt4 book ai didi

python - 异常: Output tensors to a Model must be Keras tensors

转载 作者:太空宇宙 更新时间:2023-11-03 15:57:08 24 4
gpt4 key购买 nike

运行以下代码时出现此异常:

base_model = VGG16(weights='imagenet')

conv4_3, conv3_3, conv2_2, conv1_2 = base_model.get_layer('block4_conv3').output, base_model.get_layer('block3_conv3').output, base_model.get_layer('block2_conv2').output, base_model.get_layer('block1_conv2').output

conv1 = Convolution2D(256, 1, 1, border_mode='same')(BatchNormalization()(conv4_3))
conv1_scaled = tf.image.resize_bilinear(conv1, (56, 56))
x = merge([BatchNormalization()(conv3_3), conv1_scaled], mode='sum')
conv2 = Convolution2D(128, 3, 3, border_mode='same', input_shape=(256, 56, 56))(x)

op = Convolution2D(2, 3, 3, border_mode='same')(conv2)

model = Model(input=base_model.input, output=op)

回溯:

Traceback (most recent call last):
File "keras_btp.py", line 147, in <module>
model = Model(input=base_model.input, output=op)
File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 1661, in __init__
'Keras tensors. Found: ' + str(x))
Exception: Output tensors to a Model must be Keras tensors. Found:

Tensor("add_19:0", shape=(?, 56, 56, 2), dtype=float32)

我意识到错误出现在 merge 行中。我该如何修复它?

最佳答案

您看到此错误是因为合并的输入之一不是来自 Keras 层。相反,尝试 defining your own custom layer for resizing .

关于python - 异常: Output tensors to a Model must be Keras tensors,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40685648/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com