Giter VIP home page Giter VIP logo

pytorch-craft's Introduction

如何利用CRAFT训练属于自己文本检测数据集的模型

本项目旨在以CRAFT提供的预训练模型为基础,进行迁移学习以用于检测自己数据集中的文本。
[CRAFT论文] [代码]
[论文中文解读]

1. 直接使用CRAFT的预训练模型测试自己的文本图像

  1. 下载CRAFT预训练权重文件[craft_mlt_25k.pth](提取码:3bgk),并将该权重文件放入pretrained目录下。
  2. 将需要检测的图像全部放入imgs目录下。
  3. 运行代码:
    python test.py --trained_model ./pretrained/craft_mlt_25k.pth
    
  4. 检测的结果将保存在result文件夹中供查看。

2. 在自己的数据集上训练CRAFT,迁移学习

  1. 标注自己的数据集,使用标注工具[labelme],我们进行字符级别的标注,即对每个字符顺时针标注4个点构成一个多边形框,如下图所示: 标注
    然后我们给这个多边形框标注对应的字符,方便之后如果要做文本识别时使用。

  2. 假设我们数据集的根目录是blw,目录中有图片blw_1.jpg和标注blw_1.json两种文件[参考数据集:提取码6q33],此时我们运行generate_score_map.py(注意修改main函数中的name = 你的根目录名称),运行完之后,你的目录中除了上面两种.jpg和.json外,会多了blw_region_1.npy和blw_affinity_1.npy两种,分别对应了CRAFT中的region_map和affinity_map。然后我们建立一个根目录data,并将四种文件分别放入对应的子目录,如下所示:

    • data:
      • affinity:blw_affinity_1.npy
      • anno:blw_1.json
      • img:blw_1.jpg
      • region:blw_region_1.npy

    此时我们自己的数据集就准备好了。

  3. 运行train.py(注意修改main函数中的参数设置),训练好的模型默认存放在./models中。

3. 使用得到的新模型来测试自己的文本图像

这里我们会遇到一个问题,在训练时,每个epoch之后我们都会保持一个模型,那究竟应该使用哪个呢?
其实这也没有一个标准答案,选不同的都试试看测试效果,然后挑一个比较好的即可。
具体的步骤与1差不多:将models文件夹中的权重,比如:[100.pth](提取码:1tmc)放入./pretrained中,然后运行代码:

python test.py --trained_model ./pretrained/100.pth

检测的结果将保存在result文件夹中供查看,可以发现检测的效果相比直接使用预训练模型有了一定的提升!
检测结果

4. 将标注的点透视变换成水平文本框(供文本识别使用)

run divide_text_region_from_gt.py

注意修改main函数中的参数配置。

pytorch-craft's People

Contributors

commissarma 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

Watchers

 avatar  avatar  avatar  avatar

pytorch-craft's Issues

训练效果

你好我训练了双层黄色车牌效果不是很好,双层黄色车牌是那种大卡车车牌,比如车牌上面是京A,下面是56G89。我训练得图片是把车牌直接裁剪下来,通过labelme标注,一共100张做训练,但是训练完每次识别都是整个车牌,我想检测车牌上面得京A,和下面得56G89。

ValueError: zero-size array to reduction operation minimum which has no identity

mini = dst[np.where(dst>0)].min()
在执行generate_score_map.py时出现了错误。
下面是某一张出错的图片等label数据,是仿照您提供的blw_0.json的格式制作的。
{
"imageHeight": 415,
"imagePath": "train_ReCTS_000024.jpg",
"imageWidth": 307,
"shapes": [
{
"label": "舊",
"points": [
[
90,
80
],
[
152,
80
],
[
152,
144
],
[
90,
144
]
]
},
{
"label": "街",
"points": [
[
155,
76
],
[
223,
76
],
[
223,
140
],
[
155,
140
]
]
},
{
"label": "糖",
"points": [
[
132,
156
],
[
176,
156
],
[
176,
198
],
[
132,
198
]
]
},
{
"label": "水",
"points": [
[
132,
200
],
[
175,
200
],
[
175,
241
],
[
132,
241
]
]
},
{
"label": "铺",
"points": [
[
132,
243
],
[
176,
243
],
[
176,
284
],
[
132,
284
]
]
}
]
}

想問一下訓練集

您好,我的文本大概都是像收據有一格一格的

如果我想訓練自己的數據集,我是要整個收據去標註

還是要把收據切成小張圖片(一行)再去標註,謝謝

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.