由于非常熟悉native C开发,学习Python的过程中还老是忘不了Qt, 准备用Qt产生训练样本。而后,使用Qt的GUI在后台调用python进行实验。当然,这个路子已经Out了,现在不少人转去pytorch, 还有朋友在用PaddlePaddle飞桨做实验。不过对比了类似的API,我认为Tensorflow 2作为一个实验工具也是足够用。

1. 生成训练样本

使用Qt QImage直接进行验证码绘图。相关代码见
https://gitcode.net/coloreaglestdio/qtfnn_kits/-/tree/master/mixnn_example

     QImage img(pic_width,pic_height,QImage::Format_RGB888);//QColor cBk(rand()%32+168,rand()%64+128,rand()%54+128);QColor cBk(255,255,255);img.fill(cBk);QPainter painter(&img);//产生干扰图象QVector<QRectF> bounds;QVector<int> charids;const int lines =  rand()%64+1;for (int j=0;j<lines;j++){QPen pl = QPen(QBrush(QColor(rand()%64+128,rand()%64+128,rand()%16+16,192)),rand()%4);painter.setPen(pl);const int x1 = rand()% pic_width;const int y1 = rand()% pic_height;const int x2 = x1 + rand()% 64 - 32;const int y2 = y1 + rand()% 64 - 32;if (j<4)painter.drawLine(x1,y1,x2,y2);elsepainter.drawPoint(x1,y1);}//绘制文字for (int j=0;j<char_words;++j){const char * fontfm[] = {"DejaVu Serif","Microsoft Sans Serif","Courier New","Trebuchet MS"};QFont serifFont(fontfm[rand()%4], rand()%12+20, QFont::Normal);painter.setFont(serifFont);painter.setPen(QColor(rand()%32+32,rand()%64,rand()%64));QString str;const int cid = rand() % total_chars;charids.push_back(cid);str.push_back(vch[cid]);const double seed = pic_width / (char_words+0.3);//计算中心const int center_x = j*seed+seed*0.75+rand() % 20 - 10,  center_y = pic_height/2 + rand() % 8 -4;painter.translate(center_x,center_y);painter.rotate(rand() % 30 - 15); // 第2步: 旋转一定角度QRectF brec;painter.drawText(QRectF(-seed/2,-pic_height/2,seed,pic_height), Qt::AlignCenter, str,&brec);         // 第3步: 绘制文字         painter.resetTransform();                  // 第4步: 恢复坐标旋转painter.setBrush(Qt::NoBrush);brec.setX(brec.x()-4);brec.setWidth(brec.width()+2);brec.translate(center_x,center_y);painter.drawRect(brec);bounds.push_back(brec);}img.save(fm_split+".png");
  1. 输入Trainning Feature Dir, 并勾选“Also make chars”同时生成字符的训练样本。
  2. 在Make Samples里输入要生成的样本个数,start里选择样本起点,可以不断增加样本。
  3. 点击按Make开始生成。

    这样生成的样本图片类似(已经框选了文字的外接矩形):

    为训练准备十万组样本,为测试准备1000组。

2. 识别原理

使用两个模型来完成识别。模型1用来切割锁定5个字符的外接矩形,输出每个字符的坐标。模型2用于对字符进行识别。

#mermaid-svg-gDfhP4k61LaRfjEb {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-gDfhP4k61LaRfjEb .error-icon{fill:#552222;}#mermaid-svg-gDfhP4k61LaRfjEb .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-gDfhP4k61LaRfjEb .edge-thickness-normal{stroke-width:2px;}#mermaid-svg-gDfhP4k61LaRfjEb .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-gDfhP4k61LaRfjEb .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-gDfhP4k61LaRfjEb .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-gDfhP4k61LaRfjEb .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-gDfhP4k61LaRfjEb .marker{fill:#333333;stroke:#333333;}#mermaid-svg-gDfhP4k61LaRfjEb .marker.cross{stroke:#333333;}#mermaid-svg-gDfhP4k61LaRfjEb svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-gDfhP4k61LaRfjEb .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-gDfhP4k61LaRfjEb .cluster-label text{fill:#333;}#mermaid-svg-gDfhP4k61LaRfjEb .cluster-label span{color:#333;}#mermaid-svg-gDfhP4k61LaRfjEb .label text,#mermaid-svg-gDfhP4k61LaRfjEb span{fill:#333;color:#333;}#mermaid-svg-gDfhP4k61LaRfjEb .node rect,#mermaid-svg-gDfhP4k61LaRfjEb .node circle,#mermaid-svg-gDfhP4k61LaRfjEb .node ellipse,#mermaid-svg-gDfhP4k61LaRfjEb .node polygon,#mermaid-svg-gDfhP4k61LaRfjEb .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-gDfhP4k61LaRfjEb .node .label{text-align:center;}#mermaid-svg-gDfhP4k61LaRfjEb .node.clickable{cursor:pointer;}#mermaid-svg-gDfhP4k61LaRfjEb .arrowheadPath{fill:#333333;}#mermaid-svg-gDfhP4k61LaRfjEb .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-gDfhP4k61LaRfjEb .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-gDfhP4k61LaRfjEb .edgeLabel{background-color:#e8e8e8;text-align:center;}#mermaid-svg-gDfhP4k61LaRfjEb .edgeLabel rect{opacity:0.5;background-color:#e8e8e8;fill:#e8e8e8;}#mermaid-svg-gDfhP4k61LaRfjEb .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-gDfhP4k61LaRfjEb .cluster text{fill:#333;}#mermaid-svg-gDfhP4k61LaRfjEb .cluster span{color:#333;}#mermaid-svg-gDfhP4k61LaRfjEb div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-gDfhP4k61LaRfjEb :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;}

原始图象
模型1
外接坐标
切割
切片
模型2
字符结果

模型1的结构定义
模型2的结构定义

模型可以直接使用minxx_gui加载。

3.训练过程

在训练界面里,选择与模型对应的样本文件夹,而后直接训练。

十万组数据,进行模型1 训练。这里注意因为不是分类,而是坐标输出,所以只看loss就可以了。

34/40 [========================>.....] - ETA: 0s - loss: 2.7917e-04 - accuracy: 0.7978
35/40 [=========================>....] - ETA: 0s - loss: 2.8035e-04 - accuracy: 0.7991
36/40 [==========================>...] - ETA: 0s - loss: 2.7921e-04 - accuracy: 0.8012
37/40 [==========================>...] - ETA: 0s - loss: 2.7967e-04 - accuracy: 0.8041
38/40 [===========================>..] - ETA: 0s - loss: 2.7937e-04 - accuracy: 0.8026
39/40 [============================>.] - ETA: 0s - loss: 2.7858e-04 - accuracy: 0.8029
40/40 [==============================] - ETA: 0s - loss: 2.7870e-04 - accuracy: 0.8062
40/40 [==============================] - 5s 125ms/step - loss: 2.7870e-04 - accuracy: 0.8062
Save Model to code_rect_Saved/Model/weights.ckpt

再对模型2进行训练

28/32 [=========================>....] - ETA: 0s - loss: 7.4408e-05 - accuracy: 1.0000
29/32 [==========================>...] - ETA: 0s - loss: 7.5170e-05 - accuracy: 1.0000
30/32 [===========================>..] - ETA: 0s - loss: 7.5220e-05 - accuracy: 1.0000
31/32 [============================>.] - ETA: 0s - loss: 7.5259e-05 - accuracy: 1.0000
32/32 [==============================] - ETA: 0s - loss: 7.4850e-05 - accuracy: 1.0000
32/32 [==============================] - 2s 78ms/step - loss: 7.4850e-05 - accuracy: 1.0000Save Model to code_char_Saved/Model/weights.ckpt

4. 应用效果

在模型收敛后,直接测试识别分割、分类效果。可见,模型正确识别了 VRI64的字符。

5. 后续

后续我们准备尝试PyTorch、飞桨等不同的平台,以及CNN之外的模型,如进行句法的识别。

