Skip to content

Commit 1f7672c

Browse files
authored
add hrnet semantic segmentation model w18, w32 and w48 (wang-xinyu#503)
* create psenet create psenet with weight from tensorflow * delete some useless code * repalce tab with 4 blanks * fix network bug, rewrite post-processing pse algorithm * update readme * update readme * add RepVGG * fix typo * add hrnetseg w18 w32 w48 * add hrnetseg with ocr w18 w32 w48 * merge hrnet and small, add hrnet_ocr * fix warning * change project name
1 parent b58a798 commit 1f7672c

File tree

8 files changed

+1584
-751
lines changed

8 files changed

+1584
-751
lines changed

hrnet/hrnet-semantic-segmentation/CMakeLists.txt

+11-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,17 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Ofast -Wfatal-errors -
2424
find_package(OpenCV)
2525
include_directories(${OpenCV_INCLUDE_DIRS})
2626

27-
add_executable(hrnetseg ${PROJECT_SOURCE_DIR}/hrnetseg.cpp)
28-
target_link_libraries(hrnetseg nvinfer)
29-
target_link_libraries(hrnetseg cudart)
30-
target_link_libraries(hrnetseg ${OpenCV_LIBS})
27+
add_executable(hrnet ${PROJECT_SOURCE_DIR}/hrnet.cpp)
28+
target_link_libraries(hrnet nvinfer)
29+
target_link_libraries(hrnet cudart)
30+
target_link_libraries(hrnet ${OpenCV_LIBS})
31+
32+
33+
add_executable(hrnet_ocr ${PROJECT_SOURCE_DIR}/hrnet_ocr.cpp)
34+
target_link_libraries(hrnet_ocr nvinfer)
35+
target_link_libraries(hrnet_ocr cudart)
36+
target_link_libraries(hrnet_ocr ${OpenCV_LIBS})
37+
3138

3239
add_definitions(-O2 -pthread)
3340

hrnet/hrnet-semantic-segmentation/README.md

+60-11
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,76 @@
11
# HRNet-Semantic-Segmentation
22

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).
44

55

66
## 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
1517

1618
```
1719
mkdir build
1820
cd build
1921
cmake ..
2022
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.
2323
```
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
2451

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+
```
2574
## Result
2675

2776
TRT Result:

0 commit comments

Comments
 (0)