Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test_forward_ssd_mobilenet_v1 to tflite/test_forward #3350

Merged
merged 1 commit into from
Jun 14, 2019

Conversation

apivovarov
Copy link
Contributor

@apivovarov apivovarov commented Jun 12, 2019

This tests uses official non-quantized model ssd_mobilenet_v1_coco downloaded from https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md

ssd_mobilenet_v1_coco_2018_01_28.tar.gz contains checkpoint.
To generate tflite file I exported the checkpoint to tflite_graph.pb file using object_detection/export_tflite_ssd_graph.py form `tensorflow/models' repo.

Then I converted tflite_graph.pb file to TFLITE format using the command below.
Because TFLite frontend does not support custom operators I did not include custom operator TFLite_Detection_PostProcess which are the last operator in the graph.
I did that by specifying --output_arrays as raw_outputs/class_predictions,raw_outputs/box_encodings which are inputs for TFLite_Detection_PostProcess op.
Users can do PostProcessing outside of TVM.
post-processing code is here

# FLOAT no Post Processing
export TFM_PATH=<path_to_dir_containing_tflite_graph.pb>
export FMT=TFLITE
tflite_convert \
--graph_def_file=$TFM_PATH/tflite_graph.pb \
--output_file=$TFM_PATH/model_nopp.tflite \
--output_format=$FMT \
--input_arrays=normalized_input_image_tensor \
--input_shapes=1,300,300,3 \
--inference_type=FLOAT \
--output_arrays="raw_outputs/class_predictions,raw_outputs/box_encodings"

Graph visualization

I uploaded resulting model_nopp.tflite file to s3 bucket belonging to neo-ai organization

@apivovarov
Copy link
Contributor Author

apivovarov commented Jun 12, 2019

ci_2: All checks have passed

ci_1: test_vm.test_sum_loop ... ./tests/scripts/task_python_integration.sh: line 41: 31003 Segmentation fault (core dumped) TVM_FFI=ctypes python3 -m nose -v tests/python/relay
http://ci.tvm.ai:8080/blue/organizations/jenkins/tvm/detail/PR-3350/1/pipeline

@apivovarov
Copy link
Contributor Author

@FrozenGene @kevinthesun @yongwww Could you review?

@@ -567,6 +567,24 @@ def test_forward_inception_v4_net():
tvm.testing.assert_allclose(np.squeeze(tvm_output[0]), np.squeeze(tflite_output[0]),
rtol=1e-5, atol=1e-5)

#######################################################################
# SSD Mobilenet
# ---------
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to be

# SSD Mobilenet
---------------

Keep the same length

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

"""Test the SSD Mobilenet V1 TF Lite model."""
# SSD MobilenetV1
tflite_model_file = tf_testing.get_workload_official(
"https://neo-ai-dlr-test-artifacts.s3-us-west-2.amazonaws.com/tflite-models/ssd_mobilenet_v1_coco_2018_01_28_nopp.tgz",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this to our dmlc / web-data : https://github.com/dmlc/web-data

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or download the model directly from tf lite community if possible

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TF provides tflite files only for quantized models, but TVM does not support quantized models yet.
For non-quantized models they provide tflite_graph.pb file which is compatible with tflite_convert util and can be converted to tflite file.

For now I can put my tflite converted file to dmlc/web-data.

I can also investigate if Jenkins worker has tflite_convert util or python module tensorflow.lite.TFLiteConverter available. In that case I can download tgz model file from Tensorflow zoo, unpack it and convert tflite_graph.pb to tflite file.

Copy link
Contributor Author

@apivovarov apivovarov Jun 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, official non-quantized tar.gz ssd model files do not have tflite_graph.pb. They only have inference pb file and a checkpoint.
tflite_graph.pb can be created from checkpoint using object_detection/export_tflite_ssd_graph.py from tensorflow/models repo.
We do not have this repo and util on Jenkins worker.

I opened PR to add tflite model packed to tar.gz ssd_mobilenet_v1_coco_2018_01_28_nopp.tgz to dmlc/web-data
dmlc/web-data#186

"""Test the SSD Mobilenet V1 TF Lite model."""
# SSD MobilenetV1
tflite_model_file = tf_testing.get_workload_official(
"https://raw.githubusercontent.com/apivovarov/web-data/dev/tensorflow/models/object_detection/ssd_mobilenet_v1_coco_2018_01_28_nopp.tgz",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will change it to dmlc once dmlc/web-data#186 is merged

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@apivovarov apivovarov force-pushed the tflite branch 2 times, most recently from 2076e54 to 6193ccc Compare June 13, 2019 22:34
@apivovarov
Copy link
Contributor Author

@FrozenGene CI build/test passed. Can you merge it?

@FrozenGene
Copy link
Member

@FrozenGene CI build/test passed. Can you merge it?

I don't have merge privilege. ping @tqchen @srkreddy1238 help to handle.

@apivovarov
Copy link
Contributor Author

@FrozenGene @yongwww Can you approve the PR?

Copy link
Member

@yongwww yongwww left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kevinthesun kevinthesun merged commit 59d8ba8 into apache:master Jun 14, 2019
@kevinthesun
Copy link
Contributor

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants