{"action":"created","issue":{"url":"https://api.github.com/repos/keras-team/keras/issues/7362","repository_url":"https://api.github.com/repos/keras-team/keras","labels_url":"https://api.github.com/repos/keras-team/keras/issues/7362/labels{/name}","comments_url":"https://api.github.com/repos/keras-team/keras/issues/7362/comments","events_url":"https://api.github.com/repos/keras-team/keras/issues/7362/events","html_url":"https://github.com/keras-team/keras/issues/7362","id":243519241,"node_id":"MDU6SXNzdWUyNDM1MTkyNDE=","number":7362,"title":"Creating Model variable throws \"AttributeError: 'Tensor' object has no attribute '_keras_history'\"","user":{"login":"aiwabdn","id":5555334,"node_id":"MDQ6VXNlcjU1NTUzMzQ=","avatar_url":"https://avatars1.githubusercontent.com/u/5555334?v=4","gravatar_id":"","url":"https://api.github.com/users/aiwabdn","html_url":"https://github.com/aiwabdn","followers_url":"https://api.github.com/users/aiwabdn/followers","following_url":"https://api.github.com/users/aiwabdn/following{/other_user}","gists_url":"https://api.github.com/users/aiwabdn/gists{/gist_id}","starred_url":"https://api.github.com/users/aiwabdn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aiwabdn/subscriptions","organizations_url":"https://api.github.com/users/aiwabdn/orgs","repos_url":"https://api.github.com/users/aiwabdn/repos","events_url":"https://api.github.com/users/aiwabdn/events{/privacy}","received_events_url":"https://api.github.com/users/aiwabdn/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":40,"created_at":"2017-07-17T20:35:25Z","updated_at":"2018-11-18T09:09:26Z","closed_at":"2017-07-18T00:26:30Z","author_association":"NONE","body":"Hello all,\r\n\r\nsetup: 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\r\n\r\nProblem: 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.\r\nThe 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'**\r\n\r\nGoogling 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. \r\n\r\nStackTrace:\r\n>Traceback (most recent call last):\r\n>  File \"/usr/lib/python2.7/runpy.py\", line 162, in _run_module_as_main\r\n    \"__main__\", fname, loader, pkg_name)\r\n>  File \"/usr/lib/python2.7/runpy.py\", line 72, in _run_code\r\n    exec code in run_globals\r\n>  File \"/root/.local/lib/python2.7/site-packages/trainer/VAE_GAN.py\", line 564, in <module>\r\n    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)\r\n>  File \"/root/.local/lib/python2.7/site-packages/trainer/VAE_GAN.py\", line 471, in inference\r\n    e_net = Model(inputs=[encoder_input1,encoder_input2,encoder_input3,encoder_input4,encoder_input5], outputs=[enc_mean,enc_sigma],name=\"encoder\")\r\n>  File \"/root/.local/lib/python2.7/site-packages/keras/legacy/interfaces.py\", line 87, in wrapper\r\n    return func(*args, **kwargs)\r\n>  File \"/root/.local/lib/python2.7/site-packages/keras/engine/topology.py\", line 1705, in __init__\r\n    build_map_of_graph(x, finished_nodes, nodes_in_progress)\r\n>  File \"/root/.local/lib/python2.7/site-packages/keras/engine/topology.py\", line 1695, in build_map_of_graph\r\n    layer, node_index, tensor_index)\r\n>  File \"/root/.local/lib/python2.7/site-packages/keras/engine/topology.py\", line 1695, in build_map_of_graph\r\n    layer, node_index, tensor_index)\r\n>  File \"/root/.local/lib/python2.7/site-packages/keras/engine/topology.py\", line 1695, in build_map_of_graph\r\n    layer, node_index, tensor_index)\r\n>  File \"/root/.local/lib/python2.7/site-packages/keras/engine/topology.py\", line 1695, in build_map_of_graph\r\n    layer, node_index, tensor_index)\r\n>  File \"/root/.local/lib/python2.7/site-packages/keras/engine/topology.py\", line 1665, in build_map_of_graph\r\n    layer, node_index, tensor_index = tensor._keras_history\r\n>AttributeError: 'Tensor' object has no attribute '_keras_history'\r\n"},"comment":{"url":"https://api.github.com/repos/keras-team/keras/issues/comments/439678100","html_url":"https://github.com/keras-team/keras/issues/7362#issuecomment-439678100","issue_url":"https://api.github.com/repos/keras-team/keras/issues/7362","id":439678100,"node_id":"MDEyOklzc3VlQ29tbWVudDQzOTY3ODEwMA==","user":{"login":"BassantTolba","id":45139353,"node_id":"MDQ6VXNlcjQ1MTM5MzUz","avatar_url":"https://avatars3.githubusercontent.com/u/45139353?v=4","gravatar_id":"","url":"https://api.github.com/users/BassantTolba","html_url":"https://github.com/BassantTolba","followers_url":"https://api.github.com/users/BassantTolba/followers","following_url":"https://api.github.com/users/BassantTolba/following{/other_user}","gists_url":"https://api.github.com/users/BassantTolba/gists{/gist_id}","starred_url":"https://api.github.com/users/BassantTolba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BassantTolba/subscriptions","organizations_url":"https://api.github.com/users/BassantTolba/orgs","repos_url":"https://api.github.com/users/BassantTolba/repos","events_url":"https://api.github.com/users/BassantTolba/events{/privacy}","received_events_url":"https://api.github.com/users/BassantTolba/received_events","type":"User","site_admin":false},"created_at":"2018-11-18T09:09:26Z","updated_at":"2018-11-18T09:09:26Z","author_association":"NONE","body":"Please all,\r\nI have this error and i spent lot of time to solve this .\r\n\"Tensor has no attribute outputs\" ,Below there is the error figure and the my code . Please i need a solution to correct and solve this.\r\nThe error appears in this line \r\n\r\n_, logits_fake = SRGAN_d(net_g.outputs, is_train=True, reuse=True)\r\n\r\n![error3072](https://user-images.githubusercontent.com/45139353/48670450-c320fd00-eb20-11e8-8bec-1d58e054777c.png)\r\n# -*- coding: utf8 -*-\r\n\r\nimport os, time, pickle, random, time\r\nfrom datetime import datetime\r\nimport numpy as np\r\nfrom time import localtime, strftime\r\nimport logging\r\nimport scipy.io as sio\r\n\r\nimport tensorflow as tf\r\nimport tensorlayer as tl\r\nfrom model import SRGAN_g, SRGAN_d\r\nfrom config import config, log_config\r\nenvir = 'indoor' #'indoor' or 'outdoor'\r\n# image parameter\r\nimg_height = 32\r\nimg_width = 32\r\nimg_channels = 2 \r\nimg_total = img_height*img_width*img_channels\r\n# network params\r\nresidual_num = 2\r\nencoded_dim = 512  #compress rate=1/4->dim.=512, compress rate=1/16->dim.=128, compress rate=1/32->dim.=64, compress rate=1/64->dim.=32\r\n\r\n###====================== HYPER-PARAMETERS ===========================###\r\n## Adam\r\nbatch_size = config.TRAIN.batch_size\r\nlr_init = config.TRAIN.lr_init\r\nbeta1 = config.TRAIN.beta1\r\n## initialize G\r\nn_epoch_init = config.TRAIN.n_epoch_init\r\n## adversarial learning (SRGAN)\r\nn_epoch = config.TRAIN.n_epoch\r\nlr_decay = config.TRAIN.lr_decay\r\ndecay_every = config.TRAIN.decay_every\r\n\r\nni = int(np.sqrt(batch_size))\r\n\r\n\r\ndef train():\r\n    ## create folders to save result images and trained model\r\n    save_dir_ginit = \"samples/{}_ginit\".format(tl.global_flag['mode'])\r\n    save_dir_gan = \"samples/{}_gan\".format(tl.global_flag['mode'])\r\n    tl.files.exists_or_mkdir(save_dir_ginit)\r\n    tl.files.exists_or_mkdir(save_dir_gan)\r\n    checkpoint_dir = \"checkpoint\"  # checkpoint_resize_conv\r\n    tl.files.exists_or_mkdir(checkpoint_dir)\r\n\r\n    ###====================== PRE-LOAD DATA ===========================###\r\n    if envir == 'indoor':\r\n        mat = sio.loadmat('data/DATA_Htrainin.mat')\r\n        x_train = mat['HT'] # array\r\n        mat = sio.loadmat('data/DATA_Hvalin.mat')\r\n        x_val = mat['HT'] # array\r\n        mat = sio.loadmat('data/DATA_Htestin.mat')\r\n        x_test = mat['HT'] # array\r\n    elif envir == 'outdoor':\r\n        mat = sio.loadmat('data/DATA_Htrainout.mat')\r\n        x_train = mat['HT'] # array\r\n        mat = sio.loadmat('data/DATA_Hvalout.mat')\r\n        x_val = mat['HT'] # array\r\n        mat = sio.loadmat('data/DATA_Htestout.mat')\r\n        x_test = mat['HT'] # array\r\n\r\n    x_train = x_train.astype('float32')\r\n    x_val = x_val.astype('float32')\r\n    x_test = x_test.astype('float32')\r\n    x_train = np.reshape(x_train, (len(x_train), img_channels, img_height, img_width))  # adapt this if using `channels_first` image data format\r\n    x_val = np.reshape(x_val, (len(x_val), img_channels, img_height, img_width))  # adapt this if using `channels_first` image data format\r\n    x_test = np.reshape(x_test, (len(x_test), img_channels, img_height, img_width))  # adapt this if using `channels_first` image data format\r\n\r\n\r\n    ###========================== DEFINE MODEL ============================###\r\n    ## train inference\r\n    image_tensor = tf.placeholder('float32', [batch_size, img_channels, img_height, img_width], name='t_image_input_to_SRGAN_generator')\r\n    t_target_image = tf.placeholder('float32', [batch_size, img_channels, img_height, img_width], name='t_target_image')\r\n\r\n\r\n    net_g = SRGAN_g(image_tensor, residual_num, encoded_dim)\r\n    net_d, logits_real = SRGAN_d(t_target_image, is_train=True, reuse=False)\r\n    _, logits_fake = SRGAN_d(net_g.outputs, is_train=True, reuse=True)\r\n\r\n    net_g.print_params(False)\r\n    net_g.print_layers()\r\n    net_d.print_params(False)\r\n    net_d.print_layers()\r\n\r\n\r\n"}}
{"actor":{"display_login":"BassantTolba"}}