tensorflow: Saving GRU with dropout to SavedModel fails

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): No
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Colab
  • Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device:
  • TensorFlow installed from (source or binary): Pip
  • TensorFlow version (use command below): v2.0.0-rc2-26-g64c3d38 2.0.0
  • Python version: python 3.6.8
  • Bazel version (if compiling from source):
  • GCC/Compiler version (if compiling from source):
  • CUDA/cuDNN version:
  • GPU model and memory:

Describe the current behavior When Model containing GRU layer, dropout is set and activation=‘relu’, the model is not savable.

Error: Attempted to save a function b’__inference_GRU_layer_call_fn_8041’ which references a symbolic Tensor Tensor(“dropout/mul_1:0”, shape=(None, 3), dtype=float32) that is not a simple constant. This is not supported.

Describe the expected behavior Model gets saved.

Code to reproduce the issue

from tensorflow import keras
from tensorflow.keras import layers

inputs = keras.Input(shape=(784,3), name='digits')
x = layers.GRU(64, activation='relu', name='GRU',dropout=0.1)(inputs)
x = layers.Dense(64, activation='relu', name='dense')(x)
outputs = layers.Dense(10, activation='softmax', name='predictions')(x)

model = keras.Model(inputs=inputs, outputs=outputs, name='3_layer')
model.summary()
model.save('model',save_format='tf')

Based on: https://www.tensorflow.org/guide/keras/save_and_serialize

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 11
  • Comments: 19 (10 by maintainers)

Most upvoted comments

@fhausmann, Model is Saved Successfully if you replace model.save('model',save_format="tf") with model.save('model.h5') . Here is the Gist.

See the above link. I don’t think LSTM works as well