机器学习小试(11)验证码识别测试-使用Qt与Tensorflow2进行深度学习实验相关推荐

  1. 《智能步态识别门禁系统》,基于深度学习的多人步态识别系统

    本文章仅仅提供一种自认为比较科学的方式去实现多人步态识别,如果对多人步态识别感兴趣,却又不知道如何实现的话,这篇文章将会有莫大的帮助.以下方法作者皆实验过是可行的方案.(训练集124人,准确率96%, ...

  2. The Wide and Deep Learning Model(译文+Tensorlfow源码解析) 原创 2017年11月03日 22:14:47 标签: 深度学习 / 谷歌 / tensorf

    The Wide and Deep Learning Model(译文+Tensorlfow源码解析) 原创 2017年11月03日 22:14:47 标签: 深度学习 / 谷歌 / tensorfl ...

  3. python汽车类型识别源代码带图形界面,基于PyTorach深度学习

    python汽车类型识别源代码带图形界面,基于torch深度学习,目前可识别公交车, 货车,客运车, 面包车, 皮卡车, 小轿车,程序包中已含模型文件 完整代码下载地址:python汽车类型识别源代码 ...

  4. 12306验证码为什么那么变态?都是这项深度学习应用给逼的

    导读:12306为什么要设置那么复杂的验证码机制呢?就是因为OCR. 今天聊OCR. OCR是人工智能.机器学习特别是深度学习,在图像识别方向最为重要的应用之一.OCR全称Optical Charar ...

  5. 图机器学习 | 图信号处理、矩阵分解、随机游走和深度学习算法

    点上方计算机视觉联盟获取更多干货 仅作学术分享,不代表本公众号立场,侵权联系删除 转载于:专知 AI博士笔记系列推荐 周志华<机器学习>手推笔记正式开源!可打印版本附pdf下载链接 图是连 ...

  6. H2O机器学习:一种强大的可扩展的人工智能和深度学习技术

    书名:基于H2O的机器学习实用方法:一种强大的可扩展的人工智能和深度学习技术 原书名:Practical Machine Learning with H2O:Powerful, Scalable Te ...

  7. 扛鼎之作!Twitter 图机器学习大牛发表160页论文:以几何学视角统一深度学习

    编译 | Mr Bear.青暮 转自 | AI科技评论 导语:近日,帝国理工学院教授.Twitter 首席科学家 Michael Bronstein 发表了一篇长达160页的论文(或者说书籍),试图从 ...

  8. 虹膜识别之路(一):深度学习现有CNN下的虹膜识别

    今天读了一篇IEEE paper:Iris Recognition With Off-the-Shelf CNN Features: A Deep Learning Perspective,在此做一些 ...

  9. 【NLP-NER】命名实体识别中最常用的两种深度学习模型

    命名实体识别(Named Entity Recognition,NER)是NLP中一项非常基础的任务.NER是信息提取.问答系统.句法分析.机器翻译等众多NLP任务的重要基础工具. 上一期我们介绍了N ...

最新文章

  1. CentOS7 service network start命令启动时报错解决方法
  2. Markdown基本语法使用
  3. ElasticSearch大批量数据入库
  4. 观察:Android与潮流一起,机遇无处不在
  5. 服务器SSL/TLS快速检测工具TLLSSLed
  6. 解决Android Studio内代码乱码
  7. 重庆市公安局北碚分局所需容灾备份设备及软件采购
  8. php ini include,php.ini文件中的include_path设置
  9. leetcode-19-删除链表的倒数第N个节点
  10. Struts2框架原理
  11. CentOS 6.4 卸载与安装桌面
  12. [转]Visual Studio 项目类型 GUID 清单
  13. 微信支付宝扫一扫进入小程序的相关配置
  14. 在DOS中使用系统还原工具
  15. java 调用 easypr_EasyPR-Java项目maven版本所需jar包
  16. 论文-公式对齐和右侧自动编号
  17. 网络防火墙开发二三事 转
  18. matlab中的三次样条曲线拟合,三次样条拟合典型实例.doc
  19. 2020年烟花爆竹经营单位主要负责人试题及答案及烟花爆竹经营单位主要负责人实操考试视频
  20. NLP机器阅读理解:四大任务及相应数据集、比赛

热门文章

  1. Practical Exposure Correction: Great Truths Are Always Simple
  2. dedecms的搜索页面支持调用dede标签方法
  3. 温文尔雅的伤感空间日志:你心里的痛,是我永远的殇
  4. 【鸿蒙】《校园通》--游玩南昌模块
  5. python中显示第三行数据_Python数据分析及可视化-小测验
  6. 【线程池】自行准备linux环境,带你手写线程池,只需仅仅150行代码|内存池|API|连接池|应用协议丨C/C++Linux服务器开发
  7. 【SPSS】多因素方差分析详细操作教程(附案例实战)
  8. dw main.less php,less基础详解 - Python测试和开发 - OSCHINA - 中文开源技术交流社区
  9. Visual Studio 2022 for Mac v17.0 发布,离线安装包下载
  10. 实现医生工作站的辅助检查功能的代码(七)