kendryte / canmv

Other
58 stars 21 forks source link

Error: StackVM stack underflow #36

Closed narduzzi closed 1 year ago

narduzzi commented 1 year ago

Describe the bug Hi,

I am trying to perform inference using a MLP Network with 70 inputs.

 import sensor, image, time, lcd
from maix import KPU
import gc

lcd.init(freq=15000000)
sensor.reset()                      # Reset and initialize the sensor. It will
                                    # run automatically, call sensor.run(0) to stop
print("SensorOK")
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA)   # Set frame size to QVGA (320x240)
print("FrameSet")

print("Sensor on. Loading kmodel")

kpu = KPU()
kpu.load("/sd/audio_model.kmodel") # network input size is [1,1,1,70]

print("Start run")
try:
    while True:
        gc.collect()
        img = sensor.snapshot()

        # to grayscale
        img_gray=img.to_grayscale(1)        #convert to gray
        print("Gray:")
        print(img_gray)

        # cut at the right size
        print("CUT:")

        img_mnist2=img_gray.resize(70,1) # As a trial, use 70 pixels from the image.

        print(img_mnist2)
        a=img_mnist2.pix_to_ai()
        print(img_mnist2)
        kpu.run(img_mnist2)
        print("DONE")

        out = kpu.get_outputs()
        print(out)

except Exception as e:
    print(e)
    kpu.deinit()
    del kpu
    gc.collect()

And it raises the following exception:

error: StackVM stack underflow
Model Buffer maybe dirty!

What could be the source of the problem? I am attaching the kmodel converted using NNCase [1.9.0.]

Configuration

kendryte747 commented 1 year ago

this error is reported by nncase runtime,please check your model or use pc tool to simulate.

narduzzi commented 1 year ago

The problem was that the network was compiled using nncase 1.8.0 while the firmware was using nncase 1.1.0. Updating the firmware library to use nncase 1.8.0 and reflashing the chip solved the problem.