{"id":19198363,"url":"https://github.com/deepvac/dbnet","last_synced_at":"2025-05-09T01:08:55.424Z","repository":{"id":49047230,"uuid":"357398432","full_name":"DeepVAC/DBNet","owner":"DeepVAC","description":"DeepVAC-compliant DB Net implementation.","archived":false,"fork":false,"pushed_at":"2021-06-30T07:29:31.000Z","size":82,"stargazers_count":17,"open_issues_count":2,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-09T01:08:49.587Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DeepVAC.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-04-13T02:19:53.000Z","updated_at":"2025-04-27T07:45:05.000Z","dependencies_parsed_at":"2022-09-09T03:00:31.364Z","dependency_job_id":null,"html_url":"https://github.com/DeepVAC/DBNet","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeepVAC%2FDBNet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeepVAC%2FDBNet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeepVAC%2FDBNet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeepVAC%2FDBNet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DeepVAC","download_url":"https://codeload.github.com/DeepVAC/DBNet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253171260,"owners_count":21865293,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T12:21:32.938Z","updated_at":"2025-05-09T01:08:55.404Z","avatar_url":"https://github.com/DeepVAC.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DBNet\nDeepVAC-compliant DBNet implementation.\n\n# 简介\n本项目实现了符合DeepVAC规范的OCR检测模型DBNet\n\n**项目依赖**\n\n- deepvac \u003e= 0.5.6\n- pytorch \u003e= 1.8.0\n- torchvision \u003e= 0.7.0\n- opencv-python\n- numpy\n- pyclipper\n- shapely\n- pillow\n\n# 如何运行本项目\n\n## 1. 阅读[DeepVAC规范](https://github.com/DeepVAC/deepvac)\n可以粗略阅读，建立起第一印象\n\n## 2. 准备运行环境\n可以使用DeepVAC规范指定的[Docker镜像](https://github.com/DeepVAC/deepvac#2-%E7%8E%AF%E5%A2%83%E5%87%86%E5%A4%87)\n\n## 3. 准备数据集\n- 获取文本检测数据集\n  CTW1500格式的数据集，CTW1500下载地址:\n\n  [ch4_training_images.zip](https://rrc.cvc.uab.es/downloads/ch4_training_images.zip)\n\n  [ch4_training_localization_transcription_gt.zip](https://rrc.cvc.uab.es/downloads/ch4_training_localization_transcription_gt.zip)\n\n  [ch4_test_images.zip](https://rrc.cvc.uab.es/downloads/ch4_test_images.zip)\n\n  [Challenge4_Test_Task1_GT.zip](https://rrc.cvc.uab.es/downloads/Challenge4_Test_Task1_GT.zip)\n\n- 数据集配置\n  在config.py文件中作如下配置:\n\n```python\nconfig.sample_path = \u003cyour train image path\u003e\nconfig.label_path = \u003cyour train gt path\u003e\n\nconfig.sample_path = \u003cyour val image path\u003e\nconfig.label_path = \u003cyour val gt path\u003e\n```\n\n## 5. 模型相关配置\n\n- DB backbone配置\n\n```python\n# 目前支持resnet18，mv3large\nconfig.arch = \"resnet18\"\n```\n\n## 4. 训练相关配置\n\n- dataloader相关配置\n\n```python\nconfig.is_transform = True        # 是否做数据增强\nconfig.img_size = 640             # 训练图片大小(img_size, img_size)\nconfig.datasets.DBTrainDataset = AttrDict()\nconfig.datasets.DBTrainDataset.shrink_ratio = 0.4\nconfig.datasets.DBTrainDataset.thresh_min = 0.3\nconfig.datasets.DBTrainDataset.thresh_max = 0.7\nconfig.core.DBNetTrain.batch_size = 8\nconfig.core.DBNetTrain.num_workers = 4\nconfig.core.DBNetTrain.train_dataset = DBTrainDataset(config, config.sample_path, config.label_path, config.is_transform, config.img_size)\nconfig.core.DBNetTrain.train_loader = torch.utils.data.DataLoader(\n  dataset = config.core.DBNetTrain.train_dataset,\n  batch_size = config.core.DBNetTrain.batch_size,\n  shuffle = True,\n  num_workers = config.core.DBNetTrain.num_workers,\n  pin_memory = True,\n  sampler = None\n)\n```\n\n## 5. 训练\n\n```\npython3 train.py\n```\n\n## 6. 测试\n\n- 测试相关配置\n\n```python\nconfig.core.DBNetTest.model_path = \u003cyour model path\u003e            # 加载模型路径\n# config.core.DBNetTest.jit_model_path = \u003ctorchscript-model-path\u003e # torchscript model path\nconfig.core.DBNetTest.is_output_polygon = True                  # 输出是否为多边形模型\nconfig.sample_path = \u003cyour test image path\u003e                     # 测试图片路径\nconfig.core.DBNetTrain.batch_size = 8\nconfig.core.DBNetTrain.num_workers = 4\nconfig.core.DBNetTest.test_dataset = DBTestDataset(config, config.sample_path, long_size = 1280)\nconfig.core.DBNetTest.test_loader = torch.utils.data.DataLoader(\n  dataset = config.core.DBNetTest.test_dataset,\n  batch_size = config.core.DBNetTrain.batch_size,\n  shuffle = False,\n  num_workers = config.core.DBNetTrain.num_workers,\n  pin_memory = True\n)\n```\n\n- 运行测试脚本:\n\n```bash\npython3 test.py\n```\n\n## 7. 使用torchscript模型\n\n  如果训练过程中未开启config.cast.TraceCast.model_dir开关，可以在测试过程中转化torchscript模型\n\n  - 转换torchscript模型(.pt)\n\n  ```python\n  config.cast.TraceCast.model_dir = \"output/script.pt\"\n  ```\n\n  按照步骤6完成测试，torchscript模型会保存至config.cast.TraceCast.model_dir指定位置\n\n  - 加载torchscript模型\n\n  ```python\n  config.core.DBNetTest.jit_model_path = \u003ctorchscript-model-path\u003e\n  ```\n  然后按照步骤6测试，会读取script_model\n\n## 更多功能\n\n  如果要在本项目中开启如下功能:\n\n  - 预训练模型加载\n  - checkpoint加载\n  - 使用tensorboard\n  - 启用TorchScript\n  - 转换ONNX\n  - 转换NCNN\n  - 转换CoreML\n  - 开启量化\n  - 开启自动混合精度训练\n  - 采用ema策略(config.ema)\n  - 采用梯度积攒到一定数量再进行反向更新梯度策略(config.nominal_batch_factor)\n\n  请参考[DeepVAC](https://github.com/DeepVAC/deepvac)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeepvac%2Fdbnet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeepvac%2Fdbnet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeepvac%2Fdbnet/lists"}