AIWintermuteAI / aXeleRate

Keras-based framework for AI on the Edge
MIT License
174 stars 72 forks source link

Problem with TFLite in RaspberryPi ? /MaixPy OCR #30

Closed WillyMC95 closed 3 years ago

WillyMC95 commented 3 years ago

Hi @AIWintermuteAI ,I'm working on an object detection model and Axelerate is fantastic, I still don't know how it works completely because the training is very fast and the results are very good in contrast with the usual training for (CSV files/TF records...etc).

Now the issues : I've made a vehicular plate recognition and the model for the MaixPy works correctly but when I try to replicate this in the Raspberry with tflite format it just doesn't run. In the Raspeberry console show me : "IndexError: list index out of range".

Ive been working with "https://github.com/EdjeElectronics/TensorFlow-Lite-Object-Detection-on-Android-and-Raspberry-Pi" for the implementation, and the training is with Axelerate. In the issues on EdjeElectronics the error is showed and answer is "Hi all, the "list index out of range" error is occurring because you are using an "image classification" model rather than an "object detection" model. So I don't understad what is really happening , I worked on Google Colab (Object Detection) and the Config File is : image The script Im using to run the Raspberry is here: https://github.com/EdjeElectronics/TensorFlow-Lite-Object-Detection-on-Android-and-Raspberry-Pi/blob/master/TFLite_detection_webcam.py

So, is the conversion failing or am I executing badly?.

The other thing is about MaixPy , the Kmodel works perctly and the model is really amazing detecting plates but for a strange reason the camera is always rotating, the code Im using is this: image I modify the example script because in line 18 "img = sensor.snapshot().rotation_corr(z_rotation=90.0)" the rotation part always marked an atribute error.

To finish Im planning on do OCR to the plate, with the Raspberry I'll work with OpenCV/pytesseract but in the MaixPy I dont know how to do it. Can I install those libraries? or Can give me an idea in how to make it?

Thanks a lot for the help if u can and u have done an amazing work with Axelerate.

AIWintermuteAI commented 3 years ago

Thanks for the kind words about aXeleRate. Object detection models are more tricky than image classification models and their output need to be properly decoded to get bounding boxes. Different object detection architectures process the output of neural network differently - so as a rule of thumb, you cannot just take any example script and use it with any object detection network. Fortunately I made example scripts for inference with Raspberry Pi, you can find them here https://github.com/AIWintermuteAI/aXeleRate/tree/master/example_scripts/raspberry_pi You can check this example and see if it works for you - if there are problems, do report here :)

Which board are you using? I mean for MaixPy. For rotated image, it is better to avoid rotating image, since this operation consumes memory and slows down the image processing pipeline. Can you just rotate the camera properly?

There are no readily available solutions for OCR on MaixPy - I've trained number detection model myself and it works pretty good, I think it is possible to add letters to the model as well. Anyhow, that will be two stage detection problem - first detect license place, then detect numbers/letters in cropped plate image. Maybe even make it three stage, if two stage doesn't work reliably - then it will be plate detection - character detection in cropped plate image - character recognition in cropped character image.

WillyMC95 commented 3 years ago

Hi @AIWintermuteAI, thanks for the quick reply. Well I'm still learning (I'm a newbie) about this and didn't realize that I would have issues with the model itself depending on the type of training. For the example scripts I need the .tflite provide by Axelerate and I supposeed that I need to create a .txt file with the labels for the arguments in the detector_video.py , right?

I'm using MaixGo and I don't know how to explain the camera error properly but I'll do my best : The image in the screen (on the board) is always in rotation mode, I mean , I can't handle it properly because if I rotate the board the image is rotated too, so the image on the screen will always be upside down. About the OCR on the Maix, Can I combine two models ? like I said I'm still learning and right now I don't know how to do that , Can u give some advices to look information about that?.

Thanks for all the help , I really appreciate it.

AIWintermuteAI commented 3 years ago

Sorry for delayed reply, got busy with other things and could continue working on aXeleRate only in December. I just published a new release.

For the example scripts I need the .tflite provide by Axelerate and I supposeed that I need to create a .txt file with the labels for the arguments in the detector_video.py , right?

yes, correct.

I'm using MaixGo and I don't know how to explain the camera error properly but I'll do my best : The image in the screen (on the board) is always in rotation mode, I mean , I can't handle it properly because if I rotate the board the image is rotated too, so the image on the screen will always be upside down.

I think you need to set vflip and horizontal flip for the sensor.

About the OCR on the Maix, Can I combine two models ?

You can have a look at example of two stage inference in MaixPy face recognition script here https://github.com/sipeed/MaixPy_scripts/blob/master/machine_vision/face_recognization/demo_face_recognization.py It's fairly easy - just perform object detection, crop the original image and feed the cropped image to the second network. If you have three stages (as in face recognition example), then repeat the process one more time.

If you have any other issues, please create a separate thread!