Last active
October 13, 2019 14:06
-
-
Save williamjshipman/cbbd1605623e00de378ceae3d6468d3b to your computer and use it in GitHub Desktop.
Simple demo of TensorFlow 2.0's SavedModel, not very complicated
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
def create_model(): | |
X = tf.keras.Input(shape=(10,), name='input') | |
h = tf.keras.layers.Dense(10, kernel_initializer=tf.constant_initializer(1), bias_initializer=tf.constant_initializer(1))(X) | |
y = tf.keras.layers.Dense(10, kernel_initializer=tf.constant_initializer(1), bias_initializer=tf.constant_initializer(1), name='output')(h) | |
model = tf.keras.models.Model(inputs=[X], outputs=[y]) | |
return model | |
def run_model(model: tf.keras.Model): | |
output = model.predict(np.array([[1,2,3,4,5,6,7,8,9,10]])) | |
print(output) | |
if __name__ == "__main__": | |
model = create_model() | |
run_model(model) | |
tf.saved_model.save(model, './data/save_model_v2') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment