kendryte / canmv

Other
58 stars 21 forks source link

Strange output format #38

Closed narduzzi closed 1 year ago

narduzzi commented 1 year ago

Hi,

I am trying to run a Mnist network on JPEG images (3-channels, range 0-255), and the output is the following:

...
filename = "/sd/img0.bmp"
img = image.Image(filename)
img.pix_to_ai()
kpu.run(img)
out_values = kpu.get_outputs()
print(out_values)

>>> [//./////, //./////, //./////, //./////, //./////, //./////, //./////, //./////, //./////, //./////]

I have trained my model using Keras. The network is then converted to TFLite

def keras_to_tflite(keras_model: str, tflite_path: str, custom_objects: dict = {}) -> str:
        keras_model = tf.keras.models.load_model(keras_model, custom_objects=custom_objects)
        save_folder = os.path.join(tflite_path.replace(".tflite", ""))
        keras_model.save(save_folder)
        # Convert the model
        converter = tf.lite.TFLiteConverter.from_saved_model(save_folder)  # path to the SavedModel directory
        tflite_model = converter.convert()

        # Save the model.
        with open(tflite_path, 'wb') as f:
            f.write(tflite_model)

    return tflite_path

And finally to KModelV5 using NNCase 1.8.0. This is the configuration I have used:

compile_options = nncase.CompileOptions()
compile_options.target = 'k210'
compile_options.input_type = 'uint8'
compile_options.input_shape = [1,3,28,28]
compile_options.input_layout = "NCHW"
compile_options.output_layout = "NCHW"
compile_options.model_layout = 'NHWC'
compile_options.preprocess = True
compile_options.dump_ir = True
compile_options.dump_asm = True
compile_options.dump_dir = 'tmp'

Is something missing from my configuration? The simulation works fine.

Please complete the following information

narduzzi commented 1 year ago

Nevermind, my input data type was wrong.