解决tf报Graph disconnected错误

WARNING:tensorflow:Functional model inputs must come from tf.keras.Input (thus holding past layer metadata), they cannot be the output of a previous non-Input layer. Here, a tensor specified as input to “discriminator” was not an Input tensor, it was generated by layer tf.identity.

在这里插入图片描述我的错误:


def build_discriminator_with_teacher(filters=16):
    inputs = Input(shape = input_shape, name='dis_input')
    x = inputs
    z_teacher = Input(shape= (latent_dim,), name='z_teacher')
    z_teacher = Dropout(rate=0.75)(z_teacher)
    z_embedding = Dense(1024, activation='linear', name='z_embbding_dis')(z_teacher)
    #3层卷积
    for i in range(3):
        filters *= 2
        x = Conv2D(filters=filters,
                kernel_size=kernel_size,
                activation='relu',
                strides=2,
                padding='same')(x)
    x = Flatten()(x)
    #(16*16*128--1024,对16*16*128层施加dropout)
    x = Dropout(rate=0.2)(x)
    x = Dense(1024,activation='relu')(x)

    # 对z_embedding和x进行加和操作

    x = add([x,z_embedding])

    x = Dense(1,activation='linear')(x)

    return Model(inputs=[inputs,z_teacher], outputs=x, name='discriminator')

输入层的变量名不要在后面改了!
应把z_teacher改为z_teacher_input

20220518

Graph disconnected: cannot obtain value for tensor KerasTensor(type_spec=TensorSpec(shape=(None, 16), dtype=tf.float64, name=‘solution_latent_inputs’), name=‘solution_latent_inputs’, description=“created by layer ‘solution_latent_inputs’”) at layer “concatenate”. The following previous layers were accessed without issue: []

这一次是因为输入层最后没有在Model里写。

  • 1
    点赞
  • 0
    收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页
评论 2

打赏作者

构建的乐趣

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值