diff --git a/models/trt/.gitattributes b/models/trt/.gitattributes new file mode 100644 index 00000000000000..75ae2089a5ae46 --- /dev/null +++ b/models/trt/.gitattributes @@ -0,0 +1 @@ +*.trt filter=lfs diff=lfs merge=lfs -text diff --git a/models/trt/dmonitoring.metadata b/models/trt/dmonitoring.metadata new file mode 100644 index 00000000000000..1f688bd3eb935e --- /dev/null +++ b/models/trt/dmonitoring.metadata @@ -0,0 +1 @@ +{"input_names": ["input_img"], "output_names": ["face_descs/BiasAdd", "face_prob/Sigmoid", "left_blink_prob/Sigmoid", "left_eye_descs/BiasAdd", "left_eye_prob/Sigmoid", "right_blink_prob/Sigmoid", "right_eye_descs/BiasAdd", "right_eye_prob/Sigmoid"]} \ No newline at end of file diff --git a/models/trt/dmonitoring.trt b/models/trt/dmonitoring.trt new file mode 100644 index 00000000000000..6ce8f20b021e16 --- /dev/null +++ b/models/trt/dmonitoring.trt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:268008cbf8b13dc8fcb4bb4fdbd388ded5419b5a8c0f721aeb558a10896f2be1 +size 716746 diff --git a/models/trt/supercombo.metadata b/models/trt/supercombo.metadata new file mode 100644 index 00000000000000..06b08d74856a32 --- /dev/null +++ b/models/trt/supercombo.metadata @@ -0,0 +1 @@ +{"input_names": ["desire", "input_imgs", "rnn_state", "traffic_convention"], "output_names": ["add_3/add", "desire_state/Softmax", "flatten/Reshape", "lead/BiasAdd", "left_lane/BiasAdd", "long_a/BiasAdd", "long_v/BiasAdd", "long_x/BiasAdd", "meta/Sigmoid", "path/BiasAdd", "pose/pose/Identity", "right_lane/BiasAdd"]} \ No newline at end of file diff --git a/models/trt/supercombo.trt b/models/trt/supercombo.trt new file mode 100644 index 00000000000000..7baff2eac3d60c --- /dev/null +++ b/models/trt/supercombo.trt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f8531ddd4ca16fa9637dace93438c6eb109cca19ae700c6e2606ddf3e5d82d9a +size 78652778 diff --git a/tools/keras/convert_trt.py b/tools/keras/convert_trt.py new file mode 100755 index 00000000000000..bd007e66f4214e --- /dev/null +++ b/tools/keras/convert_trt.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 + +import os + +import json +from pathlib import Path +import tensorflow as tf +import sys + +in_model = os.path.expanduser(sys.argv[1]) +output = os.path.expanduser(sys.argv[2]) +output_path = Path(output) +output_meta = Path('%s/%s.metadata' % (output_path.parent.as_posix(), output_path.stem)) + + +# Reset session +tf.keras.backend.clear_session() +tf.keras.backend.set_learning_phase(0) + +model = tf.keras.models.load_model(in_model, compile=False) +session = tf.keras.backend.get_session() + +input_names = sorted([layer.op.name for layer in model.inputs]) +output_names = sorted([layer.op.name for layer in model.outputs]) + +# Store additional information in metadata, useful when creating a TensorRT network +meta = {'input_names': input_names, 'output_names': output_names} + +graph = session.graph + +# Freeze Graph +with graph.as_default(): + # Convert variables to constants + graph_frozen = tf.compat.v1.graph_util.convert_variables_to_constants(session, graph.as_graph_def(), output_names) + # Remove training nodes + graph_frozen = tf.compat.v1.graph_util.remove_training_nodes(graph_frozen) + with open(output, 'wb') as output_file, open(output_meta.as_posix(), 'w') as meta_file: + output_file.write(graph_frozen.SerializeToString()) + meta_file.write(json.dumps(meta)) + + print ('Inputs = [%s], Outputs = [%s]' % (input_names, output_names)) + print ('Writing metadata to %s' % output_meta.as_posix()) + print ('To convert use: \n `convert-to-uff %s`' % (output))