This file contains hidden or 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
| model = MyModel() | |
| checkpoint = tf.train.Checkpoint(myModel=model) | |
| checkpoint.save('./test/model.ckpt') | |
| del model | |
| model = MyModel() | |
| checkpoint = tf.train.Checkpoint(myModel=model) | |
| checkpoint.restore(tf.train.latest_checkpoint('./test/')) |
This file contains hidden or 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
| app = Flask(__name__) | |
| cors = CORS(app) | |
| @app.route("/api/predict", methods=['POST']) | |
| def predict(): | |
| start = time.time() | |
| data = request.data.decode("utf-8") | |
| if data == "": |
This file contains hidden or 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
| DEF_SERVING_DEF_KEY = tf.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY | |
| tensor_x = model.signature_def[DEF_SERVING_DEF_KEY].inputs['x'].name # return Placeholder:0 | |
| tensor_y = model.signature_def[DEF_SERVING_DEF_KEY].outputs['y'].name # return 'dense/BiasAdd:0' | |
| x = tf.get_default_graph().get_tensor_by_name(tensor_x) | |
| y = tf.get_default_graph().get_tensor_by_name(tensor_y) |
This file contains hidden or 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 | |
| session = tf.Session() | |
| for item in tf.get_default_graph().get_operations(): | |
| print(item) | |
| print(50*'-') | |
| model = tf.saved_model.loader.load(sess=session, | |
| tags=[tf.saved_model.tag_constants.SERVING], | |
| export_dir='./test/') |
This file contains hidden or 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 | |
| session = tf.Session() | |
| for item in tf.get_default_graph().get_operations(): | |
| print(item) | |
| print(50*'-') | |
| model = tf.saved_model.loader.load(sess=session, | |
| tags=[tf.saved_model.tag_constants.SERVING], | |
| export_dir='./test/') |
This file contains hidden or 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
| model = tf.saved_model.loader.load(sess=session, | |
| tags=[tf.saved_model.tag_constants.SERVING], | |
| export_dir='./test/') |
This file contains hidden or 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 numpy as np | |
| import tensorflow as tf | |
| # create dummy data | |
| X_raw = np.array([2013, 2014, 2015, 2016, 2017], dtype=np.float32) | |
| y_raw = np.array([12000, 14000, 15000, 16500, 17500], dtype=np.float32) | |
| X_data = (X_raw - X_raw.min()) / (X_raw.max() - X_raw.min()) | |
| Y_data = (y_raw - y_raw.min()) / (y_raw.max() - y_raw.min()) | |
| X_data = np.expand_dims(X_data, axis=1) | |
| Y_data = np.expand_dims(Y_data, axis=1) |
This file contains hidden or 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
| from keras.models import load_model | |
| model.save('my_model.h5') | |
| del model # deletes the existing model | |
| # returns a compiled model | |
| # identical to the previous one | |
| model = load_model('my_model.h5') |
This file contains hidden or 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
| checkpoint = ModelCheckpoint('./test/, monitor='val_acc') | |
| model.fit(x_train, y_train, | |
| callbacks=[checkpoint]) |
This file contains hidden or 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
| with tf.Session() as sess: | |
| tf.saved_model.loader.load(sess, [tag_constants.TRAINING], './test/') |