diff --git a/tftrt/examples/object_detection/install_dependencies.sh b/tftrt/examples/object_detection/install_dependencies.sh index 0f55d90db..5d7a0e61a 100755 --- a/tftrt/examples/object_detection/install_dependencies.sh +++ b/tftrt/examples/object_detection/install_dependencies.sh @@ -16,26 +16,24 @@ # limitations under the License. # ============================================================================= +echo Setup local variables... TF_MODELS_DIR=third_party/models -COCO_API_DIR=third_party/cocoapi - -python -V 2>&1 | grep "Python 3" || \ - ( export DEBIAN_FRONTEND=noninteractive && \ - apt-get update && \ - apt-get install -y --no-install-recommends python-tk ) - RESEARCH_DIR=$TF_MODELS_DIR/research SLIM_DIR=$RESEARCH_DIR/slim +COCO_API_DIR=third_party/cocoapi PYCOCO_DIR=$COCO_API_DIR/PythonAPI +PROTO_BASE_URL="https://github.com/google/protobuf/releases/download/v3.5.1/" +PROTOC_DIR=$PWD/protoc -pushd $RESEARCH_DIR - -# GET PROTOC 3.5 +#echo Install python-tk ... +#python -V 2>&1 | grep "Python 3" || \ +# ( export DEBIAN_FRONTEND=noninteractive && \ +# apt-get update && \ +# apt-get install -y --no-install-recommends python-tk ) -BASE_URL="https://github.com/google/protobuf/releases/download/v3.5.1/" -PROTOC_DIR=protoc -PROTOC_EXE=$PROTOC_DIR/bin/protoc +set -v +echo Download protobuf... mkdir -p $PROTOC_DIR pushd $PROTOC_DIR ARCH=$(uname -m) @@ -47,25 +45,26 @@ else echo ERROR: $ARCH not supported. exit 1; fi -wget --no-check-certificate ${BASE_URL}${filename} -unzip ${filename} +wget --no-check-certificate ${PROTO_BASE_URL}${filename} +unzip -o ${filename} popd -# BUILD PROTOBUF FILES -$PROTOC_EXE object_detection/protos/*.proto --python_out=. - -# INSTALL OBJECT DETECTION +echo Compile object detection protobuf files... +pushd $RESEARCH_DIR +$PROTOC_DIR/bin/protoc object_detection/protos/*.proto --python_out=. +popd +echo Install tensorflow/models/research... +pushd $RESEARCH_DIR pip install -e . - popd +echo Install tensorflow/models/research/slim... pushd $SLIM_DIR pip install -e . popd -# INSTALL PYCOCOTOOLS - +echo Install cocodataset/cocoapi/PythonAPI... pushd $PYCOCO_DIR pip install -e . popd diff --git a/tftrt/examples/object_detection/object_detection.py b/tftrt/examples/object_detection/object_detection.py index 38e86a300..17e93a993 100644 --- a/tftrt/examples/object_detection/object_detection.py +++ b/tftrt/examples/object_detection/object_detection.py @@ -302,7 +302,7 @@ def optimize_model(config_path, 1] elif config.model.HasField('faster_rcnn'): if override_nms_score_threshold is not None: - config.model.faster_rcnn.second_stage_post_processing.score_threshold = override_nms_score_threshold + config.model.faster_rcnn.second_stage_post_processing.batch_non_max_suppression.score_threshold = override_nms_score_threshold if override_resizer_shape is not None: config.model.faster_rcnn.image_resizer.fixed_shape_resizer.height = override_resizer_shape[ 0] @@ -612,7 +612,8 @@ def benchmark_model(frozen_graph, statistics = { 'map': eval.stats[0], 'avg_latency_ms': 1000.0 * np.mean(runtimes), - 'avg_throughput_fps': np.sum(image_counts) / np.sum(runtimes) + 'avg_throughput_fps': np.sum(image_counts) / np.sum(runtimes), + 'runtimes_ms': [1000.0 * r for r in runtimes] } if output_path is not None: diff --git a/tftrt/examples/object_detection/test.py b/tftrt/examples/object_detection/test.py index b7c2248c6..89b1175a8 100644 --- a/tftrt/examples/object_detection/test.py +++ b/tftrt/examples/object_detection/test.py @@ -80,7 +80,12 @@ def test(test_config_path): statistics = benchmark_model( frozen_graph=frozen_graph, **test_config['benchmark_config']) - print(json.dumps(statistics, sort_keys=True, indent=4)) + + # print some statistics to command line + print_statistics = statistics + if 'runtimes_ms' in print_statistics: + print_statistics.pop('runtimes_ms') + print(json.dumps(print_statistics, sort_keys=True, indent=4)) # run assertions if 'assertions' in test_config: