Code Monkey home page Code Monkey logo

crnn_plate_recognition's Introduction

车牌识别

车牌检测+车牌识别 看这里车牌检测识别

车牌颜色和车牌识别一起训练看这里: 车牌识别+车牌颜色

训练的时候 选择相应的cfg 即可选择模型的大小

train.py

 # construct face related neural networks
    #cfg =[8,8,16,16,'M',32,32,'M',48,48,'M',64,128] #small model
    # cfg =[16,16,32,32,'M',64,64,'M',96,96,'M',128,256]#medium model
    cfg =[32,32,64,64,'M',128,128,'M',196,196,'M',256,256] #big model
    model = myNet_ocr(num_classes=len(plate_chr),cfg=cfg)

环境配置

  1. WIN 10 or Ubuntu 16.04
  2. **PyTorch > 1.2.0 (may fix ctc loss)**🔥
  3. yaml
  4. easydict
  5. tensorboardX

数据

车牌识别数据集CCPD+CRPD

  1. 从CCPD和CRPD截下来的车牌小图以及我自己收集的一部分车牌 有需要的话加vx:we0091234

  2. 数据集打上标签,生成train.txt和val.txt

    Image text

    图片命名如上图:车牌号_序号.jpg 然后执行如下命令,得到train.txt和val.txt

    python plateLabel.py --image_path your/train/img/path/ --label_file datasets/train.txt
    python plateLabel.py --image_path your/val/img/path/ --label_file datasets/val.txt
    

    数据格式如下:

    train.txt

    /mnt/Gu/trainData/plate/new_git_train/CCPD_CRPD_ALL/冀BAJ731_3.jpg 5 53 52 60 49 45 43 
    /mnt/Gu/trainData/plate/new_git_train/CCPD_CRPD_ALL/冀BD387U_2454.jpg 5 53 55 45 50 49 70 
    /mnt/Gu/trainData/plate/new_git_train/CCPD_CRPD_ALL/冀BG150C_3.jpg 5 53 58 43 47 42 54 
    /mnt/Gu/trainData/plate/new_git_train/CCPD_CRPD_OTHER_ALL/皖A656V3_8090.jpg 13 52 48 47 48 71 45 
    /mnt/Gu/trainData/plate/new_git_train/CCPD_CRPD_OTHER_ALL/皖C91546_7979.jpg 13 54 51 43 47 46 48 
    /mnt/Gu/trainData/plate/new_git_train/CCPD_CRPD_OTHER_ALL/皖G88950_1540.jpg 13 58 50 50 51 47 42 
    /mnt/Gu/trainData/plate/new_git_train/CCPD_CRPD_OTHER_ALL/皖GX9Y56_2113.jpg 13 58 73 51 74 47 48 
    
  3. 将train.txt val.txt路径写入lib/config/360CC_config.yaml 中

    DATASET:
      DATASET: 360CC
      ROOT: ""
      CHAR_FILE: 'lib/dataset/txt/plate2.txt'
      JSON_FILE: {'train': 'datasets/train.txt', 'val': 'datasets/val.txt'}
    

Train

python train.py --cfg lib/config/360CC_config.yaml

结果保存再output文件夹中

测试demo


python demo.py --model_path saved_model/best.pth --image_path images/test.jpg
                                   or your/model/path

Image text

结果是:

Image text

导出onnx


python export.py --weights saved_model/best.pth --save_path saved_model/best.onnx  --simplify

onnx 推理

python onnx_infer.py --onnx_file saved_model/best.onnx  --image_path images/test.jpg

双层车牌

双层车牌这里采用拼接成单层车牌的方式:

python:

def get_split_merge(img):
    h,w,c = img.shape
    img_upper = img[0:int(5/12*h),:]
    img_lower = img[int(1/3*h):,:]
    img_upper = cv2.resize(img_upper,(img_lower.shape[1],img_lower.shape[0]))
    new_img = np.hstack((img_upper,img_lower))
    return new_img

c++:

