Skip to content

Instantly share code, notes, and snippets.

@zmjjmz
Created July 11, 2019 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zmjjmz/fcc73dad9f49d34f9c047c108fdd0e3f to your computer and use it in GitHub Desktop.
Save zmjjmz/fcc73dad9f49d34f9c047c108fdd0e3f to your computer and use it in GitHub Desktop.
TF keras export usage
import tensorflow as tf
# Create a tf.keras model.
print(tf.version.VERSION)
model = tf.keras.Sequential()
model.add(tf.keras.layers.Dense(1, input_shape=[10]))
model.summary()
# Save the tf.keras model in the SavedModel format.
saved_to_path = tf.keras.experimental.export(
model, 'my_simple_tf_keras_saved_model')
# Load the saved keras model back.
model_prime = tf.keras.experimental.load_from_saved_model(saved_to_path)
model_prime.summary()
@zmjjmz
Copy link
Author

zmjjmz commented Jul 11, 2019

Oh, and here's the output!

$ python documented_example.py                                                                                                                    
/home/u1/zach/proj/dataplayground2/local/lib/python2.7/site-packages/h5py/__init__.py:34: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, i
t will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
1.13.1
WARNING:tensorflow:From /home/u1/zach/proj/dataplayground2/local/lib/python2.7/site-packages/tensorflow/python/ops/resource_variable_ops.py:435: colocate_with (from tensorflow.python.framework.ops) is deprecate
d and will be removed in a future version.
Instructions for updating:
Colocations handled automatically by placer.
_________________________________________________________________
Layer (type)                 Output Shape              Param #
=================================================================
dense (Dense)                (None, 1)                 11
=================================================================
Total params: 11
Trainable params: 11
Non-trainable params: 0
_________________________________________________________________
Traceback (most recent call last):
  File "documented_example.py", line 10, in <module>
    saved_to_path = tf.keras.experimental.export(
AttributeError: 'module' object has no attribute 'export'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment