analogdevicesinc / ai8x-synthesis

Quantization and Synthesis (Device Specific Code Generation) for ADI's MAX78000 and MAX78002 Edge AI Devices
Apache License 2.0
57 stars 56 forks source link

BN error #350

Closed fzh-adham closed 2 months ago

fzh-adham commented 4 months ago

hi when I want to generate c files I get this error "the checkpoint file contains 1-dimensional weights for conv1.bn.weight with dimensions (24,). Ensure the BatchNorm layers have been folded." what is the problem and what is the solution?

ermanok commented 4 months ago

Hello,

The hardware does not support BatchNorm (BN) layer so if you want to use a BN layer in your model, you have to fuse these layers to the preceding convolution layers (see here). If you enable Quantization Aware Training (QAT) during your model training, the code automatically folds the the batchnorm layers. So if you use qat_checkpoint.pth.tar or qat_best.path.tar, you will not get such an error during the code synthesis. If you want to use post training quantization without QAT, you may run batchnormfuser.py to fold the BN layers to the convolutional layers.

fzh-adham commented 4 months ago

Hi Thanks for reply Yes,I have trained in both ways and I just have problem in none qat So for your second choice in command how do I run my model in training with batchnormfuser.py Could you please tell me in details🙏🙏

On Thu, 25 Jul 2024, 12:35 Erman Okman, @.***> wrote:

Hello,

The hardware does not support BatchNorm (BN) layer so if you want to use a BN layer in your model, you have to fuse these layers to the preceding convolution layers (see here https://github.com/analogdevicesinc/ai8x-training?tab=readme-ov-file#batch-normalization). If you enable Quantization Aware Training (QAT) during your model training, the code automatically folds the the batchnorm layers. So if you use qat_checkpoint.pth.tar or qat_best.path.tar, you will not get such an error during the code synthesis. If you want to use post training quantization without QAT, you may run batchnormfuser.py to fold the BN layers to the convolutional layers.

— Reply to this email directly, view it on GitHub https://github.com/analogdevicesinc/ai8x-synthesis/issues/350#issuecomment-2249838414, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWLZTJMP5HZEYDLOCBTZ2VTZOC5TZAVCNFSM6AAAAABLMOLD62VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENBZHAZTQNBRGQ . You are receiving this because you authored the thread.Message ID: @.***>

ermanok commented 4 months ago

It is a python script that you can run from the command line. The details of the batchnormfuser is here. But we always suggest to use QAT as the direct quantization of a floating model may cause huge accuracy drop.

fzh-adham commented 4 months ago

Thanks a lot

I have another problem in command

In the documentation is suggested to use --energy for energy during processing but in my max78000fthr board it doesn't show

How can I get energy ?

On Thu, 25 Jul 2024, 13:46 Erman Okman, @.***> wrote:

It is a python script that you can run from the command line. The details of the batchnormfuser is here https://github.com/analogdevicesinc/ai8x-training?tab=readme-ov-file#command-line-arguments-1. But we always suggest to use QAT as the direct quantization of a floating model may cause huge accuracy drop.

— Reply to this email directly, view it on GitHub https://github.com/analogdevicesinc/ai8x-synthesis/issues/350#issuecomment-2249979424, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWLZTJJ4F5JSUTFC4S7KJWTZODGALAVCNFSM6AAAAABLMOLD62VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENBZHE3TSNBSGQ . You are receiving this because you authored the thread.Message ID: @.***>

ermanok commented 4 months ago

You need a MAX78000 EvKit to measure and observe the energy consumption. The feather board does not have an energy measurement circuitry.

fzh-adham commented 4 months ago

thanks for reply is there any way to calculate energy consumption and power?

ermanok commented 3 months ago

There is no other straightforward approach to measure the energy consumption.

github-actions[bot] commented 2 months ago

This issue has been marked stale because it has been open for over 30 days with no activity. It will be closed automatically in 10 days unless a comment is added or the "Stale" label is removed.