keras-team / keras

Deep Learning for humans
http://keras.io/
Apache License 2.0
61.65k stars 19.42k forks source link

Creating Model variable throws "AttributeError: 'Tensor' object has no attribute '_keras_history'" #7362

Closed aiwabdn closed 7 years ago

aiwabdn commented 7 years ago

Hello all,

setup: Keras 2.0, Tensorflow 1.0, Keras-contrib (using functional api of Keras, but older layer names e.g. Convolution3D). Running on Google Cloud MLEngine with K80 GPU

Problem: The layers are setup properly. All the output shapes match correctly. Inputs and outputs are setup properly. The model takes 5 image inputs and produces 2 outputs. Internally, it takes each image, puts it through layers of residual convolution and updates an LSTM layer. Each image is used recurrently to update the hidden state of the LSTM. The final hidden state of the LSTM is then flattened and put through 2 dense layers to produce 2 output tensors. The problem arises when declaring the Model variable of Keras. We provide the 5 inputs and 2 outputs as suggested in Keras functional api documentation. At this point, we encounter an internal Keras layer error that says AttributeError: 'Tensor' object has no attribute '_keras_history'

Googling for the error shows similar problems with other attributes. As far we have checked, none of them serve our purpose. Any pointers will be highly appreciated.

StackTrace:

Traceback (most recent call last): File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main "main", fname, loader, pkg_name) File "/usr/lib/python2.7/runpy.py", line 72, in _run_code exec code in run_globals File "/root/.local/lib/python2.7/site-packages/trainer/VAE_GAN.py", line 564, in e_net,g_net,d_net,x_tilde,z_x_mean, z_x_log_sigma_sq, z_x, x_p, d_x, d_x_p, z_p = inference(image_data1,image_data2,image_data3,image_data4, image_data5,real_3d_data) File "/root/.local/lib/python2.7/site-packages/trainer/VAE_GAN.py", line 471, in inference e_net = Model(inputs=[encoder_input1,encoder_input2,encoder_input3,encoder_input4,encoder_input5], outputs=[enc_mean,enc_sigma],name="encoder") File "/root/.local/lib/python2.7/site-packages/keras/legacy/interfaces.py", line 87, in wrapper return func(*args, **kwargs) File "/root/.local/lib/python2.7/site-packages/keras/engine/topology.py", line 1705, in init build_map_of_graph(x, finished_nodes, nodes_in_progress) File "/root/.local/lib/python2.7/site-packages/keras/engine/topology.py", line 1695, in build_map_of_graph layer, node_index, tensor_index) File "/root/.local/lib/python2.7/site-packages/keras/engine/topology.py", line 1695, in build_map_of_graph layer, node_index, tensor_index) File "/root/.local/lib/python2.7/site-packages/keras/engine/topology.py", line 1695, in build_map_of_graph layer, node_index, tensor_index) File "/root/.local/lib/python2.7/site-packages/keras/engine/topology.py", line 1695, in build_map_of_graph layer, node_index, tensor_index) File "/root/.local/lib/python2.7/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'

dongmeixu commented 1 year ago

您好,已收到您的来信,谢谢~~~