# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# + [markdown] id="yVmCc9NPkP3U"
# # Convert the model
# Once we have have the TensorFlow graph proto we can use it in Python, but we are going to take it a step further and convert the model to TensorFlow.js so we can use it directly in the browser.
#
# The model only detects objects as the IDs in out `label_map.pbtxt` so we also need to create a json list of all of our labels so we can map the ID back to a label.

# + id="A-f5lfcnp01e"
# !tensorflowjs_converter \
#     --input_format=tf_frozen_model \
#     --output_format=tfjs_graph_model \
#     --output_node_names='Postprocessor/ExpandDims_1,Postprocessor/Slice' \
#     --quantization_bytes=1 \
#     --skip_op_check \
#     $EXPORTED_PATH/frozen_inference_graph.pb \
#     model_web

import json

from object_detection.utils.label_map_util import get_label_map_dict

label_map = get_label_map_dict(LABEL_MAP_PATH)
label_array = [k for k in sorted(label_map, key=label_map.get)]

with open(os.path.join('model_web', 'labels.json'), 'w') as f:
    json.dump(label_array, f)

StarcoderdataJupyterScriptsDedupFiltered