The MaixPy IDE gives reports: "ValueError: [MAIXPY] kpu: load error:2003, ERR_KMODEL_FORMAT: layer_header.body_size<=0"
when executing "task = kpu.load(0x300000)" from the IDE.
The model was trained with tf/keras, stored as .tflite and converted with:
c:\apu4\nncase_git\nncase\out\bin\ncc.exe compile -i tflite -t k210 c:\apu23\model_tflite.tflite c:\apu23\tflite_tflite.kmodel --dataset c:\apu23\images_1
An equivalent model was trained with pytorch, stored as .onnx and converted with:
c:\apu4\nncase_git\nncase\out\bin\ncc.exe compile -i onnx -t k210 c:\apu23\omanet_1.onnx c:\apu23\omanet_1.kmodel --dataset c:\apu23\images_1
The error report is the same when using keras or using pytorch.
The MaixPy IDE gives reports: "ValueError: [MAIXPY] kpu: load error:2003, ERR_KMODEL_FORMAT: layer_header.body_size<=0" when executing "task = kpu.load(0x300000)" from the IDE.
The model was trained with tf/keras, stored as .tflite and converted with: c:\apu4\nncase_git\nncase\out\bin\ncc.exe compile -i tflite -t k210 c:\apu23\model_tflite.tflite c:\apu23\tflite_tflite.kmodel --dataset c:\apu23\images_1 An equivalent model was trained with pytorch, stored as .onnx and converted with: c:\apu4\nncase_git\nncase\out\bin\ncc.exe compile -i onnx -t k210 c:\apu23\omanet_1.onnx c:\apu23\omanet_1.kmodel --dataset c:\apu23\images_1
The error report is the same when using keras or using pytorch.
The keras/tf thing was:
model=keras.models.Sequential() model.add(keras.layers.Conv2D(8,(3,3),padding='same',input_shape=(28,28,1)))#no activation model.add(keras.layers.MaxPooling2D(2)) model.add(keras.layers.Conv2D(16,(3,3),padding='same')) model.add(keras.layers.Activation('relu'))
model.add(keras.layers.MaxPooling2D(2)) model.add(keras.layers.Flatten()) model.add(keras.layers.Dense(7716,activation='relu')) model.add(keras.layers.Dropout(0.2)) model.add(keras.layers.Dense(4,activation='softmax')) opti=keras.optimizers.SGD(learning_rate=0.01,momentum=0.5) model.compile(loss='categorical_crossentropy', optimizer=opti, metrics=[keras.metrics.CategoricalAccuracy()]) model.fit(x, y, epochs=5, batch_size=64, shuffle=True, validation_data=(u, v), verbose=2) model.save("treeni_1_model.h5") converter = tf.lite.TFLiteConverter.from_keras_model_file("treeni_1_model.h5") converter.experimental_new_converter = True tflite_model = converter.convert() open('model_tflite.tflite', 'wb').write(tflite_model)
Leaving out the dropout layer did not make any difference. The onnx file passes onnx.checker and works fine with onnxruntime.