ultralytics / yolov5

YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
50.28k stars 16.24k forks source link

better OCR with yolov5 ? #7034

Closed yinrong closed 2 years ago

yinrong commented 2 years ago

Search before asking

Question

Can I get better precision detect character-like objects? Some character are badly classified. add some spatial transformer layers maybe ? Would you give a code example ?

why I do NOT use an OCR model ?

yolov5 is easy / fast to train / use. It is easier to use a single model.

current precision

class[6], class[8] have lowest precision class [0:9] have low precision class[9:] is good

usage in real life

image

all classes to detect

first line: class[0:9] second line: class[10:19] ... image

Additional

No response

github-actions[bot] commented 2 years ago

👋 Hello @yinrong, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a 🐛 Bug Report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

For business inquiries or professional support requests please visit https://ultralytics.com or email support@ultralytics.com.

Requirements

Python>=3.7.0 with all requirements.txt installed including PyTorch>=1.7. To get started:

git clone https://github.com/ultralytics/yolov5  # clone
cd yolov5
pip install -r requirements.txt  # install

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

CI CPU testing

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), validation (val.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit.

glenn-jocher commented 2 years ago

@yinrong 👋 Hello! Thanks for asking about improving YOLOv5 🚀 training results.Yes I think you are correct! Your use case appears more suited to object detection than OCR. You should be able to get great results if your dataset is large enough and your --img-size is large enough to capture the small details.

Most of the time good results can be obtained with no changes to the models or training settings, provided your dataset is sufficiently large and well labelled. If at first you don't get good results, there are steps you might be able to take to improve, but we always recommend users first train with all default settings before considering any changes. This helps establish a performance baseline and spot areas for improvement.

If you have questions about your training results we recommend you provide the maximum amount of information possible if you expect a helpful response, including results plots (train losses, val losses, P, R, mAP), PR curve, confusion matrix, training mosaics, test results and dataset statistics images such as labels.png. All of these are located in your project/name directory, typically yolov5/runs/train/exp.

We've put together a full guide for users looking to get the best results on their YOLOv5 trainings below.

Dataset

COCO Analysis

Model Selection

Larger models like YOLOv5x and YOLOv5x6 will produce better results in nearly all cases, but have more parameters, require more CUDA memory to train, and are slower to run. For mobile deployments we recommend YOLOv5s/m, for cloud deployments we recommend YOLOv5l/x. See our README table for a full comparison of all models.

YOLOv5 Models

Training Settings

Before modifying anything, first train with default settings to establish a performance baseline. A full list of train.py settings can be found in the train.py argparser.

Further Reading

If you'd like to know more a good place to start is Karpathy's 'Recipe for Training Neural Networks', which has great ideas for training that apply broadly across all ML domains: http://karpathy.github.io/2019/04/25/recipe/

Good luck 🍀 and let us know if you have any other questions!

yinrong commented 2 years ago

@glenn-jocher

I still believe the model layers or hyper-parameters should change

because what I did is enough for class[9:] (100% accuracy in real life), but far NOT enough for class[1:9]. the model predicts: image

What I did

  1. take only 1 real photo all.png

  2. python program generates 30, 000 photos, the generated photo is like image

  3. augment

    class Albumentations:
        def __init__(self):
            self.transform = None
            try:
                import albumentations as A
                class Rotate180 (A.Rotate):
                    def get_params(self):
                        return {"angle": 180}
    
                self.transform = A.Compose([
                    A.Affine(),
                    A.PiecewiseAffine(),
                    A.Perspective(),
                    Rotate180(),
                    A.RandomSnow(snow_point_lower=0.00, snow_point_upper=0.05),
                    A.RandomFog(fog_coef_lower=0.00, fog_coef_upper=0.05),
                    A.Blur(p=0.02),
                    A.CLAHE(p=0.02),
                    A.RandomBrightnessContrast(),
                    A.RandomGamma(),
                    A.ImageCompression(quality_lower=75, p=0.1)],
                    bbox_params=A.BboxParams(format='yolo', label_fields=['class_labels']))
    
  4. fine-tune with default hyper-parameters.

    # only classes info in mydata.yml
    python -m torch.distributed.launch --nproc_per_node 2 train.py --batch 64 --data mydata.yml --weights yolov5m.pt --device 2,3

    train report is at: https://wandb.ai/yinrong/YOLOv5/reports/Untitled-Report--VmlldzoxNzA5ODIx?accessToken=tcogkoplpg041wl28r0w800w7uk241h75elbnwxsziti8ldtx348jt964s2b7oiz

yinrong commented 2 years ago

@glenn-jocher Would you give some pointers for my specific situation?

I'm trying the following method:

  1. Use resize(interpolation=CV_AREA_MEAN) in Photo generation and Augmentation (training: https://wandb.ai/yinrong/YOLOv5/reports/Untitled-Report--VmlldzoxNzMxNjgz)
glenn-jocher commented 2 years ago

@yinrong I'd point you to all of our recommendations in https://github.com/ultralytics/yolov5/issues/7034#issuecomment-1072357957

github-actions[bot] commented 2 years 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 ⭐!