Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using layer classes as attribute throw an exception #27431

Closed
guillaumekln opened this issue Apr 2, 2019 · 4 comments
Closed

Using layer classes as attribute throw an exception #27431

guillaumekln opened this issue Apr 2, 2019 · 4 comments
Assignees
Labels
comp:keras Keras related issues TF 2.0 Issues relating to TensorFlow 2.0 type:bug Bug

Comments

@guillaumekln
Copy link
Contributor

System information

  • Have I written custom code: Yes
  • OS Platform and Distribution: Ubuntu 16.04
  • TensorFlow installed from: binary
  • TensorFlow version: 2.0.0.dev20190402
  • Python version: 2.7.12

Describe the current behavior

When a layer class is used as attribute, the code will throw a TypeError exception when calling self._gather_children_attribute. It appears that the layer class is tracked.

Describe the expected behavior

Only layer instances should be tracked, not classes.

Code to reproduce the issue

import tensorflow as tf

class Layer(tf.keras.layers.Layer):

    def __init__(self):
        super(Layer, self).__init__()
        self.layer_fn = tf.keras.layers.Dense

layer = Layer()
print(layer.variables)

Other info / logs

Traceback (most recent call last):
  File "tf2/class.py", line 10, in <module>
    print(layer.variables)
  File "/tmp/tf2/local/lib/python2.7/site-packages/tensorflow/python/keras/engine/base_layer.py", line 1330, in variables
    return self.weights
  File "/tmp/tf2/local/lib/python2.7/site-packages/tensorflow/python/keras/engine/base_layer.py", line 708, in weights
    return self.trainable_weights + self.non_trainable_weights
  File "/tmp/tf2/local/lib/python2.7/site-packages/tensorflow/python/keras/engine/base_layer.py", line 687, in trainable_weights
    nested = self._gather_children_attribute('trainable_weights')
  File "/tmp/tf2/local/lib/python2.7/site-packages/tensorflow/python/keras/engine/base_layer.py", line 1850, in _gather_children_attribute
    getattr(layer, attribute) for layer in nested_layers))
TypeError: 'property' object is not iterable
@jvishnuvardhan jvishnuvardhan added the comp:keras Keras related issues label Apr 3, 2019
@jvishnuvardhan jvishnuvardhan self-assigned this Apr 3, 2019
@jvishnuvardhan jvishnuvardhan added type:bug Bug TF 2.0 Issues relating to TensorFlow 2.0 labels Apr 3, 2019
@jvishnuvardhan jvishnuvardhan added the stat:awaiting tensorflower Status - Awaiting response from tensorflower label Apr 3, 2019
@qlzh727 qlzh727 assigned allenlavoie and unassigned qlzh727 Apr 4, 2019
@allenlavoie
Copy link
Member

@qlzh727 this is a better project for someone working on TF Keras. I am realistically never going to get to it. (It's near code I've modified, but I don't think those modifications made the situation any worse.)

@qlzh727 qlzh727 assigned qlzh727 and unassigned allenlavoie Apr 4, 2019
@qlzh727
Copy link
Member

qlzh727 commented Apr 4, 2019

Ack, I will take it from here.

@tensorflowbutler tensorflowbutler removed the stat:awaiting tensorflower Status - Awaiting response from tensorflower label Apr 5, 2019
@qlzh727
Copy link
Member

qlzh727 commented Apr 11, 2019

Should be fixed by 9d724a8 now.

@qlzh727 qlzh727 closed this as completed Apr 11, 2019
@tensorflow-bot
Copy link

Are you satisfied with the resolution of your issue?
Yes
No

tensorflow-copybara pushed a commit that referenced this issue Apr 11, 2019
The layer class was incorrectly tracked by layer._layer, which should
only track layer instance. This should be mitigated once b/110718070 is
fixed.

PiperOrigin-RevId: 243103748
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:keras Keras related issues TF 2.0 Issues relating to TensorFlow 2.0 type:bug Bug
Projects
None yet
Development

No branches or pull requests

5 participants