|
1 | 1 | # HRNet-Semantic-Segmentation
|
2 | 2 |
|
3 |
| -The Pytorch implementation is [HRNet-Semantic-Segmentation-v1.1](https://github.com/HRNet/HRNet-Semantic-Segmentation/tree/pytorch-v1.1). The implemented model is **HRNetV2-W18-Small-v2** |
| 3 | +This repo implemtents [HRNet-Semantic-Segmentation-v1.1](https://github.com/HRNet/HRNet-Semantic-Segmentation/tree/pytorch-v1.1) and [HRNet-Semantic-Segmentation-OCR](https://github.com/HRNet/HRNet-Semantic-Segmentation/tree/HRNet-OCR). |
4 | 4 |
|
5 | 5 |
|
6 | 6 | ## How to Run
|
7 |
| - |
8 |
| -* 1. generate .wts |
9 |
| - |
10 |
| - Download code and model from [HRNet-Semantic-Segmentation-v1.1](https://github.com/HRNet/HRNet-Semantic-Segmentation/tree/pytorch-v1.1) and config your environments. |
11 |
| - |
12 |
| - Put `demo.py` in the `YOUR_ROOT_DIR\HRNet-Semantic-Segmentation\tools ` folder, set `savewts in main()` as `True`, and run, the .wts will be generated. |
13 |
| - |
14 |
| -* 2. cmake and make |
| 7 | +### For HRNet-Semantic-Segmentation-v1.1 |
| 8 | +1. generate .wts, use config `experiments/cityscapes/seg_hrnet_w48_train_512x1024_sgd_lr1e-2_wd5e-4_bs_12_epoch484.yaml` and pretrained weight `hrnet_w48_cityscapes_cls19_1024x2048_trainset.pth` as example. change `PRETRAINED` in `experiments/cityscapes/seg_hrnet_w48_train_512x1024_sgd_lr1e-2_wd5e-4_bs_12_epoch484.yaml` to `""`. |
| 9 | +``` |
| 10 | +cp gen_wts.py $HRNET--Semantic-Segmentation-PROJECT-ROOT/tools |
| 11 | +cd $HRNET--Semantic-Segmentation-PROJECT-ROOT |
| 12 | +python tools/gen_wts.py --cfg experiments/cityscapes/seg_hrnet_w48_train_512x1024_sgd_lr1e-2_wd5e-4_bs_12_epoch484.yaml --ckpt_path hrnet_w48_cityscapes_cls19_1024x2048_trainset.pth --save_path hrnet_w48.wts |
| 13 | +cp hrnet_w48.wts $HRNET-TENSORRT-ROOT |
| 14 | +cd $HRNET-TENSORRT-ROOT |
| 15 | +``` |
| 16 | +2. cmake and make |
15 | 17 |
|
16 | 18 | ```
|
17 | 19 | mkdir build
|
18 | 20 | cd build
|
19 | 21 | cmake ..
|
20 | 22 | make
|
21 |
| - sudo ./hrnetseg -s // serialize model to plan file i.e. 'hrnetseg.engine' |
22 |
| - sudo ./hrnetseg -d ../samples // deserialize plan file and run inference, the images in samples will be processed. |
23 | 23 | ```
|
| 24 | + first serialize model to plan file |
| 25 | + ``` |
| 26 | + ./hrnet -s [.wts] [.engine] [small or 18 or 32 or 48] # small for W18-Small-v2, 18 for W18, etc. |
| 27 | + ``` |
| 28 | + such as |
| 29 | + ``` |
| 30 | + ./hrnet -s ../hrnet_w48.wts ./hrnet_w48.engine 48 |
| 31 | + ``` |
| 32 | + then deserialize plan file and run inference |
| 33 | + ``` |
| 34 | + ./hrnet -d [.engine] [image dir] |
| 35 | + ``` |
| 36 | + such as |
| 37 | + ``` |
| 38 | + ./hrnet -d ./hrnet_w48.engine ../samples |
| 39 | + ``` |
| 40 | +### For HRNet-Semantic-Segmentation-OCR |
| 41 | + |
| 42 | +1. generate .wts, use config `experiments/cityscapes/seg_hrnet_ocr_w48_train_512x1024_sgd_lr1e-2_wd5e-4_bs_12_epoch484.yaml` and pretrained weight `hrnet_ocr_cs_8162_torch11.pth` as example. change `PRETRAINED` in `experiments/cityscapes/seg_hrnet_ocr_w48_train_512x1024_sgd_lr1e-2_wd5e-4_bs_12_epoch484.yaml` to `""`. |
| 43 | +``` |
| 44 | +cp gen_wts.py $HRNET-OCR-TRAIN-PROJECT-ROOT/tools |
| 45 | +cd $HRNET-OCR-PROJECT-ROOT |
| 46 | +python tools/gen_wts.py --cfg experiments/cityscapes/seg_hrnet_ocr_w48_train_512x1024_sgd_lr1e-2_wd5e-4_bs_12_epoch484.yaml --ckpt_path hrnet_ocr_cs_8162_torch11.pth --save_path hrnet_ocr_w48.wts |
| 47 | +cp hrnet_ocr_w48.wts $HRNET-OCR-TENSORRT-ROOT |
| 48 | +cd $HRNET-OCR-TENSORRT-ROOT |
| 49 | +``` |
| 50 | +2. cmake and make |
24 | 51 |
|
| 52 | + ``` |
| 53 | + mkdir build |
| 54 | + cd build |
| 55 | + cmake .. |
| 56 | + make |
| 57 | + ``` |
| 58 | + first serialize model to plan file |
| 59 | + ``` |
| 60 | + ./hrnet_ocr -s [.wts] [.engine] [18 or 32 or 48] |
| 61 | + ``` |
| 62 | + such as |
| 63 | + ``` |
| 64 | + ./hrnet_ocr -s ../hrnet_ocr_w48.wts ./hrnet_ocr_w48.engine 48 |
| 65 | + ``` |
| 66 | + then deserialize plan file and run inference |
| 67 | + ``` |
| 68 | + ./hrnet_ocr -d [.engine] [image dir] |
| 69 | + ``` |
| 70 | + such as |
| 71 | + ``` |
| 72 | + ./hrnet_ocr -d ./hrnet_ocr_w48.engine ../samples |
| 73 | + ``` |
25 | 74 | ## Result
|
26 | 75 |
|
27 | 76 | TRT Result:
|
|
0 commit comments