gpt4 book ai didi

python - 图已断开连接 : cannot obtain value for tensor Tensor ("input_2:0", shape=(?, 500, 500, 5, 1)

转载 作者:太空宇宙 更新时间:2023-11-03 21:47:31 25 4
gpt4 key购买 nike

def make_fcn_resnet(input_shape, nb_labels, use_pretraining, freeze_base):
nb_rows, nb_cols, _ = input_shape
input_tensor = Input(shape=input_shape)
weights = 'imagenet' if use_pretraining else None

model =ResnetBuilder.build(num_outputs=2,repetitions2=3, weights='present', input_shape=(1, 500, 500, 5))

if freeze_base:
for layer in model.layers:
layer.trainable = False

x32 = model.get_layer('act2').output
print("x32", x32._keras_shape)
x16 = model.get_layer('act3').output
print("x16", x16._keras_shape)
x8 = model.get_layer('act4').output
print("x8", x8._keras_shape)

c32 = Conv3D(nb_labels, (1, 1,5), name='conv_labels_32', padding='valid')(x32)
c32=Reshape((500,500,2))(c32)
print("c32", c32._keras_shape)
c16 = Conv3D(nb_labels, (1, 1,5), name='conv_labels_16', padding='valid')(x16)
c16=Reshape((250,250,2))(c16)
print("c16", c16._keras_shape)
c8 = Conv3D(nb_labels, (1, 1,5), name='conv_labels_8', padding='valid')(x8)
c8=Reshape((125,125,2))(c8)
print("c8", c8._keras_shape)

def resize_bilinear(images):
return tf.image.resize_bilinear(images, [nb_rows, nb_cols])

r32 = Lambda(resize_bilinear, name='resize_labels_32')(c32)
r16 = Lambda(resize_bilinear, name='resize_labels_16')(c16)
r8 = Lambda(resize_bilinear, name='resize_labels_8')(c8)

m = Add(name='merge_labels')([r32, r16, r8])

x = Reshape((nb_rows * nb_cols, nb_labels))(m)
x = Activation('softmax')(x)
x = Reshape((nb_rows, nb_cols, nb_labels))(x)

model = Model(inputs=input_tensor, outputs=x)

#print model.summary()
return model

Resn​​etBuilder.build 函数中,我使用 conv3d 层编写了 Resnet 模型。在这里,我采用我自己的模型的 Resnet 层并设计新模型。当我调用新模型时,我收到诸如图表断开连接之类的错误。

最佳答案

在 keras(或 tensorflow )中,张量之间的运算用数据流图表示。使用数据流图时,模型(数据流图)的输入和输出之间应该存在直接或间接连接(链接)。在您的情况下,您的输入(input_tensor变量)和输出(x)之间没有连接。为了解决这个问题,你应该将 input_tensor 与 ResNet 模型连接起来。 Keras 函数式 API 具有在张量上调用模型的功能。

在您的情况下,请在卡住 ReseNet 模型层后进行以下更改。

model = model(input_tensor)
# Now model variable is just output tensor of resnet model.
x32 = model
print("x32", x32._keras_shape)
x16 = model
print("x16", x16._keras_shape)
x8 = model
print("x8", x8._keras_shape)

关于python - 图已断开连接 : cannot obtain value for tensor Tensor ("input_2:0", shape=(?, 500, 500, 5, 1),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52380387/

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