You need to export the model. I have a PR that exports a model during retraining. Its essence is below:
import tensorflow as tf def export_model(sess, architecture, saved_model_dir): if architecture == 'inception_v3': input_tensor = 'DecodeJpeg/contents:0' elif architecture.startswith('mobilenet_'): input_tensor = 'input:0' else: raise ValueError('Unknown architecture', architecture) in_image = sess.graph.get_tensor_by_name(input_tensor) inputs = {'image': tf.saved_model.utils.build_tensor_info(in_image)} out_classes = sess.graph.get_tensor_by_name('final_result:0') outputs = {'prediction': tf.saved_model.utils.build_tensor_info(out_classes)} signature = tf.saved_model.signature_def_utils.build_signature_def( inputs=inputs, outputs=outputs, method_name=tf.saved_model.signature_constants.PREDICT_METHOD_NAME ) legacy_init_op = tf.group(tf.tables_initializer(), name='legacy_init_op')
Above, a directory of variables and the file saved_model.pb will be created. If you put it in the parent directory representing the version number (e.g. 1 /), you can call the tensor flow function using:
tensorflow_model_server --port=9000 --model_name=inception --model_base_path=/path/to/saved_models/
source share