google-coral / edgetpu

Coral issue tracker (and legacy Edge TPU API source)
https://coral.ai
Apache License 2.0
429 stars 125 forks source link

Help understanding edgetpu compiler optimizations #832

Open SteefR opened 8 months ago

SteefR commented 8 months ago

Description

I trained a model which accepts images, but is constructed in such a way that it is input width invariant. This means I can build the model with any specified input width, and I can load the model weights (mainly convolution kernel weights) the same for any width. The number of parameters remains constant for any input width I specify.

When I compile it for the edgetpu however, changing the input width changes the optimization inside the edgetpu model. When I specify a width of 800 it is very efficient (the model is only 464.94 Kb): image

When I specify a width of 801 it is very inefficient (the model is suddenly 4.70 Mb): image

When I specify a width of 802 it is very inefficient (the model is 4.71 Mb): image

When I specify a width of 1600 it is very efficient again (the model is 1.58 Mb): image

It probably has to do with internal optimizations of the compiler, but can someone explain what to look for and how to determine an optimal width before compiling? I want to find an optimal width to use, but I do not want to compile a model for each and every input width up to 5000 pixels.

Click to expand! ### Issue Type Support ### Operating System Windows 10 ### Coral Device USB Accelerator ### Other Devices _No response_ ### Programming Language Python 3.9 ### Relevant Log Output _No response_