google-coral / coralmicro

Source code for Coral Dev Board Micro
Apache License 2.0
106 stars 44 forks source link

Different results between inference on CPU and TPU #117

Closed Gorge997 closed 4 months ago

Gorge997 commented 5 months ago

Description

I was trying to implement the code needed to run the MLPerf-Tiny benchmark suite's networks on the coral micro board.

After finding the problem related to serial communication (described in issue #116) i was able to write the code, send the input values from the pc to the board and run the inference. I found that while the inference results on cpu are correct, the inference results on TPU are very wrong. In the sense that not only do the results vary a little, but the performance of the benchmark goes from about 80% accuracy to 10% accuracy.

Using as an example the ResNet used in the ImageClassification benchmark: The original network is (image generated using Netron): image

This network was created, trained and quantized using the scripts provided in the MLPerf-tiny benchmark repo/training folder

The network, after the compilation using edgetpu-compiler is: image

Using as an example the file the first test image (an emu): Figure_1 the results are: CPU: [0.000,0.000,0.664,0.281,0.051,0.000,0.004,0.000,0.000,0.000] TPU: [0.000,0.000,0.000,0.004,0.000,0.621,0.000,0.371,0.000,0.000]

label_names: ['airplane', 'automobile', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck']

so the CPU recognize that the image depicts a bird while the TPU return very different and wrong results.

I found other issue describing the same problem and I decided to try to run some layers of the network on the CPU in order to find out which one is the cause of these different results. I tried splitting the model using the -i flag on both the output tensors of the add layers. Both the times the inference was completed but again with wrong results.

I then tried to split the model before the first add layer., specifying the output of the first Conv2D layer, obtaining the network below. image

This time the inference hanged the code and no result was provided. ( The problem is in the inference phase because i turn on the user led before calling interpreter.Invoke() and turn off it as soon as the inference ends).

Additional informations:

Click to expand! ### Issue Type Support ### Operating System Ubuntu ### Coral Device Dev Board Micro ### Other Devices _No response_ ### Programming Language C++ ### Relevant Log Output _No response_
google-coral-bot[bot] commented 4 months ago

Are you satisfied with the resolution of your issue? Yes No