Skip to content

Instantly share code, notes, and snippets.

@salman-ghauri
Created January 9, 2019 16:09
Show Gist options
  • Save salman-ghauri/bb3109b1ebc08ffb6923bcfa7e49d428 to your computer and use it in GitHub Desktop.
Save salman-ghauri/bb3109b1ebc08ffb6923bcfa7e49d428 to your computer and use it in GitHub Desktop.
import tensorflow as tf
# Assuming object detection API is available for use
from object_detection.utils.config_util import create_pipeline_proto_from_configs
from object_detection.utils.config_util import get_configs_from_pipeline_file
import object_detection.tf_server_export_inference_graph
# Configuration for model to be exported, the pipeline_config_path
config_pathname = "custom_detection/configs/101resnet_frcnn_coco.config"
# Input checkpoint for the model to be exported
# Path to the directory which consists of the saved model on disk (see above)
trained_model_dir = "custom_detection/training/res2out"
# Create proto from model confguration
configs = get_configs_from_pipeline_file(config_pathname)
pipeline_proto = create_pipeline_proto_from_configs(configs=configs)
# Read .ckpt and .meta files from model directory
checkpoint = tf.train.get_checkpoint_state(trained_model_dir)
input_checkpoint = checkpoint.model_checkpoint_path
print(input_checkpoint)
# Model Version
model_version_id = 1
# Output Directory
output_directory = "custom_detection/serving/res2out/" + str(model_version_id)
# Export model for serving
object_detection.serving_exporter.export_inference_graph(input_type='image_tensor',
pipeline_config=pipeline_proto,
trained_checkpoint_prefix=input_checkpoint,
output_directory=output_directory)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment