google / automl

Google Brain AutoML

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tensorflow Lite Model Output

mm7721 opened this issue · comments

I'm using 2.3.0.dev20200617, and have run the recommend command to create a TF Lite model:

!python model_inspect.py --runmode=saved_model --model_name=efficientdet-d0
--ckpt_path=efficientdet-d0 --saved_model_dir=savedmodeldir
--tensorrt=FP32 --tflite_path=efficientdet-d0.tflite

The .tflite file is created successfully. However, when viewing it in Netron, its output is 1x1x7, which isn't what I expected. Shouldn't there be a much larger tensor with classes, probabilities, and box coordinates?

edet0_output

Hey! May be it is correlated to max_boxes_to_draw parameter. When I open my d0.tflite in Neutron it actually does not shows shapes for the last detections tensor. But Im trying to run it on Android and for detections it currently gives me error:
java.lang.IllegalArgumentException: Cannot copy from a TensorFlowLite tensor (detections) with shape [1, 100, 7] to a Java object with shape [1, 100, 4].
which means network returns [1,100,7] shape instead of [1,1,7]

Hi @InfiniteLife , it looks like that's because your app is expecting [1, 100, 4], while our model outputs [1, 100, 7]. You may want to take a look at #529 (comment)

Notably, our model output format is [image_id, ymin, xmin, ymax, xmax, score, class] (see here)

Hi @InfiniteLife , it looks like that's because your app is expecting [1, 100, 4], while our model outputs [1, 100, 7]. You may want to take a look at #529 (comment)

Notably, our model output format is [image_id, ymin, xmin, ymax, xmax, score, class] (see here)

yeah, I was able to run it on Android-cpu, currently trying to run in on Android-gpu

Hi @InfiniteLife, could you point me to changes required in Android cpu/gpu app

I don't think this is a problem with EfficientDet's model. The structure of the model and the structure of the inference results converted using Tensorflow v2.2.0 is shown below And so it was. max_boxes_to_draw is 10. When I check the structure with Netron, the shape of the detections is undefined, but the shape of the resulting inference is correctly estimated.
Screenshot 2020-06-22 23:53:42
Screenshot 2020-06-22 23:55:01

However, tf-nightly==2.3.0-dev20200622, output shape_signature are [1, -1, 7] It seems to be. Strangely enough, the size of the detections shape confirmed by Netron and the actual size of the detections when inferred are different. The inference results report the correct shape.
Screenshot 2020-06-23 00:12:38
Screenshot 2020-06-23 00:09:47

import numpy as np
import tensorflow as tf

interpreter = tf.lite.Interpreter(model_path="efficientdet_d0_512x512_weight_quant.tflite")
interpreter.allocate_tensors()
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()

print('input:', input_details)
print('')
print('output:', output_details)

input_shape = input_details[0]['shape']
input_data = np.array(np.random.random_sample(input_shape), dtype=np.float32)
interpreter.set_tensor(input_details[0]['index'], input_data)
interpreter.invoke()
output_data = interpreter.get_tensor(output_details[0]['index'])
print('output_data.shape:', output_data.shape)

It may not be helpful, but here's my collection of quantized tflites.
https://github.com/PINTO0309/PINTO_model_zoo/tree/master/18_EfficientDet

@PINTO0309, thanks for your comments. Perhaps it's an issue with Netron. I'll investigate a bit more on my side to confirm what you're seeing.