Giter VIP home page Giter VIP logo

dbnet's Introduction

DBNet

DeepVAC-compliant DBNet implementation.

简介

本项目实现了符合DeepVAC规范的OCR检测模型DBNet

项目依赖

  • deepvac >= 0.5.6
  • pytorch >= 1.8.0
  • torchvision >= 0.7.0
  • opencv-python
  • numpy
  • pyclipper
  • shapely
  • pillow

如何运行本项目

1. 阅读DeepVAC规范

可以粗略阅读,建立起第一印象

2. 准备运行环境

可以使用DeepVAC规范指定的Docker镜像

3. 准备数据集

config.sample_path = <your train image path>
config.label_path = <your train gt path>

config.sample_path = <your val image path>
config.label_path = <your val gt path>

5. 模型相关配置

  • DB backbone配置
# 目前支持resnet18,mv3large
config.arch = "resnet18"

4. 训练相关配置

  • dataloader相关配置
config.is_transform = True        # 是否做数据增强
config.img_size = 640             # 训练图片大小(img_size, img_size)
config.datasets.DBTrainDataset = AttrDict()
config.datasets.DBTrainDataset.shrink_ratio = 0.4
config.datasets.DBTrainDataset.thresh_min = 0.3
config.datasets.DBTrainDataset.thresh_max = 0.7
config.core.DBNetTrain.batch_size = 8
config.core.DBNetTrain.num_workers = 4
config.core.DBNetTrain.train_dataset = DBTrainDataset(config, config.sample_path, config.label_path, config.is_transform, config.img_size)
config.core.DBNetTrain.train_loader = torch.utils.data.DataLoader(
  dataset = config.core.DBNetTrain.train_dataset,
  batch_size = config.core.DBNetTrain.batch_size,
  shuffle = True,
  num_workers = config.core.DBNetTrain.num_workers,
  pin_memory = True,
  sampler = None
)

5. 训练

python3 train.py

6. 测试

  • 测试相关配置
config.core.DBNetTest.model_path = <your model path>            # 加载模型路径
# config.core.DBNetTest.jit_model_path = <torchscript-model-path> # torchscript model path
config.core.DBNetTest.is_output_polygon = True                  # 输出是否为多边形模型
config.sample_path = <your test image path>                     # 测试图片路径
config.core.DBNetTrain.batch_size = 8
config.core.DBNetTrain.num_workers = 4
config.core.DBNetTest.test_dataset = DBTestDataset(config, config.sample_path, long_size = 1280)
config.core.DBNetTest.test_loader = torch.utils.data.DataLoader(
  dataset = config.core.DBNetTest.test_dataset,
  batch_size = config.core.DBNetTrain.batch_size,
  shuffle = False,
  num_workers = config.core.DBNetTrain.num_workers,
  pin_memory = True
)
  • 运行测试脚本:
python3 test.py

7. 使用torchscript模型

如果训练过程中未开启config.cast.TraceCast.model_dir开关,可以在测试过程中转化torchscript模型

  • 转换torchscript模型(.pt)
config.cast.TraceCast.model_dir = "output/script.pt"

按照步骤6完成测试,torchscript模型会保存至config.cast.TraceCast.model_dir指定位置

  • 加载torchscript模型
config.core.DBNetTest.jit_model_path = <torchscript-model-path>

然后按照步骤6测试,会读取script_model

更多功能

如果要在本项目中开启如下功能:

  • 预训练模型加载
  • checkpoint加载
  • 使用tensorboard
  • 启用TorchScript
  • 转换ONNX
  • 转换NCNN
  • 转换CoreML
  • 开启量化
  • 开启自动混合精度训练
  • 采用ema策略(config.ema)
  • 采用梯度积攒到一定数量再进行反向更新梯度策略(config.nominal_batch_factor)

请参考DeepVAC

dbnet's People

Contributors

buptlihang avatar gemfield avatar

Stargazers

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

Watchers

 avatar  avatar

dbnet's Issues

测试出现问题?

File "/home/jiangchang/anaconda3/envs/torch/lib/python3.8/site-packages/deepvac/core/deepvac.py", line 296, in process
x = self.doTest()
File "/tmp/pycharm_project_511/DB/DB/test.py", line 51, in doTest
self.config.sample = img
UnboundLocalError: local variable 'img' referenced before assignment
代码没有改变 但是不能测试
请问框架里面这个是什么 self.config.sample = img 谢谢

数据集

下载下来的ICDAR2015数据集数据集没有json格式的呀,请问怎么解决

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.