kendryte / canmv

Other
58 stars 21 forks source link

SYSCALL: Out of memory when loading v5 model #34

Closed BillisC closed 1 year ago

BillisC commented 1 year ago

Describe the bug Using feat/kpu branch, I tried loading my squeezenet model (quantized & kmodel v5) but the results were:

Probe model size failed, will skip size check.                                                    
E (791017052) SYSCALL: Out of memory                                                              

Traceback (most recent call last):                                                                
  File "boot.py", line 13, in <module>                                                            
OSError: Failed to load model

I should note that the firmware is very minimal and I've replaced nncase runtime v1.1 with v1.8 to match my model's compiler. I attached the files in the zip: files.zip

Please complete the following information

kendryte747 commented 1 year ago

The firmware is too big to run Kmodel v5, you can set Minimum size OMV function ON. image

BillisC commented 1 year ago

Alright so I've managed to shrink firmware's size down to 1.6 MB, but the issue is still the same. I even tried reducing GC heap size and free memory was like this:

Free GC Heap: 374KB                                                                                  
Free Heap: 3712KB 

It's pretty weird that the model cannot fit inside the memory. What else could cause this? The model originated from Pytorch and it was converted to ONNX (hence the need for KModel v5).

BillisC commented 1 year ago

I'm loading the model from my SD card if that helps

kendryte747 commented 1 year ago

You can use older nncase runtime.

BillisC commented 1 year ago

Tried nncase v1.1 and still out of memory. Apparently I tried a custom lenet5 model with v5 and it worked by allocating only ~100kb. So could it be that the model input/output layers could trouble k210? It's squeezenet with 1000 classes output.

kendryte747 commented 1 year ago

input and output layer will alloc some memory, maybe it cause the issuse.

narduzzi commented 1 year ago

Hi @BillisC, how did you replace the runtime of nncase? Did you had to change any file in this project? Is replacing the kmodel file sufficient?