eloquentarduino / EloquentTinyML

Eloquent interface to Tensorflow Lite for Microcontrollers
287 stars 56 forks source link

Conv1D & MaxPooling1D #16

Closed rkuo2000 closed 3 years ago

rkuo2000 commented 3 years ago

After I successfully using Kaggle to generate TinyML MNIST and running its Arduino TinyML_MNIST sample code on ESP32 I create another example which is TinyML ECG, it uses Conv1D & MaxPooling1D for ECG heartbeat classification, input_shape=(187, 1) however, it failed to predict using its Arduino TinyML_ECG sample code on ESP32 (NodeMCU32S)

I tried different TENSOR_ARENA_SIZE , 32/64 *1024, still not able to get prediction result, the below message seems not running the model with x_test.h, y_pred are all 0.00 (this ECG num_classes = 5)

It took 3 micros to run inference 0.00,0.00,0.00,0.00,0.00 Predicted Class :0 Sanity check:0

Any hint to debug this ?

eloquentarduino commented 3 years ago

Can you please share a Notebook of this?

rkuo2000 commented 3 years ago

you can download tinyml-ecg.ipynb from https://www.kaggle.com/rkuo2000/tinyml-ecg on Kaggle also the ECG heartbeat dataset from https://www.kaggle.com/shayanfazeli/heartbeat

eloquentarduino commented 3 years ago

I'm getting this error using your code.

GetModel done
Version check done
Didn't find op for builtin opcode 'EXPAND_DIMS' version '1'

Failed to get registration from op code  d

Allocation failed
AllocateTensors() failed

Cannot load Tf model
rkuo2000 commented 3 years ago

