. Advertisement .
..3..
. Advertisement .
..4..
I get the ”’tensor’ object has no attribute ‘_keras_history”’ error when I am making a sort of GAN (Generative Adversarial Networks).
The structure is below:
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 and model_3 were pretrained beforehand. I pretrained model_2 using a list made up of 0 and 1 but model_1 returned values that were approach. So, with the following code, I contemplated rounding the model_1output: model1_out’s K.round() method.
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
[...]
Then I receive the error message:
AttributeError: 'Tensor' object has no attribute '_keras_history'
The full traceback is:
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'
I don’t know how to solve this error. Can someone help me?
The cause: I think this error is here:
Because your models’ inputs depend on the results of earlier models, so I think the problem is with the model’s codes.
Solution: Please verify your model code line by line to see whether any non-Keras operations are being used, especially in the last few lines.
Eg: You would naturally use
+
or evennumpy.add
for element-wise addition, butkeras.layers.Add()
should be used instead.