AttributeError:"Tensor"对象没有属性"_keras_history" [英] AttributeError: 'Tensor' object has no attribute '_keras_history'

查看:234
本文介绍了AttributeError:"Tensor"对象没有属性"_keras_history"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我寻找了所有'Tensor'对象都没有属性***",但似乎都与Keras不相关(除了

I looked for all the "'Tensor' object has no attribute ***" but none seems related to Keras (except for TensorFlow: AttributeError: 'Tensor' object has no attribute 'log10' which didn't help)...

我正在制作一种GAN(通用对抗网络).在这里您可以找到结构.

I am making a sort of GAN (Generative Adversarial Networks). Here you can find the structure.

Layer (type)                     Output Shape          Param #         Connected to                     
_____________________________________________________________________________
input_1 (InputLayer)             (None, 30, 91)        0                                            
_____________________________________________________________________________
model_1 (Model)                  (None, 30, 1)         12558           input_1[0][0]                    
_____________________________________________________________________________
model_2 (Model)                  (None, 30, 91)        99889           input_1[0][0]                    
                                                                       model_1[1][0]                    
_____________________________________________________________________________
model_3 (Model)                  (None, 1)             456637          model_2[1][0]                    
_____________________________________________________________________________

我预先训练了model_2和model_3.事情是我用由0和1组成的列表对model_2进行了预训练,但是model_1返回了接近的值.因此,我考虑使用以下代码对model1_output进行四舍五入:model1_out上的K.round().

I pretrained model_2, and model_3. The thing is I pretrained model_2 with list made of 0 and 1, but model_1 return approached values. So i considered rounding the model1_output, with the following code : the K.round() on model1_out.

import keras.backend as K
[...]
def make_gan(GAN_in, model1, model2, model3):
    model1_out = model1(GAN_in)
    model2_out = model2([GAN_in, K.round(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
[...]

我遇到以下错误:

AttributeError:"Tensor"对象没有属性"_keras_history"

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

完整追溯:

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)
  File "C:\ProgramData\Anaconda3\lib\site-packages\keras\legacy\interfaces.py", line 88, in wrapper
return func(*args, **kwargs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py", line 1705, in __init__
build_map_of_graph(x, finished_nodes, nodes_in_progress)
  File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py", line 1695, in build_map_of_graph
layer, node_index, tensor_index)
  File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py", line 1695, in build_map_of_graph
layer, node_index, tensor_index)
  File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py", line 1665, in build_map_of_graph
layer, node_index, tensor_index = tensor._keras_history
AttributeError: 'Tensor' object has no attribute '_keras_history'

我在Windows 7上使用带有Spyder 3.1.4的Python 3.6.我上周用pip升级了TensorFlow和Keras. 感谢您提供的任何帮助!

I'm using Python 3.6, with Spyder 3.1.4, on Windows 7. I upgraded TensorFlow and Keras with pip last week. Thank you for any help provided !

推荐答案

我的问题是在keras上使用'+'而不是'Add'

My problem is use '+' not 'Add' on keras

这篇关于AttributeError:"Tensor"对象没有属性"_keras_history"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