{"action":"created","issue":{"url":"https://api.github.com/repos/tensorflow/tensorflow/issues/22963","repository_url":"https://api.github.com/repos/tensorflow/tensorflow","labels_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/22963/labels{/name}","comments_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/22963/comments","events_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/22963/events","html_url":"https://github.com/tensorflow/tensorflow/issues/22963","id":369860260,"node_id":"MDU6SXNzdWUzNjk4NjAyNjA=","number":22963,"title":"Subclassing the tf.keras.model.Model class, throw \"ValueError: You tried to call `count_params` on dense_81, but the layer isn't built. You can build it manually via: `dense_81.build(batch_input_shape)`.\"","user":{"login":"Abeltime","id":20335476,"node_id":"MDQ6VXNlcjIwMzM1NDc2","avatar_url":"https://avatars2.githubusercontent.com/u/20335476?v=4","gravatar_id":"","url":"https://api.github.com/users/Abeltime","html_url":"https://github.com/Abeltime","followers_url":"https://api.github.com/users/Abeltime/followers","following_url":"https://api.github.com/users/Abeltime/following{/other_user}","gists_url":"https://api.github.com/users/Abeltime/gists{/gist_id}","starred_url":"https://api.github.com/users/Abeltime/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Abeltime/subscriptions","organizations_url":"https://api.github.com/users/Abeltime/orgs","repos_url":"https://api.github.com/users/Abeltime/repos","events_url":"https://api.github.com/users/Abeltime/events{/privacy}","received_events_url":"https://api.github.com/users/Abeltime/received_events","type":"User","site_admin":false},"labels":[{"id":1097546578,"node_id":"MDU6TGFiZWwxMDk3NTQ2NTc4","url":"https://api.github.com/repos/tensorflow/tensorflow/labels/comp:keras","name":"comp:keras","color":"0052cc","default":false}],"state":"closed","locked":false,"assignee":{"login":"ymodak","id":42785357,"node_id":"MDQ6VXNlcjQyNzg1MzU3","avatar_url":"https://avatars1.githubusercontent.com/u/42785357?v=4","gravatar_id":"","url":"https://api.github.com/users/ymodak","html_url":"https://github.com/ymodak","followers_url":"https://api.github.com/users/ymodak/followers","following_url":"https://api.github.com/users/ymodak/following{/other_user}","gists_url":"https://api.github.com/users/ymodak/gists{/gist_id}","starred_url":"https://api.github.com/users/ymodak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ymodak/subscriptions","organizations_url":"https://api.github.com/users/ymodak/orgs","repos_url":"https://api.github.com/users/ymodak/repos","events_url":"https://api.github.com/users/ymodak/events{/privacy}","received_events_url":"https://api.github.com/users/ymodak/received_events","type":"User","site_admin":false},"assignees":[{"login":"ymodak","id":42785357,"node_id":"MDQ6VXNlcjQyNzg1MzU3","avatar_url":"https://avatars1.githubusercontent.com/u/42785357?v=4","gravatar_id":"","url":"https://api.github.com/users/ymodak","html_url":"https://github.com/ymodak","followers_url":"https://api.github.com/users/ymodak/followers","following_url":"https://api.github.com/users/ymodak/following{/other_user}","gists_url":"https://api.github.com/users/ymodak/gists{/gist_id}","starred_url":"https://api.github.com/users/ymodak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ymodak/subscriptions","organizations_url":"https://api.github.com/users/ymodak/orgs","repos_url":"https://api.github.com/users/ymodak/repos","events_url":"https://api.github.com/users/ymodak/events{/privacy}","received_events_url":"https://api.github.com/users/ymodak/received_events","type":"User","site_admin":false}],"milestone":null,"comments":6,"created_at":"2018-10-14T02:21:46Z","updated_at":"2018-11-29T23:20:02Z","closed_at":"2018-11-29T23:20:02Z","author_association":"NONE","body":"The example code :\r\n```python\r\nfrom tensorflow.keras.models import Sequential, Model\r\nfrom tensorflow.keras.layers import Dense, Input\r\n\r\nclass MyModel(Model):\r\n    def __init__(self):\r\n        super().__init__()\r\n        self.dense = Dense(4)\r\n    \r\n    def call(self, inputs):\r\n  \r\n        return self.dense(inputs)\r\n    \r\nmodel = MyModel()\r\n# inputs = Input(shape=(None, 10))\r\nmodel.build((None, 10))\r\nmodel.summary()\r\n```\r\n```\r\n---------------------------------------------------------------------------\r\nValueError                                Traceback (most recent call last)\r\n<ipython-input-103-b62d1ffe41d5> in <module>()\r\n     14 # inputs = Input(shape=(None, 10))\r\n     15 model.build((None, 10))\r\n---> 16 model.summary()\r\n\r\n~\\AppData\\Roaming\\Python\\Python35\\site-packages\\tensorflow\\python\\keras\\engine\\network.py in summary(self, line_length, positions, print_fn)\r\n   1551                               line_length=line_length,\r\n   1552                               positions=positions,\r\n-> 1553                               print_fn=print_fn)\r\n   1554 \r\n   1555 \r\n\r\n~\\AppData\\Roaming\\Python\\Python35\\site-packages\\tensorflow\\python\\keras\\utils\\layer_utils.py in print_summary(model, line_length, positions, print_fn)\r\n    221   for i in range(len(layers)):\r\n    222     if sequential_like:\r\n--> 223       print_layer_summary(layers[i])\r\n    224     else:\r\n    225       print_layer_summary_with_connections(layers[i])\r\n\r\n~\\AppData\\Roaming\\Python\\Python35\\site-packages\\tensorflow\\python\\keras\\utils\\layer_utils.py in print_layer_summary(layer)\r\n    177     name = layer.name\r\n    178     cls_name = layer.__class__.__name__\r\n--> 179     fields = [name + ' (' + cls_name + ')', output_shape, layer.count_params()]\r\n    180     print_row(fields, positions)\r\n    181 \r\n\r\n~\\AppData\\Roaming\\Python\\Python35\\site-packages\\tensorflow\\python\\keras\\engine\\base_layer.py in count_params(self)\r\n   1324                          ', but the layer isn\\'t built. '\r\n   1325                          'You can build it manually via: `' + self.name +\r\n-> 1326                          '.build(batch_input_shape)`.')\r\n   1327     weight_shapes = [w.shape.as_list() for w in self.weights]\r\n   1328     return int(sum([np.prod(w) for w in weight_shapes]))\r\n\r\nValueError: You tried to call `count_params` on dense_84, but the layer isn't built. You can build it manually via: `dense_84.build(batch_input_shape)`.\r\n```\r\n\r\n>The environment in below:\r\nOS Platform: Window10 64bit\r\nDistribution: N\r\ntools: Jupyter Notebook\r\nPython:  python3.5\r\nTensorflow: tensorflow-gpu1.10 by pip installed\r\nBazel version: N\r\nCUDA: 9.0\r\ncuDNN: 7.0\r\nGPU: Quadro M2000/4G\r\nMobile device: N\r\n\r\nIn **Jupyter** result thrown ValueError, but result show as below in **Colab**\r\n```\r\n_______________________________________________________________\r\nLayer (type)                 Output Shape              Param #   \r\n=================================================================\r\ndense_2 (Dense)              multiple                  44        \r\n=================================================================\r\nTotal params: 44\r\nTrainable params: 44\r\nNon-trainable params: 0\r\n_________________________________________________________________\r\n```"},"comment":{"url":"https://api.github.com/repos/tensorflow/tensorflow/issues/comments/443030757","html_url":"https://github.com/tensorflow/tensorflow/issues/22963#issuecomment-443030757","issue_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/22963","id":443030757,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0MzAzMDc1Nw==","user":{"login":"ymodak","id":42785357,"node_id":"MDQ6VXNlcjQyNzg1MzU3","avatar_url":"https://avatars1.githubusercontent.com/u/42785357?v=4","gravatar_id":"","url":"https://api.github.com/users/ymodak","html_url":"https://github.com/ymodak","followers_url":"https://api.github.com/users/ymodak/followers","following_url":"https://api.github.com/users/ymodak/following{/other_user}","gists_url":"https://api.github.com/users/ymodak/gists{/gist_id}","starred_url":"https://api.github.com/users/ymodak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ymodak/subscriptions","organizations_url":"https://api.github.com/users/ymodak/orgs","repos_url":"https://api.github.com/users/ymodak/repos","events_url":"https://api.github.com/users/ymodak/events{/privacy}","received_events_url":"https://api.github.com/users/ymodak/received_events","type":"User","site_admin":false},"created_at":"2018-11-29T23:20:02Z","updated_at":"2018-11-29T23:20:02Z","author_association":"NONE","body":"Please use the latest version of TensorFlow and test again. I was able to execute your script successfully in TF version 1.11 and later. Feel free to reopen the issue if the problems still persists. Thanks!"}}
{"actor":{"display_login":"ymodak"}}