GithubHelp home page GithubHelp logo

pytorch_retina_license_plate's Introduction

Pytorch_Retina_License_Plate

利用RetinaFace进行迁移学习实现的车牌检测、车牌四角定位、车牌矫正对齐程序。 当Retinaface使用mobilenet0.25作为骨干网时,模型大小仅为1.8M 我们还提供resnet50作为骨干网以获得更好的结果。 RetinaFace的官方代码可以在这里找到。

内容

  • 环境说明
  • 安装
  • 数据
  • 训练
  • TODO
  • 参考文献

环境说明

  • python=3.7
  • pytorch=1.2.0
  • torchvision=0.4.0
  • cudatoolkit=10.0
  • cudnn=7.6.4

安装

数据

地址

https://github.com/detectRecog/CCPD

数据容量

CCPD 数量/k 描述
Base 200 正常车牌
FN 20 距离摄像头相当的远或者相当近
DB 20 光线暗或者比较亮
Rotate 10 水平倾斜20-25°,垂直倾斜-10-10°
Tilt 10 水平倾斜15-45°,垂直倾斜15-45°
Weather 10 在雨天,雪天,或者雾天
Blur 5 由于相机抖动造成的模糊
Challenge 10 其他的比较有挑战性的车牌
NP 5 没有车牌的新车

注释说明

注释嵌入在文件名中。 样本图像名称为“ 025-95_113-154&383_386&473-386&473_177&454_154&383_363&402-0_0_22_27_27_33_16-37-15.jpg”。每个名称可以分为七个字段。这些字段解释如下。

  • 面积:牌照面积与整个图片区域的面积比。

  • 倾斜度:水平倾斜程度和垂直倾斜度。

  • 边界框坐标:左上和右下顶点的坐标。

  • 四个顶点位置:整个图像中LP的四个顶点的精确(x,y)坐标。这些坐标从右下角->左下角->左上角->右上角

车牌号:CCPD中的每个图像只有一个LP。每个LP号码由一个汉字,一个字母和五个字母或数字组成。有效的中文车牌由七个字符组成:省(1个字符),字母(1个字符),字母+数字(5个字符)。0_0_22_27_27_33_16”是每个字符的索引。这三个数组定义如下。每个数组的最后一个字符是字母O,而不是数字0。我们将O用作“无字符”的符号,因为中文车牌字符中没有O。

provinces = ["皖", "沪", "津", "渝", "冀", "晋", "蒙", "辽", "吉", "黑", "苏", "浙", "京", "闽", "赣", "鲁", "豫", "鄂", "湘", "粤", "桂", "琼", "川", "贵", "云", "藏", "陕", "甘", "青", "宁", "新", "警", "学", "O"]
alphabets = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
             'X', 'Y', 'Z', 'O']
ads = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
       'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'O']

模型训练

  • 数据预处理

    cd Pytorch_Retina_License_Plate/prepare_data python reformat_CCPD.py python dataset_provider.py

    注意修改执行文件中的数据集地址

  • 训练

    培训之前,您可以在中检查网络配置(例如batch_size,min_sizes和步骤等。)data/config.py and train.py。

    CUDA_VISIBLE_DEVICES = 0,1,2,3 python train.py --network resnet50或 CUDA_VISIBLE_DEVICES = 0 python train.py --network mobile0.25

测试

python detect.py -m ./weights/mobilenet0.25_epoch_19_ccpd.pth -image test_images/0.jpg

效果更好的预训练模型在后期陆续提供

效果

TODO

  • 评估

参考文献

@inproceedings{deng2019retinaface, title={RetinaFace: Single-stage Dense Face Localisation in the Wild}, author={Deng, Jiankang and Guo, Jia and Yuxiang, Zhou and Jinke Yu and Irene Kotsia and Zafeiriou, Stefanos}, booktitle={arxiv}, year={2019}

pytorch_retina_license_plate's People

Contributors

gm19900510 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  avatar

pytorch_retina_license_plate's Issues

anchor setting

代码里面的anchor都是方形的,改成长方形效果应该更好吧?

关于在自定义数据集上训练的一些问题?

@gm19900510 大佬你好,就是我是一名大二学生,然后是在中北大学的robomaster战队里负责用神经网络识别装甲板实现自动瞄准,不过就是之前我用yolo系列训练出来的模型最后实际测试时得到的bbox和装甲板的轮廓并不能很好的拟合,导致后续使用pnp进行姿态解算时会有较大误差,所以我想将传统yolo的数据集格式改为用四个角点的归一化坐标,然后我看到了您这个项目,不过我看您的数据集格式里还是包含了传统yolo的归一化后的中心点坐标和w,h,然后我现在的数据集格式是像这样:1 0.673029 0.373564 0.678429 0.426232 0.830433 0.401262 0.824525 0.351212,第一个数字是类别id,后面八个数字是归一化后的装甲板的四个角点坐标,我想是得改动dataloader的部分才能训练吗?望大佬解惑

train resnet50

when i train resnet50, i meet this error,
Traceback (most recent call last):
File "train.py", line 165, in
train()
File "train.py", line 134, in train
loss_l, loss_c, loss_landm = criterion(out, priors, targets)
File "/home/neut/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/torch/nn/modules/module.py", line 541, in call
result = self.forward(*input, **kwargs)
File "/home/neut/workspace/Pytorch_Retina_License_Plate/layers/modules/multibox_loss.py", line 119, in forward
loss_c = F.cross_entropy(conf_p, targets_weighted, reduction='sum')
File "/home/neut/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/torch/nn/functional.py", line 2009, in cross_entropy
return nll_loss(log_softmax(input, 1), target, weight, None, ignore_index, None, reduction)
File "/home/neut/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/torch/nn/functional.py", line 1838, in nll_loss
ret = torch._C._nn.nll_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index)
RuntimeError: invalid argument 2: non-empty vector or matrix expected at /pytorch/aten/src/THCUNN/generic/ClassNLLCriterion.cu:31

