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

Tensorflow 2.0.0 / tf.keras.layers.TimeDistributed layer can't be save to saved Model #33094

Closed
luvwinnie opened this issue Oct 6, 2019 · 8 comments
Assignees
Labels
comp:keras Keras related issues TF 2.0 Issues relating to TensorFlow 2.0 type:bug Bug

Comments

@luvwinnie
Copy link

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): No
  • OS Platform and Distribution : Colaboratory (GPU Runtime)
  • tensorflow version: 2.0.0
  • python version: 3.6.8

Describe the current behavior
The model defined which has tf.keras.layers.timeDistributed layer cannot be save by model.save() function.

It shows the error below

ValueError                                Traceback (most recent call last)
/usr/lib/python3.6/inspect.py in getfullargspec(func)
   1125                                        skip_bound_arg=False,
-> 1126                                        sigcls=Signature)
   1127     except Exception as ex:

41 frames
ValueError: no signature found for builtin <tensorflow.python.keras.saving.saved_model.save_impl.LayerCall object at 0x7f74467284a8>

The above exception was the direct cause of the following exception:

TypeError                                 Traceback (most recent call last)
/usr/lib/python3.6/inspect.py in getfullargspec(func)
   1130         # else. So to be fully backwards compatible, we catch all
   1131         # possible exceptions here, and reraise a TypeError.
-> 1132         raise TypeError('unsupported callable') from ex
   1133 
   1134     args = []

TypeError: unsupported callable

Describe the expected behavior
In tensorflow 2.0.0 supposed the model.save model default to be saved in SavedModel format.

Code to reproduce the issue


def get_data():
  datasets, ds_info = tfds.load(name='mnist', with_info=True, as_supervised=True)
  mnist_train, mnist_test = datasets['train'], datasets['test']

  BUFFER_SIZE = 10000

  BATCH_SIZE_PER_REPLICA = 64
  BATCH_SIZE = BATCH_SIZE_PER_REPLICA * mirrored_strategy.num_replicas_in_sync

  def scale(image, label):
    image = tf.cast(image, tf.float32)
    image /= 255

    return image, label

  train_dataset = mnist_train.map(scale).cache().shuffle(BUFFER_SIZE).batch(BATCH_SIZE)
  eval_dataset = mnist_test.map(scale).batch(BATCH_SIZE)

  return train_dataset, eval_dataset

def get_model():
  with mirrored_strategy.scope():
    model = tf.keras.Sequential([
        tf.keras.layers.Conv2D(32, 3, activation='relu', input_shape=(28, 28, 1)),
        tf.keras.layers.MaxPooling2D(),
        # tf.keras.layers.Flatten(),
        tf.keras.layers.TimeDistributed(tf.keras.layers.Dense(64, activation='softmax')),
        # tf.keras.layers.TimeDistributed(tf.keras.layers.Dense(64, activation='softmax')),
        # tf.keras.layers.Dense(10, activation='softmax')
    ])

    model.compile(loss='sparse_categorical_crossentropy',
                  optimizer=tf.keras.optimizers.Adam(),
                  metrics=['accuracy'])
    return model

model = get_model()
model.save("test_save")

Other info / logs
The not only can be reproduce in Colaboratory, but also in normal Ubuntu machien which installed with tensorflow-gpu 2.0.0

@luvwinnie luvwinnie changed the title tf.keras.layers.TimeDistributed layer can't be save to saved Model Tensorflow 2.0.0 / tf.keras.layers.TimeDistributed layer can't be save to saved Model Oct 6, 2019
@rmothukuru rmothukuru self-assigned this Oct 7, 2019
@rmothukuru rmothukuru added comp:keras Keras related issues stat:awaiting tensorflower Status - Awaiting response from tensorflower type:bug Bug TF 2.0 Issues relating to TensorFlow 2.0 labels Oct 7, 2019
@rmothukuru
Copy link
Contributor

Could reproduce this issue with TF Version 2.0. Here is the Gist.

@aldenks
Copy link

aldenks commented Oct 18, 2019

Also running into this. Here's a concise test case:

model = tf.keras.Sequential([tf.keras.layers.TimeDistributed(tf.keras.layers.Dense(1), input_shape=(None, 1))])
model.save('test_save')

@luvwinnie
Copy link
Author

does this issues got any progress?

@SavanK
Copy link

SavanK commented Oct 24, 2019

Any update?

@k-w-w
Copy link
Contributor

k-w-w commented Oct 25, 2019

This appears to be an error with Python 3. Submitting a fix to resolve this.

@tensorflowbutler tensorflowbutler removed the stat:awaiting tensorflower Status - Awaiting response from tensorflower label Oct 25, 2019
@tensorflow-bot
Copy link

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

@luvwinnie
Copy link
Author

so is this been fixed to tensorflow-gpu 2.0 stable build? or i have to install another build?

@jvishnuvardhan
Copy link
Contributor

@luvwinnie It was fixed in tf-nightly which is development version of TF2.1 (will be released in
the near future). Thanks!

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

7 participants