AttributeError: 'Tensor' object has no attribute '_keras_history'

前端 未结 4 1977
自闭症患者
自闭症患者 2020-12-17 10:36

I looked for all the \"\'Tensor\' object has no attribute ***\" but none seems related to Keras (except for TensorFlow: AttributeError: 'Tensor' object has no attrib

相关标签:
4条回答
  • 2020-12-17 10:58

    Try this:

    def make_gan(GAN_in, model1, model2, model3):
        model1_out = model1(GAN_in)
        model1_out = Lambda(lambda x: K.round(x), output_shape=...)(model1_out)
        model2_out = model2([GAN_in, model1_out])
        GAN_out = model3(model2_out)
        GAN = Model(GAN_in, GAN_out)
        GAN.compile(loss=loss, optimizer=model1.optimizer, metrics=['binary_accuracy'])
        return GAN
    
    0 讨论(0)
  • 2020-12-17 11:03

    My problem was using '+' instead of 'Add' on keras

    0 讨论(0)
  • 2020-12-17 11:10

    @'Maëva LC': I can't post a comment, this answers your None issue.

    but the code is working fine without the line

    model1_out = (lambda x: K.round(x), output_shape=...)(model1_out)

    and not anything else. Anyway, thank you for trying.

    Function round() is not differentiable, hence the gradient is None. I suggest you just remove the line.

    0 讨论(0)
  • 2020-12-17 11:12

    Since the error comes directly from here:

    Traceback (most recent call last):
      File "C:\Users\Asmaa\Documents\BillyValuation\GFD.py", line 88, in <module>
    GAN = make_gan(inputSentence, G, F, D)
      File "C:\Users\Asmaa\Documents\BillyValuation\GFD.py", line 61, in make_gan
    GAN = Model(GAN_in, GAN_out)
    

    , and the inputs of your models depend on the outputs from previous models, I believe the bug lies in the codes in your model.

    In you model code, please check line by line whether or not you apply a non-Keras operation, especially in the last few lines. For example ,for element-wise addition, you might intuitively use + or even numpy.add, but keras.layers.Add() should be used instead.

    0 讨论(0)
提交回复
热议问题