question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Keras to tf.keras

See original GitHub issue

Has anyone ported this (awesome) tutorial to tf.keras from keras? My motivation is related to training in AWS SageMaker where there is some required functionality in a tf.contrib package.

For the most part this seems pretty straight forward but I hit a wall (exceeded my talent) on keras_ssd300.py

  File "/home/ubuntu/projects/rev-tensorflow-ssd/models/keras_ssd300.py", line 318, in ssd_300
    conv4_3_norm = L2Normalization(gamma_init=20, name='conv4_3_norm')(conv4_3)
  File "/home/ubuntu/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py", line 538, in __call__
    self._maybe_build(inputs)
  File "/home/ubuntu/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py", line 1603, in _maybe_build
    self.build(input_shapes)
  File "/home/ubuntu/projects/rev-tensorflow-ssd/models/keras_layers/keras_layer_L2Normalization.py", line 64, in build
    self.trainable_weights = [self.gamma]
  File "/home/ubuntu/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py", line 1639, in __setattr__
    super(Layer, self).__setattr__(name, value)
AttributeError: can't set attribute

If I understand this correctly, this is feeding conv4_3 into the L2 normalization layer It is trying to set the attribute: self.trainable_weights = [self.gamma] from a(n added) print statement, it looks like self.gamma = [<tf.Variable ‘conv4_3_norm/conv4_3_norm_gamma:0’ shape=(512,) dtype=float32>]

Can anyone offer a clue here?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
MaAminicommented, Feb 17, 2020

tried the same fix and got

“ValueError: Dimensions must be equal, but are 512 and 64 for ‘conv4_3_norm/mul’ (op: ‘Mul’) with input shapes: [?,64,64,512], [64].” tf 1.13

I also got the same error. Do you find any solution for that?

1reaction
Maioy97commented, Feb 6, 2020

tried the same fix and got

“ValueError: Dimensions must be equal, but are 512 and 64 for ‘conv4_3_norm/mul’ (op: ‘Mul’) with input shapes: [?,64,64,512], [64].” tf 1.13

Read more comments on GitHub >

github_iconTop Results From Across the Web

tf.keras.Model | TensorFlow v2.11.0
Model groups layers into an object with training and inference features.
Read more >
Keras vs. tf.keras: What's the difference in TensorFlow 2.0?
Now that TensorFlow 2.0 is released both keras and tf.keras are in sync, implying that keras and tf.keras are still separate projects; however, ......
Read more >
What is the difference between keras and tf.keras?
tf.keras is the Tensorflow specific implementation of the Keras API specification. It adds the framework the support for many Tensorflow specific features ...
Read more >
How to convert your Keras models to Tensorflow - Medium
build and train your model in Keras; Use K.get_session() to get TF session and output the model as .pb file; Load .pb file...
Read more >
The Model class - Keras
tf.keras.Model(). Model groups layers into an object with training and inference features. Arguments. inputs: The input(s) of the model: a keras.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found