{"id":19198357,"url":"https://github.com/deepvac/hrnet-lite-seg","last_synced_at":"2025-05-09T01:08:24.814Z","repository":{"id":49167758,"uuid":"368031576","full_name":"DeepVAC/HRNet-lite-seg","owner":"DeepVAC","description":"DeepVAC-compliant HRNet-lite implementation for segmentation.","archived":false,"fork":false,"pushed_at":"2021-06-25T10:08:05.000Z","size":32,"stargazers_count":8,"open_issues_count":1,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-09T01:08:19.672Z","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-05-17T02:22:47.000Z","updated_at":"2024-09-29T15:28:05.000Z","dependencies_parsed_at":"2022-09-16T07:22:26.131Z","dependency_job_id":null,"html_url":"https://github.com/DeepVAC/HRNet-lite-seg","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%2FHRNet-lite-seg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeepVAC%2FHRNet-lite-seg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeepVAC%2FHRNet-lite-seg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeepVAC%2FHRNet-lite-seg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DeepVAC","download_url":"https://codeload.github.com/DeepVAC/HRNet-lite-seg/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253171257,"owners_count":21865292,"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:31.130Z","updated_at":"2025-05-09T01:08:24.789Z","avatar_url":"https://github.com/DeepVAC.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HRNet-lite-seg\nDeepVAC-compliant HRNet-lite implementation for segmentation.\n\n# 简介\n本项目实现了符合DeepVAC规范的HRNet-lite-seg 。\n\n### 项目依赖\n\n- deepvac \u003e= 0.5.7\n- pytorch \u003e= 1.8.0\n- torchvision \u003e= 0.7.0\n- opencv-python\n- numpy\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- TODO\n\n- 在config.py中修改如下配置：\n```python\nconfig.train_txt = './data/train.txt'\nconfig.val_txt = './data/val.txt'\nconfig.sample_path_prefix = 'your train images dir'\n```\n\n## 4. 训练相关配置\n\n- dataloader相关配置\n\n```python\nconfig.datasets.FileLineCvSegWithMetaInfoDataset = AttrDict()\nconfig.datasets.FileLineCvSegWithMetaInfoDataset.cached_data_file = 'data/clothes.p'\nconfig.datasets.FileLineCvSegWithMetaInfoDataset.classes = config.cls_num\nconfig.datasets.FileLineCvSegWithMetaInfoDataset.norm_val = 1.10\nconfig.data = FileLineCvSegWithMetaInfoDataset(config, config.train_txt, config.sample_path_prefix)()\nconfig.datasets.FileLineCvSegDataset = AttrDict()\nconfig.datasets.FileLineCvSegDataset.composer = LiteHRNetTrainComposer(config)\n\n\nconfig.batch_size = 8\nconfig.num_workers = 3\nconfig.core.LiteHRNetTrain.train_dataset = FileLineCvSegDataset(config, config.train_txt, config.delimiter, config.sample_path_prefix)\nconfig.core.LiteHRNetTrain.train_loader = torch.utils.data.DataLoader(config.core.LiteHRNetTrain.train_dataset, batch_size=config.batch_size, shuffle=True, num_workers=config.num_workers, pin_memory=config.pin_memory)\n\n```\n## 5. 训练\n\n### 5.1 单卡训练\n执行命令：\n\n```bash\npython3 train.py\n```\n\n### 5.2 分布式训练\n\n在config.py中修改如下配置：\n```python\n#dist_url，单机多卡无需改动，多机训练一定要修改\nconfig.core.LiteHRNetTrain.dist_url = \"tcp://localhost:27030\"\n\n#rank的数量，一定要修改\nconfig.core.LiteHRNetTrain.world_size = 2\n```\n然后执行命令：\n\n```bash\npython train.py --rank 0 --gpu 0\npython train.py --rank 1 --gpu 1\n```\n\n\n## 6. 测试\n\n- 测试相关配置\n\n```python\nconfig.core.LiteHRNetTest = config.core.LiteHRNetTrain.clone()\nconfig.core.LiteHRNetTest.test_sample_path = 'your test image dir'\nconfig.core.LiteHRNetTest.model_path = 'your trained model path'\n```\n\n- 加载模型(*.pth)\n\n```python\nconfig.core.LiteHRNetTest.model_path = \u003ctrained-model-path\u003e\n```\n\n- 运行测试脚本：\n\n```bash\npython3 test.py\n```\n## 7. 使用trace模型/script模型\n如果训练过程中开启config.cast.TraceCast（或者config.cast.ScriptCast)开关，可以在测试过程中转化torchscript模型     \n\n- 转换torchscript模型(*.pt)     \n\n```python\n# trace\nconfig.cast.TraceCast = AttrDict()\nconfig.cast.TraceCast.model_dir = \"./trace.pt\"\n\n# script\nconfig.cast.ScriptCast = AttrDict()\nconfig.cast.ScriptCast.model_dir = \"./script.pt\"\n```\n\n按照步骤6完成测试，torchscript模型将保存至model_dir指定文件位置      \n\n- 加载torchscript模型\n\n```python\nconfig.core.LiteHRNetTrain.jit_model_path = \u003ctorchscript-model-path\u003e\nconfig.core.LiteHRNetTest.jit_model_path = \u003ctorchscript-model-path\u003e\n```\n\n## 8. 使用静态量化模型\n如果训练过程中未开启config.cast.TraceCast开关，可以在测试过程中转化静态量化模型     \n- 转换静态模型(*.sq)     \n\n```python\n# trace\nconfig.cast.TraceCast.static_quantize_dir = \"./trace.sq\"\n\n# script\nconfig.cast.ScriptCast.static_quantize_dir = \"./script.sq\"\n```\n按照步骤6完成测试，静态量化模型将保存至config.static_quantize_dir指定文件位置      \n\n- 加载静态量化模型\n\n```python\nconfig.core.LiteHRNetTrain.jit_model_path = \u003cstatic-quantize-model-path\u003e\nconfig.core.LiteHRNetTest.jit_model_path = \u003cstatic-quantize-model-path\u003e\n```\n- 动态量化模型对应的配置参数为config.cast.TraceCast.dynamic_quantize_dir(或者config.cast.ScriptCast.dynamic_quantize_dir)\n\n## 9. 更多功能\n如果要在本项目中开启如下功能：\n- 预训练模型加载\n- checkpoint加载\n- 使用tensorboard\n- 启用TorchScript\n- 转换ONNX\n- 转换NCNN\n- 转换CoreML\n- 开启量化\n- 开启自动混合精度训练\n\n请参考[DeepVAC](https://github.com/DeepVAC/deepvac)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeepvac%2Fhrnet-lite-seg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeepvac%2Fhrnet-lite-seg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeepvac%2Fhrnet-lite-seg/lists"}