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

error save keras model have Conv2D and dilation_rate=2 use tf.saved_model.save() #27711

Closed
anhtu812 opened this issue Apr 10, 2019 · 4 comments
Closed
Assignees

Comments

@anhtu812
Copy link

install tensorflow2.0: pip install tf-nightly-2.0-preview==2.0.0.dev20190405

keras model have use Conv2D with dilation_rate=2.
tf.saved_model.save(model, OUTPUT_DIR) out error:

Traceback (most recent call last):
  File "convert_h5_to_tflite.py", line 146, in <module>
    tf.saved_model.save(model, OUTPUT_DIR)
  File "/docker_environment/home/docker/anaconda3/lib/python3.6/site-packages/tensorflow/python/saved_model/save.py", line 798, in save
    meta_graph_def, saveable_view, signatures)
  File "/docker_environment/home/docker/anaconda3/lib/python3.6/site-packages/tensorflow/python/saved_model/save.py", line 529, in _fill_meta_graph_def
    signatures = _generate_signatures(signature_functions, resource_map)
  File "/docker_environment/home/docker/anaconda3/lib/python3.6/site-packages/tensorflow/python/saved_model/save.py", line 407, in _generate_signatures
    function, mapped_inputs, resource_map)
  File "/docker_environment/home/docker/anaconda3/lib/python3.6/site-packages/tensorflow/python/saved_model/save.py", line 358, in _call_function_with_mapped_captures
    function.graph.captures, resource_map)
  File "/docker_environment/home/docker/anaconda3/lib/python3.6/site-packages/tensorflow/python/saved_model/save.py", line 280, in _map_captures_to_created_tensors
    .format(interior))
AssertionError: Tried to export a function which references untracked object Tensor("StatefulPartitionedCall/forward_6_1b_conv2D/stack:0", shape=(2, 2), dtype=int32).TensorFlow objects (e.g. tf.Variable) captured by functions must be tracked by assigning them to an attribute of a tracked object or assigned to an attribute of the main object directly.

dilation_rate=1 not error

@allenlavoie allenlavoie self-assigned this Apr 10, 2019
@allenlavoie
Copy link
Member

Could you put together code to reproduce? I tried exporting a Sequential that has a Conv2D with dilation_rate=2 and didn't run into the error:

root = tf.keras.Sequential([tf.keras.layers.Conv2D(filters=3, kernel_size=2, dilation_rate=2)])
initial_output = root.predict(tf.ones((1, 5, 5, 1)))
tf.saved_model.save(root, "/tmp/sm")

This was with 2.0.0-dev20190402 and at head.

@anhtu812
Copy link
Author

code out error:

import tensorflow as tf


input_data = tf.keras.layers.Input(name='fts_input', shape=(None,None,3), dtype='float32')
inner = tf.keras.layers.Conv2D(filters=3, kernel_size=3, dilation_rate=2)(input_data)
model = tf.keras.models.Model(inputs=[input_data], outputs=inner)

initial_output = model.predict([tf.ones((2, 300, 300, 3))])
tf.saved_model.save(model, './')

@allenlavoie
Copy link
Member

Thanks, that does reproduce nicely. I'll take a look.

@allenlavoie
Copy link
Member

Ooo, I accidentally fixed this in 0d4d88c

This is working for me in 2.0.0-dev20190416. I'll add a test to make sure it doesn't break in the future. Thanks for the report!

tensorflow-copybara pushed a commit that referenced this issue Apr 17, 2019
Was already fixed by 0d4d88c

PiperOrigin-RevId: 243913871
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants