ultralytics / yolov5

YOLOv5 πŸš€ in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
50.15k stars 16.19k forks source link

Best pratices to train an license plate OCR model #10684

Closed diegotecrede closed 1 year ago

diegotecrede commented 1 year ago

Search before asking

Question

Hello everyone! I'm trying to train a model for license plate recognition (OCR). I have a big dataset with thousands images. Some classes are more present than others. If someone can help me, I'll be very thankful.

Images to train are from 80x30 to 300x150. Images of real scenarios license plates.

I have some doubts about epochs number, batch size, image size... Someone could help me, please? Thanks so much

Additional

No response

liuyajian commented 1 year ago

you can try paddleOCR

diegotecrede commented 1 year ago

Hi @liuyajian . Thanks for your reply. I've tried, but accuracy of paddleOCR is not so good. I have a rich dataset of license plates, and I think yolov5 can give me better accuracy. I've already made another object detections, but with bigger images (as to train as to inference). For license plates, images and objects to detect are smaller, and the "objetcs" to detect always will have the same aspec ratio.

wolfpack12 commented 1 year ago

YOLOv5 isn't an OCR tool - It's used for object detection. To use YOLOv5 to perform OCR on license plates, you'd have to create bounding boxes and labels associated with each class (i.e. Letters of the Alphabet/Numbers) on EACH license plate. So if a plate was "ABC-123", you would draw 6 (or 7 if you want hyphens) bounding boxes on the images and assign them to the respective class.

Afterwards, you'd still need to perform some kind of post-processing to convert the detections to text. You'd also probably want to use something like agnostic NMS to prevent double-calls.

diegotecrede commented 1 year ago

Hello @wolfpack12. Yes, I did it. My dataset is all labeled in each chararcter as different classes. I think I didn't expressed correctly. I use yolov5 for another object detections, but input images and images I used to train are bigger (at least 1280x720, or bigger). In this case of license plates, I'm using small images, and results of inference are not good. Do you know if I change anchors and/or layers configurations, it can increase accuracy? If yes, what configurations should I change?

wolfpack12 commented 1 year ago

I’d recommend cropping your training set to look like your test set. If you can’t do that, try and letterbox your small images to the scale of your training set. The closer you can make the training image look like your test set, the better your performance should be.

diegotecrede commented 1 year ago

Sure @wolfpack12 . All images are similar . Training and test set are images of only license plates (already cropped) of real world. And all of them are from about 80x30 to 300x150 . My doubt is if anchor and labels parameters can increase final performance and accuracy. If yes, what are the best parameters for that?

nightfuryyy commented 1 year ago

i trained similar dataset before, my task was OCR mrz on idcard. i started tuning model with yolov5s so i can tune faster then u can try yolov5m for better results.

  1. With this images dimensions (Images that I'll use to inference are very similar.), what is the best --image-size to train? => my best image size is 384 but it has 3 line, each line has 10 digit, i think u can try 96 to 160
  2. About augumentations, how can I disable that, in view of I'm training for characteres and they can not be augmented? => in my case, i used hard augumentations for best results
  3. Is it necessary to change any "anchor" or "layers" values? What is recommended? => i use same default
  4. What's the best configuration to train and have good results? => u can increase cls or obj cause u need correct classify not box. Yolov5 use p3, p4, p5. u can try p3 only, p4 only... cause characteres almost same size
Henryplay commented 1 year ago

@diegotecrede Hi~,i am also doing OCR task.Do you know how to change the input size?I don't want the input size width and height is equal,Ideally,i want the height is 96,width is 416.Do you know how to change the code?

diegotecrede commented 1 year ago

i trained similar dataset before, my task was OCR mrz on idcard. i started tuning model with yolov5s so i can tune faster then u can try yolov5m for better results.

  1. With this images dimensions (Images that I'll use to inference are very similar.), what is the best --image-size to train? => my best image size is 384 but it has 3 line, each line has 10 digit, i think u can try 96 to 160
  2. About augumentations, how can I disable that, in view of I'm training for characteres and they can not be augmented? => in my case, i used hard augumentations for best results
  3. Is it necessary to change any "anchor" or "layers" values? What is recommended? => i use same default
  4. What's the best configuration to train and have good results? => u can increase cls or obj cause u need correct classify not box. Yolov5 use p3, p4, p5. u can try p3 only, p4 only... cause characteres almost same size

How can I increase cls or obj? And how can I use only p3 or only p4? What should I do in which files?

diegotecrede commented 1 year ago

Hi @Henryplay . I think you can't define exactly width and height, but only --img-size parameter with a multiple of 32 number, it will resize your images automatically.

nightfuryyy commented 1 year ago

@diegotecrede

  1. box: 0.05 # box loss gain cls: 0.3 # cls loss gain obj: 0.7 # obj loss gain (scale with pixels)
  2. u can change yolov5-p34.yaml
github-actions[bot] commented 1 year ago

πŸ‘‹ Hello, this issue has been automatically marked as stale because it has not had recent activity. Please note it will be closed if no further activity occurs.

Access additional YOLOv5 πŸš€ resources:

Access additional Ultralytics ⚑ resources:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLOv5 πŸš€ and Vision AI ⭐!