but mibilenet is ok, can you tell me how to solve it?

训练时有无车牌数据会报错

Traceback (most recent call last):
File "train.py", line 165, in
train()
File "train.py", line 134, in train
loss_l, loss_c, loss_landm = criterion(out, priors, targets)
File "xxxx/anaconda3/envs/new/lib/python3.6/site-packages/torch/nn/modules/module.py", line 493, in call
result = self.forward(*input, **kwargs)
File "xxxx/Pytorch_Retina_License_Plate/layers/modules/multibox_loss.py", line 119, in forward
loss_c = F.cross_entropy(conf_p, targets_weighted, reduction='sum')
File "xxxx/anaconda3/envs/new/lib/python3.6/site-packages/torch/nn/functional.py", line 2056, in cross_entropy
return nll_loss(log_softmax(input, 1), target, weight, None, ignore_index, None, reduction)
File "xxxx/anaconda3/envs/new/lib/python3.6/site-packages/torch/nn/functional.py", line 1871, in nll_loss
ret = torch._C._nn.nll_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index)
RuntimeError: invalid argument 2: non-empty vector or matrix expected at /pytorch/aten/src/THCUNN/generic/ClassNLLCriterion.cu:31
您好,我在照着指引尝试训练时遇到了这样的问题
查了一下,好像是因为负样本在计算loss时会出错,但是我不知道该怎么修改
去掉所有负样本后不再报错了
可是负样本不是专门生成用来提升训练效果的吗?
或者这个错误是因为其他的原因?
求解答,谢谢您

Model mismatch problem

Thanks for your work, I just want to test your model. I clone your repository and ran detect. But I got a model mismatch error. Here is the error message.
size mismatch for LandmarkHead.0.conv1x1.weight: copying a param with shape torch.Size ([20, 64, 1, 1]) from checkpoint, the shape in current model is torch.Size ([16, 64, 1, 1]).
size mismatch for LandmarkHead.0.conv1x1.bias: copying a param with shape torch.Size ([20]) from checkpoint, the shape in current model is torch.Size ([16]).
size mismatch for LandmarkHead.1.conv1x1.weight: copying a param with shape torch.Size ([20, 64, 1, 1]) from checkpoint, the shape in current model is torch.Size ([16, 64, 1, 1]).
size mismatch for LandmarkHead.1.conv1x1.bias: copying a param with shape torch.Size ([20]) from checkpoint, the shape in current model is torch.Size ([16]).
size mismatch for LandmarkHead.2.conv1x1.weight: copying a param with shape torch.Size ([20, 64, 1, 1]) from checkpoint, the shape in current model is torch.Size ([16, 64, 1, 1]).
size mismatch for LandmarkHead.2.conv1x1.bias: copying a param with shape torch.Size ([20]) from checkpoint, the shape in current model is torch.Size ([16]).
Can you help me thank you

resnet50 pretrain_mod

大神您好,是否可以提供一下resnet50的预训练模型呢,十分感谢!

如何添加双层车牌的检测?

你好,我想修改网络在检测阶段就区分开单双层车牌,方便在识别时候调用,看了代码。不知道从何改起,能指点一二吗 两个类别single_plate(单层),double_plate(双层),但是都有关键点 ,应该如何修改呀

detect.py so slow,about 3-7s

when I run detect.py, the net inference time is about3-7s with GPU (Geforce 940M), can you help me out to reduce the run time? Thanks a lot!

net forward time: 7.8088
priorBox time: 7.9081

关于数据集生成问题

在数据集生成脚本中需要一个文件 './data_folder/data_list_CCPD_train.txt'
请问这个文件是怎么生成的?猜测文件每行保存一个图片的车牌信息。看代码每行信息应该是 img_path,label(0或者1),num(车牌数量),x,y,w,h
但是作者写的负样本生成代码中 给出的label都是 -1 但是长度是num = 3的情况?
请确认

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.