【问题标题】:I'm facing this AttributeError: 'NoneType' object has no attribute 'compile'我正面临这个 AttributeError: \'NoneType\' object has no attribute \'compile\'
【发布时间】:2022-11-28 21:56:19
【问题描述】:

我正面临这个 AttributeError: 'NoneType' object has no attribute 'compile'

def get_gan(disc, gen):
    # For the combined model we will only train the generator
    disc.trainable = False

    gan = Sequential()
    gan.add(gen)
    gan.add(disc)
    # gan_input = Input(shape=(NOISE_SIZE,))
    # x = generator(gan_input)
    # gan_out = discriminator(x)
    # gan = Model(gan_input, gan_out)
    gan.summary()
gan = get_gan(discriminator, generator)
gan.compile(loss='binary_crossentropy',optimizer=Adam(lr=LR_G, beta_1=BETA1))

请帮忙,因为我找不到问题出在哪里:(

【问题讨论】:

    标签: python


    【解决方案1】:

    您必须从函数中返回 gan。尝试

    def get_gan(disc, gen):
        # For the combined model we will only train the generator
        disc.trainable = False
    
        gan = Sequential()
        gan.add(gen)
        gan.add(disc)
        # gan_input = Input(shape=(NOISE_SIZE,))
        # x = generator(gan_input)
        # gan_out = discriminator(x)
        # gan = Model(gan_input, gan_out)
        gan.summary()
        return gan
    gan = get_gan(discriminator, generator)
    gan.compile(loss='binary_crossentropy',optimizer=Adam(lr=LR_G, beta_1=BETA1))
    

    【讨论】:

      【解决方案2】:

      你明白问题出在哪里了吗? 因为我有同样的错误。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-12-15
        • 2017-10-20
        • 2022-01-10
        • 1970-01-01
        • 1970-01-01
        • 2017-03-08
        • 2021-04-06
        • 1970-01-01
        相关资源
        最近更新 更多