cv::Mat get_split_merge(cv::Mat &img)   //双层车牌 分割 拼接
{
    cv::Rect  upper_rect_area = cv::Rect(0,0,img.cols,int(5.0/12*img.rows));
    cv::Rect  lower_rect_area = cv::Rect(0,int(1.0/3*img.rows),img.cols,img.rows-int(1.0/3*img.rows));
    cv::Mat img_upper = img(upper_rect_area);
    cv::Mat img_lower =img(lower_rect_area);
    cv::resize(img_upper,img_upper,img_lower.size());
    cv::Mat out(img_lower.rows,img_lower.cols+img_upper.cols, CV_8UC3, cv::Scalar(114, 114, 114));
    img_upper.copyTo(out(cv::Rect(0,0,img_upper.cols,img_upper.rows)));
    img_lower.copyTo(out(cv::Rect(img_upper.cols,0,img_lower.cols,img_lower.rows)));
    return out;
}

Image text 通过变换得到 Image text

训练自己的数据集

  1. 修改alphabets.py,修改成你自己的字符集,plateName,plate_chr都要修改,plate_chr 多了一个空的占位符'#'
  2. 通过plateLabel.py 生成train.txt, val.txt
  3. 训练

数据增强

cd Text-Image-Augmentation-python-master

python demo1.py --src_path /mnt/Gu/trainData/test_aug --dst_path /mnt/Gu/trainData/result_aug/

src_path 是数据路径, dst_path是保存的数据路径

然后把两份数据放到一起进行训练,效果会好很多!

References

联系

有问题可以提issues 或者加qq群:823419837 询问

crnn_plate_recognition's People

Contributors

we0091234 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

crnn_plate_recognition's Issues

训练模型选择问题

您好,请问训练过程中使用的myNet_ocr模型与CRNN模型有联系吗?怎么替换为CRNN模型呢?感谢大佬。

ImportError: No module named lib.models.crnn

大家是否遇到同样的问题,有解决方案吗?

 ~/Documents/GitHub/crnn_plate_recognition/ [master] python train.py --cfg lib/config/360CC_config.yaml
Traceback (most recent call last):
  File "train.py", line 8, in <module>
    import lib.models.crnn as crnn
ImportError: No module named lib.models.crnn

kpt-label

kpt-label 为2 报错,这个是kpt写死了只能为4么

LPRnet Accuracy

Is there any reference to someone's knowledge which explains how to compute the accuracy of the LPRNet model output? I'm not interested into computing WER or CER, but an overall accuracy value for the LPRNet output

模型输入tensor的尺寸不对

做好数据处理等前置工作后,执行训练脚本 python train.py --cfg OWN_config.yaml 提示模型尺寸不正确,示例代码train.py 中构建的三种模型都不正确,如何约束这个尺寸问题?

下面展示各个模型的错误:
1 -- build_lprnet
model = build_lprnet(num_classes=len(plate_chr))
错误为:RuntimeError: Given groups=1, weight of size [64, 3, 3, 3], expected input[32, 1, 32, 160] to have 3 channels, but got 1 channels instead
2 -- myNet_ocr
model = myNet_ocr(num_classes=len(plate_chr),cfg=cfg)
错误为:RuntimeError: Given groups=1, weight of size [32, 3, 5, 5], expected input[32, 1, 32, 160] to have 3 channels, but got 1 channels instead
3 -- crnn
model = crnn.get_crnn(config,cfg=cfg)
错误为:RuntimeError: Given groups=1, weight of size [32, 3, 5, 5], expected input[32, 1, 32, 160] to have 3 channels, but got 1 channels instead

训练图片的宽度为啥是固定的?

我很想用此代码来训练文本识别,文本的长度是不固定的。但是 我们训练和 ncnn中的识别代码,都是宽度是固定的168,对于车牌这种还可以。要是 文本变长的,我们应该怎么办啊,求教。

train.py parser.add_argument('--img_w',type=int,default=168,help='width')

脚本
OW: 280 # origial width: 280
H: 32
W: 100 # resized width: 160

训练tricks咨询

请问博主,是否还有别的训练方法啊,我这边按照您提供的readme训练,虽然模型精度也能达到98%,但是模型的泛化性还是比您训练的模型差一点点,特别是双层车牌效果没您的好,请问您也是用的您所提供的dataset训练的吗?还是说加过其它额外数据?或者是在调参上面有一些技巧呢?谢谢。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.