Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 21 additions & 22 deletions tftrt/examples/object_detection/install_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
5 changes: 3 additions & 2 deletions tftrt/examples/object_detection/object_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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:
Expand Down
7 changes: 6 additions & 1 deletion tftrt/examples/object_detection/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down