I have revised the python code Version 1. with DNN , the arduino code predict OK Version 2. with Conv1D+Conv1D+Maxpooling1D+DNN, the arduino code did NOT predict Version 3. with Conv1D+DNN, the arduino code did NOT predict Version 4. with Conv2D+DNN (need X_train.reshape(-1, 1, 187,1), predict OK (more code size, 96.18% val accuracy, predict fast 44.1ms) Version 5. with Conv2D+Conv2D+Maxpooling2D+DNN, predict OK (less code size, 97.2 val accuracy, but predict slower 265ms)

it seems Conv1D is not converted to C code correctly ?!

rkuo2000 commented 3 years ago

I have revised the python code https://www.kaggle.com/rkuo2000/tinyml-ecg Version 1. with DNN , the arduino code predict OK Version 2. with Conv1D+Conv1D+Maxpooling1D+DNN, the arduino code did NOT predict Version 3. with Conv1D+DNN, the arduino code did NOT predict Version 4. with Conv2D+DNN (need X_train.reshape(-1, 1, 187,1), predict OK (more code size, 96.18% val accuracy, predict fast 44.1ms) Version 5. with Conv2D+Conv2D+Maxpooling2D+DNN, predict OK (less code size, 97.2 val accuracy, but predict slower 265ms)

it seems Conv1D is not converted to C code correctly ?!

eloquentarduino notifications@github.com 於 2021年1月10日 週日 上午12:30寫道:

I'm getting this error using your code.

GetModel done Version check done Didn't find op for builtin opcode 'EXPAND_DIMS' version '1'

Failed to get registration from op code d

Allocation failed AllocateTensors() failed

Cannot load Tf model

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/eloquentarduino/EloquentTinyML/issues/16#issuecomment-757331151, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA2TAJFCYX5LWHNRY6UT2KDSZCABDANCNFSM4VVWCGPQ .

-- Richard Kuo (郭子仁) Adjunct Assistant Professor Electrical Engineering Dept., National Taiwan Ocean University +886-972211921

eloquentarduino commented 3 years ago

Conv1D is not listed in their supported operators: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/micro/all_ops_resolver.cc

rkuo2000 commented 3 years ago

Thanks for your help to clarify it, I have kept my python example code in Conv2D.

AhmedElkhamisi commented 3 years ago

@rkuo2000 Bro, I tried to use your code (2D CNN) but I'm getting a prediction of "nan" on the serial monitor. Can I send you my code if you can help me out?

rkuo2000 commented 3 years ago

Yes, of course you can.

AhmedElkhamisi @.***> 於 2021年7月26日 週一 上午2:24寫道:

@rkuo2000 https://github.com/rkuo2000 Bro, I tried to use your code (2D CNN) but I'm getting a prediction of "nan" on the serial monitor. Can I send you my code if you can help me out?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/eloquentarduino/EloquentTinyML/issues/16#issuecomment-886239920, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA2TAJANVRN667KT237XMQLTZRJE3ANCNFSM4VVWCGPQ .

-- Richard Kuo (郭子仁) Adjunct Assistant Professor Electrical Engineering Dept., National Taiwan Ocean University +886-972211921

rkuo2000 commented 3 years ago

It is probably your data issue, I have several Kaggle examples for your reference below: https://www.kaggle.com/rkuo2000/tinyml-airdigit https://www.kaggle.com/rkuo2000/tinyml-ecg https://www.kaggle.com/rkuo2000/tinyml-mnist https://www.kaggle.com/rkuo2000/tinyml-gtsrb https://www.kaggle.com/rkuo2000/tinyml-digit

Richard Kuo @.***> 於 2021年7月26日 週一 上午2:39寫道:

Yes, of course you can.

AhmedElkhamisi @.***> 於 2021年7月26日 週一 上午2:24寫道:

@rkuo2000 https://github.com/rkuo2000 Bro, I tried to use your code (2D CNN) but I'm getting a prediction of "nan" on the serial monitor. Can I send you my code if you can help me out?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/eloquentarduino/EloquentTinyML/issues/16#issuecomment-886239920, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA2TAJANVRN667KT237XMQLTZRJE3ANCNFSM4VVWCGPQ .

-- Richard Kuo (郭子仁) Adjunct Assistant Professor Electrical Engineering Dept., National Taiwan Ocean University +886-972211921

-- Richard Kuo (郭子仁) Adjunct Assistant Professor Electrical Engineering Dept., National Taiwan Ocean University +886-972211921

AhmedElkhamisi commented 3 years ago

Is the export test data essential?? My project is on ECG too.

AhmedElkhamisi commented 3 years ago

@rkuo2000 How do you upload your code to arduino? I used your exact same code but it didn't predict for me.

rkuo2000 commented 3 years ago

Please look into https://github.com/rkuo2000/arduino/tree/master/examples TinyML_AirDigit TinyML_Digit TinyML_ECG TinyML_MNIST

upload code into ESP32 (NodeMCU-32S) using Arduino IDE

AhmedElkhamisi @.***> 於 2021年7月26日 週一 上午3:17寫道:

@rkuo2000 https://github.com/rkuo2000 How do you upload your code to arduino? I used your exact same code but it didn't predict for me.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/eloquentarduino/EloquentTinyML/issues/16#issuecomment-886245742, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA2TAJDG7EUY6QKQTHNJBZLTZRPLHANCNFSM4VVWCGPQ .

-- Richard Kuo (郭子仁) Adjunct Assistant Professor Electrical Engineering Dept., National Taiwan Ocean University +886-972211921

AhmedElkhamisi commented 3 years ago

Please look into https://github.com/rkuo2000/arduino/tree/master/examples TinyML_AirDigit TinyML_Digit TinyML_ECG TinyML_MNIST upload code into ESP32 (NodeMCU-32S) using Arduino IDE AhmedElkhamisi @.***> 於 2021年7月26日 週一 上午3:17寫道: @rkuo2000 https://github.com/rkuo2000 How do you upload your code to arduino? I used your exact same code but it didn't predict for me. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#16 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA2TAJDG7EUY6QKQTHNJBZLTZRPLHANCNFSM4VVWCGPQ . -- Richard Kuo (郭子仁) Adjunct Assistant Professor Electrical Engineering Dept., National Taiwan Ocean University +886-972211921

Thanks a lot!

eloquentarduino commented 3 years ago

@AhmedElkhamisi did you solved your error? I get many requests of help for NaN values, I will definetly update the examples to clarify how the input should be formatted for Conv2D to work

@rkuo2000 I'm glad you now mastered the TinyML workflow

AhmedElkhamisi commented 3 years ago

@eloquentarduino Yes I did! It was a problem with the Arduino code not the python code.

AhmedElkhamisi commented 3 years ago

@rkuo2000 Thankyou once again!

whubaichuan commented 1 year ago

@AhmedElkhamisi @rkuo2000 hi, do you have a similar problem like https://github.com/eloquentarduino/EloquentTinyML/issues/50 when transferring the EloquentTnyML examples to your own project? Thanks.

whubaichuan commented 1 year ago

did you solved your error? I get many requests of help for NaN values, I will definetly update the examples to clarify how the input should be formatted for Conv2D to work

@eloquentarduino hi, I am also facing this problem. Could you update an example to clarify how the input should be formatted for Conv2D to work?

eloquentarduino commented 1 year ago

Yes, I will create a more detailed guide for the different types of input data.