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

Always returning 100 detections with .tflite #529

Closed
aocz1 opened this issue Jun 18, 2020 · 10 comments
Closed

Always returning 100 detections with .tflite #529

aocz1 opened this issue Jun 18, 2020 · 10 comments

Comments

@aocz1
Copy link

aocz1 commented Jun 18, 2020

I've successfully managed to train and export models to .tflite with this library, though it appears as though the shape returned with .tflite is [1, 100, 7]. I would like to return less detection's in order to speed up the inference time on mobile devices, is there a way to do this? I have already tried using the hparam "max_instances_per_image", but that doesn't seem to change anything.

@mingxingtan
Copy link
Member

Hi @aocz1 You should change this flag to smaller value (it is 100 if None):

flags.DEFINE_integer('max_boxes_to_draw', None, 'Max number of boxes to draw.')

Also, if you want fast, the easy way is to use smaller images (the current input images are pretty big).

@aocz1
Copy link
Author

aocz1 commented Jun 18, 2020

Cheers, so the setting only needs to be changed when using model_inspect.py to generate the model files from the checkpoint?

@mingxingtan
Copy link
Member

that's right

@zishanahmed08
Copy link

@aocz1 Hi Ales, Is there a open source android app example for use with efficient det tflite?

@aocz1
Copy link
Author

aocz1 commented Jun 19, 2020

@zishanahmed08 Yes there are several example android apps using tensorflow lite, like here (https://github.com/tensorflow/examples/tree/master/lite/examples/object_detection/android).

Basically you would have to adapt the TFLiteObjectDetectionAPIModel class so that it can read your efficientdet model. The example app I've linked above has a model that returns the following arrays:

outputLocations = new float[1][NUM_DETECTIONS][4];
outputClasses = new float[1][NUM_DETECTIONS];
outputScores = new float[1][NUM_DETECTIONS];
numDetections = new float[1];

While our efficientdet model will return a single 3D array with dimensions of [1][MAX_BOXES][7].

Once you've mapped the results into the array, you can access the results programatically and process them however you wish.

@zishanahmed08
Copy link

@aocz1 Alex, thanks for the info. Do you have fork with these changes?

@zishanahmed08
Copy link

@aocz1 A gentle reminder

@aocz1
Copy link
Author

aocz1 commented Jun 23, 2020

@zishanahmed08 Apologies, I was out of office the last few days.

I do not have a fork with the changes, however you can find some useful information about using EfficientDet with TensorflowLite on android in another issue #533

If you're looking to learn about running a tflite model on android, I would suggest building and having a play around with https://github.com/tensorflow/examples/tree/master/lite/examples/object_detection/android and look to gain an understanding of how the code works.

Once you understand how it works, then it's a matter of changing some of the variables (such as input size) and the output array in the TFLiteObjectDetectionAPIModel class to match your own efficientdet model.

@Abdktefane
Copy link

Abdktefane commented Jul 15, 2020

@mingxingtan
after i try this :
python model_inspect.py --runmode=saved_model --model_name=efficientdet-d0 \ --ckpt_path=efficientdet-d0 --saved_model_dir=savedmodeldir \ --tflite_path=efficientdet-d0.tflite --max_boxes_to_draw=20
still return 100 and preduce this error
Cannot copy from a TensorFlowLite tensor (detections) with shape [1, 100, 7] to a Java object with shape [1, 20, 7]

@mingxingtan
Copy link
Member

@Abdktefane I recently made some changes that invalid those options. Will be fixed in db40ab7

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

No branches or pull requests

4 participants