Search code examples
tensorflow-litegoogle-coral

Retraining on device Coral Edge TPU - output tensor size


I am following the example here https://coral.ai/docs/edgetpu/retrain-classification-ondevice/#api-summary for customizing a model (initially MobileNet v1) using the sample code provided (imprinting_learning.py).

I got this to work, and it runs well classifying an image or video stream using the above mentioned model.

I am now trying to use it to customize a model that will work for object detection, making bounding boxes. When I first just tried to use the newly retrained model (based on, as given in the sample, mobilenetV1), I got

Detection model should have 4 output tensors! This model has 1.

I tried starting a new re-training based on the model mobilenet_ssd_v2_coco_quant_postprocess_edgetpu.tflite , (which I have used successfully for object detection in the past), I got an error during training (using imprinting_learning.py)

RuntimeError: Logit output tensor should be [1,x]

Thanks for the help!


Solution

  • I believe you have reached out to our private channel regarding this question, however I want to answer the question here with mode details, so that other can reference. There are a couple things I'd like to clarify:

    • In order for a model to works with the ImprintingEngine, it'll need to be prepared. With you feeding the model in the state that it is, there is no way for the imprinting engine to update the weight to the behavior we want. The process for that is quite complicated and a little outside of our support scope, but more details can be found here. If you want to prepare your own model, the backprop would be a much simpler approach as you'll just need to prepare an embedding extractor! Our page have instructions on how to create embedding extractors. And the backprop uses a technique calls softmax regression.

    • In either case, the object detection model will not work with our on device learning tutorials, unfortunately. The error message clearly state that the output tensor are mismatched that layer cannot be compatible with the imprinting engine or the softmax regression engine. The tutorial were designed only for classification. You can learn more about the output tensor of the object detection model on this page.

    For object detection retraining, there is this tutorial, although it'll requires resources from your host machine: https://coral.ai/docs/edgetpu/retrain-detection/