Trying to convert Mobilenet_v2 from Tensorflow to Tensor RT

Hi,

I am trying to convert the Tensorflow Version of Mobilenet_v2 to a Tensor RT Version. I have been using the following Project ( https://github.com/NVIDIA-Jetson/tf_to_trt_image_classification#models ) to learn how to convert Tensorflow Models. My issue occurs when I am trying to convert the frozen graphs to plans

Command Line:
python scripts/frozen_graphs_to_plans_mob_2.py
Traceback (most recent call last):
File “scripts/frozen_graphs_to_plans_mob_2.py”, line 9, in
from model_meta_mob_2 import NETS, FROZEN_GRAPHS_DIR, CHECKPOINT_DIR, PLAN_DIR
File “/home/nvidia/tf_to_trt_image_classification/scripts/model_meta_mob_2.py”, line 71, in
‘model’: mobilenet_v2_1p0_224,
NameError: name ‘mobilenet_v2_1p0_224’ is not defined

Where frozen_graphs_to_plans_mob_2.py, is a modified Version of the frozen_graphs_to_plans.py given in the Project. The same applies to the model_meta_mob_2.py file.
The only changes made to the frozen_graphs_to_plans.py file are that on line 6 I have ‘from model_meta_mob_2 Import Nets’ instead of ‘model_meta Import Nets’

The changes to model_meta_mod_2.py file are that I added;
‘Import slim.nets.mobilenet_v2’
and added to following to the NETS section;

‘mobilenet_v2_1p0_224’: {
‘model’: mobilenet_v2_1p0_224,
‘arg_scope’: nets.mobilenet_v2.mobilenet_v2_arg_scope,
‘num_classes’: 1001,
‘input_name’: ‘input’,
‘input_width’: 224,
‘input_height’: 224,
‘input_channels’: 3,
‘output_names’: [‘MobilenetV2/Logits/SpatialSqueeze’],
‘checkpoint_filename’: CHECKPOINT_DIR +
‘mobilenet_v2_1.0_224.ckpt’,
‘frozen_graph_filename’: FROZEN_GRAPHS_DIR + ‘mobilenet_v2_1p0_224.pb’,
‘plan_filename’: PLAN_DIR + ‘mobilenet_v2_1p0_224.plan’,
‘preprocess_fn’: preprocess_inception,
‘postprocess_fn’: postprocess_inception,
},

Other bits of info:

I have downloaded the checkpoints for MobileNet_V2_1.0_224 from https://github.com/tensorflow/models/tree/master/research/slim/nets/mobilenet

I am trying to run this on a Jetson TX2, with the lastest Version of Jetpack 3.2 and I have tensorflow 1.5 installed.

Any help would be greatly appreciated

Hi,

It’s recommended to following the instruction shown in the main page:

Suppose the required models can be downloaded with this command:

source scripts/download_models.sh

And be transferred into frozen graphs with this command:

python scripts/models_to_frozen_graphs.py

Thanks.

Hi,

Thanks for the quick reply.

The issue is that the mobilenet_v2 is not part of the require models given in the project.
The commands worked perfectly for all the models that they listed though. What I was trying to do was to edit some files, such that they would work for mobilenet_v2 (mobilenet_v2_1.0_224 in particular)

I think my real issue is that I don’t know where to define mobilenet_v2_1.0_224, I thought I could simply edit the model_meta.py file and that would be sufficient. Which doesn’t seem to be correct, but I am not sure what to do instead

Hi,

Could you try to use mobilenet_v2_1.0_224 instead of mobilenet_v2_1p0_224?

Thanks.

Hi AastaLLL,

changing it to mobilenet_v2_1.0_224 doesnt make a difference and the frozen file is called mobilenet_v2_1p0_224. However I did try changing both to mobilenet_v2_1.0_224 but it didn’t work.

I have been working on the issues some more and I believe my mistake lies with
‘output_names’: [‘MobilenetV2/Logits/SpatialSqueeze’],
from the meta file. This is something I simply copied from the project and changed ‘MobilenetV1’ to ‘MobilenetV2’. The error is that it isnt defined, however I don’t know where to define it, or what ‘output_names’ is meant to represent.

Thanks

Hi,

You can find the output name information via TensorFlow.
Please import your model first and print out the model definition with graphdef.

Thanks.

Hi Aastall,

I have not been able to try this yet. I will post here if I get it to work.
Thank you for your advice!

Hi

Did you have success in importing Mobilenet V2 into TensorRT?