I trained a tflite model for iris dataset. It takes in 4 floating point numbers as input and returns softmax prediction for 3 flower categories. When I tried to convert the tflitemodel to kmodel(tflite2kmodel.sh), I saw that there should be some images in an image folder for k210model output. But my model is not for images. Is there any way I can run this model in Maix?
for those small input, you need padding zeros for data input, as kpu minimum input size is 4x4
so, you can padding zeros to make input to 4x4 matrix or above.
and normalization float to 0~255 before input.
Thanks for the info on 4x4 input. So for a 4x1 input, I need to map my data into 0-255 and use it as a pixel in image? coz to convert to kmodel, I need to put some images in the image folder of nncase tool.
Is there any plan to include non image models? For example, if I am getting data from multiple sensors, I would like to feed them into a neural net to get some decision. Also scaling to 0-255 may cause loss of precision or information sometimes.
you can generate 4x4 pic via some python script.
it is not case for non-image model, it is just quantization problem.
If you think 8bit is too short, you can quantize to 16bit, and put 8bit to high byte, 8bit to low byte.
when you train model, weights will automatically know what it mean
Sorry if I “hijack” this topic. I managed to convert my Tensorflow model to kmodel. It’s for Activity Recognition based on accelerometer data.
But for Maixpy, KPU forward method expects image data as input, while my data should be array of float with shape: 3x90x1
How can I use MaixPy to do inference @Zepan ?
I guess you have 3-D sensor and 90 frames data
first you should convert float to 8bit data, and pad data to 4x90x1, as kpu support at least 4 pixels.
now you can make an gray image in Maixpy, and fill data in it (just use img[x+y*90] to fill)
then use ing.pix_to_ai to fill ai buf.
then you can use kpu.run to calculate
@Zepan it’s indeed 3d sensor with 90 data window. Thanks for responding.
Ah yes, gray image will do. Could you advise how to convert float data to 8 bit integer without losing too much precision?
can you post demo data array?
I recently saw a demo provided by kendryte where they can take iris dataset as 4x1 array.
Can this be done in Maixpy?
Since now nncase supports float?
Training for non-image based models
@Zepan you could try to use this test data (dumped by numpy): https://github.com/Shahnawax/HAR-CNN-Keras/blob/master/testData.npy
I also asked the same question on Telegram Group. Apparently, currently Maixpy expects the first layer to be Convolution layer, not Dense layer as the Iris example. Maixpy code needs to be updated.
you can add dummy conv layer first, I’m doing model convertor this week
I’ve shared my code, model, and the issue. Please take a look: Human Activity Recognition (HAR) model and demo (still has issues)