์ด ๊ธ€์€ ์ œ๊ฐ€ ใ€ŽCenterNet: Objects as Pointsใ€์˜ ์ฝ”๋“œ๋ฅผ ์ง์ ‘ ์‹ค์Šตํ•ด๋ณธ ๊ณผ์ •์„ ๊ธฐ๋กํ•œ ํฌ์ŠคํŠธ ์ž…๋‹ˆ๋‹ค.

4 minute read

์ด ๊ธ€์€ ์ œ๊ฐ€ ใ€ŽCenterNet: Objects as Pointsใ€์˜ ์ฝ”๋“œ๋ฅผ ์ง์ ‘ ์‹ค์Šตํ•ด๋ณธ ๊ณผ์ •์„ ๊ธฐ๋กํ•œ ํฌ์ŠคํŠธ ์ž…๋‹ˆ๋‹ค.

์‹คํ–‰ ํ™˜๊ฒฝ์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

(2021.06.03)
- Windows ๐Ÿ”ฅ
- Python: 3.9.2
- PyTorch: 1.8.0
- CUDA: 10.2
- VS2019
- CenterNet last commit: 2020.06.21

GitHub์— ๊ฒŒ์‹œ๋œ <CenterNet>์˜ ์ฝ”๋“œ์˜ ํŠœํ† ๋ฆฌ์–ผ์„ Windows ํ™˜๊ฒฝ์—์„œ ๊ทธ๋Œ€๋กœ ์‹คํ–‰ํ•˜๋ฉด, ์•„๋ž˜์™€ ๊ฐ™์€ ์˜ค๋ฅ˜๋ฅผ ์–ป๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

ModuleNotFoundError: No module named '_ext'

์ด ํฌ์ŠคํŠธ๋Š” Windows ํ™˜๊ฒฝ์—์„œ <CenterNet>์„ ๋Œ๋ฆฌ๊ณ ์ž ํ•˜๋Š” ๋ถ„๋“ค์„ ์œ„ํ•œ ํฌ์ŠคํŠธ ์ž…๋‹ˆ๋‹ค! ๊ฐ€์ด๋“œ๋ฅผ ๋”ฐ๋ผํ•˜๊ธฐ ์ „, ๋ณธ์ธ์˜ ์‹คํ–‰ ํ™˜๊ฒฝ์„ ๋ฐ˜.๋“œ.์‹œ. ์ฒดํฌํ•ด์ฃผ์„ธ์š”! (์ œ ๋ฐฉ๋ฒ•๋„ ์‹œ๊ฐ„์ด ์ง€๋‚˜๋ฉด, ์ •์ƒ์ ์œผ๋กœ ๋™์ž‘ํ•˜์ง€ ์•Š์„ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค ใ… ใ… )


Start CenterNet on Windows

๊ฐ€์žฅ ๋จผ์ € ์‹œ๋„ํ•ด๋ณผ ๊ฒƒ์€ <CenterNet>์—์„œ ์ œ์‹œํ•˜๋Š” Installation ๋ฌธ์„œ๋ฅผ ๊ทธ๋Œ€๋กœ ๋”ฐ๋ผํ•ด๋ณด๋Š” ๊ฒƒ ์ž…๋‹ˆ๋‹ค.

๐Ÿ‘‰ CenterNet/readme/INSTALL.md

์ด ๊ณผ์ •์„ ๊ทธ๋Œ€๋กœ ์ง„ํ–‰ํ–ˆ์Œ์—๋„ demo.py ์‹คํ–‰์— ์‹คํŒจํ–ˆ๋‹ค๋ฉด, <CenterNet>์— Issue๋กœ ์˜ฌ๋ผ์˜จ โ€˜auskโ€™๋‹˜์˜ ์ด์Šˆ๋ฅผ ๋”ฐ๋ผํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ‘‰ CenterNet/Issue - CenterNet works ok on Pytorch 1.1 + Cuda10.1 + Win10

โ€˜auskโ€™๋‹˜์˜ ์ด์Šˆ๋ฅผ ๊ทธ๋Œ€๋กœ ์ง„ํ–‰ํ–ˆ์Œ์—๋„ ์‹คํŒจํ–ˆ๋‹ค๋ฉด, ์ œ๊ฐ€ ์„ฑ๊ณตํ•œ ๋ฐฉ์‹์œผ๋กœ ์ง„ํ–‰ํ•ด๋ณด์„ธ์š”!

๐Ÿ’ฅ ์ €๋Š” ํŠœํ† ๋ฆฌ์–ผ ์ž‘์„ฑ์„ ์œ„ํ•ด GitHub์—์„œ <CenterNet> ๋ ˆํฌ๋ฅผ ๋‹ค์‹œ ๋‹ค์šด ๋ฐ›์•„์„œ ์ง„ํ–‰ํ–ˆ์Šต๋‹ˆ๋‹ค!

๐Ÿ’ฅ Python Interpreter ์„ค์ •๊ณผ requirements.txt ์„ค์น˜๋Š” ๋ชจ๋‘ ์™„๋ฃŒ๋˜์—ˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•ฉ๋‹ˆ๋‹ค.

1. Build nms

cd src/lib/external/setup.py ํŒŒ์ผ์—์„œ "-Wno-cpp" ๋ถ€๋ถ„์„ ์•„๋ž˜์™€ ๊ฐ™์ด ์ฃผ์„์ฒ˜๋ฆฌ

extensions = [
    Extension(
        "nms",
        ["nms.pyx"],
        # extra_compile_args=["-Wno-cpp", "-Wno-unused-function"]
    )
]

์ˆ˜์ • ํ›„, ์•„๋ž˜์˜ ๋ช…๋ น์–ด ์‹คํ–‰

cd src/lib/external
python setup.py build_ext --inplace

## output
nms.c(7997): warning C4244: '=': 'double'์—์„œ 'float'(์œผ)๋กœ ๋ณ€ํ™˜ํ•˜๋ฉด์„œ ๋ฐ์ดํ„ฐ๊ฐ€ ์†์‹ค๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
nms.c(8016): warning C4244: '=': 'double'์—์„œ 'float'(์œผ)๋กœ ๋ณ€ํ™˜ํ•˜๋ฉด์„œ ๋ฐ์ดํ„ฐ๊ฐ€ ์†์‹ค๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
nms.c(8059): warning C4244: '=': 'double'์—์„œ 'float'(์œผ)๋กœ ๋ณ€ํ™˜ํ•˜๋ฉด์„œ ๋ฐ์ดํ„ฐ๊ฐ€ ์†์‹ค๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
nms.c(8192): warning C4244: 'ํ•จ์ˆ˜': 'double'์—์„œ 'float'(์œผ)๋กœ ๋ณ€ํ™˜ํ•˜๋ฉด์„œ ๋ฐ์ดํ„ฐ๊ฐ€ ์†์‹ค๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
...
...
   build\temp.win-amd64-3.9\Release\nms.cp39-win_amd64.lib ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋ฐ build\temp.win-amd64-3.9\Release\nms.cp39-win_amd64.exp ๊ฐœ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
์ฝ”๋“œ๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
์ฝ”๋“œ๋ฅผ ์ƒ์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค.

์‹คํ–‰ ํ›„, ์œ„์™€ ๊ฐ™์ด ์ถœ๋ ฅ๋˜๋ฉด ์ •์ƒ์ ์œผ๋กœ ์™„๋ฃŒ๋œ ๊ฒƒ. (warning์€ ๋ฌด์‹œํ•ด๋„ ๋œ๋‹ค.)

2. Clone and Build DCNv2

์—ฌ๊ธฐ์—์„œ โ€˜auskโ€™๋‹˜์˜ ์ด์Šˆ์™€ ๋‹ค๋ฅด๊ฒŒ ์ง„ํ–‰ํ•œ๋‹ค.

๋จผ์ €, ๊ธฐ์กด <CenterNet>์˜ src/lib/models/networks์˜ DCNv2 ํด๋”๋ฅผ ์‚ญ์ œํ•œ๋‹ค. <CeterNet>dms PyTorch 0.4.1์ด๋ผ๋Š” ์•„์ฃผ ๊ตฌ์‹œ๋Œ€ ๋ฒ„์ „์˜ PyTorch๋ฅผ ์“ฐ๊ณ  ์žˆ๊ณ , CenterNet์˜ ๋ ˆํฌ์—๋Š” ์ด๊ฒƒ์— ๋งž์ถ˜ DCNv2 ๋ชจ๋ธ์ด ๋“ค์–ด์žˆ๋‹ค. ๊ทธ๋ž˜์„œ CenterNet ๋ ˆํฌ์˜ DCNv2๋Š” PyTorch 1.x๋Œ€์™€๋Š” ์ „ํ˜€ ํ˜ธํ™˜ ๋˜์ง€ ์•Š๋Š”๋‹ค.

โ€˜auskโ€™๋‹˜์˜ ์ด์Šˆ์—์„œ๋Š” DCNv2์˜ original repo๋ฅผ ๋‹ค์šด ๋ฐ›์œผ๋ผ๊ณ  ํ•˜์ง€๋งŒ, ์ด๊ฒƒ ์—ญ์‹œ ๋ณธ์ธ์€ ๋™์ž‘ํ•˜์ง€ ์•Š์•˜๋‹ค. ๋Œ€์‹  ์•„๋ž˜์˜ DCNv2 ๋ ˆํฌ๋ฅผ ๋‹ค์šด ๋ฐ›์•„์„œ ๊ธฐ์กด DCNv2์˜ ํด๋”์— ๋„ฃ๋„๋ก ํ•˜์ž!

๐Ÿ‘‰ jinfagang/DCNv2_latest // compatible with PyTorch 1.8+

๋‹ค์šด & unzip ํ›„, ๊ฒฝ๋กœ๋กœ ๋“ค์–ด๊ฐ€์„œ ์•„๋ž˜์˜ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•œ๋‹ค.

cd src/lib/models/networks/DCNv2
python setup.py build develop

## output
...
...
์ฝ”๋“œ๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
์ฝ”๋“œ๋ฅผ ์ƒ์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค.
copying build\lib.win-amd64-3.9\_ext.cp39-win_amd64.pyd ->
Creating c:\users\hsy4462\miniconda3\envs\pytorch_latest\lib\site-packages\DCNv2.egg-link (link to .)
Removing DCNv2 0.1 from easy-install.pth file
Adding DCNv2 0.1 to easy-install.pth file

Installed c:\users\hsy4462\documents\github\centernet-master\src\lib\models\networks\dcnv2
Processing dependencies for DCNv2==0.1
Finished processing dependencies for DCNv2==0.1

์œ„์™€ ๊ฐ™์€ ์ถœ๋ ฅ ๊ฒฐ๊ณผ์™€ DCNv2/ ํด๋”์— build/, DCNv2.egg-info/, _ext.cp39-win_amd64.pyd ๋“ฑ์ด ์ƒ์„ฑ๋˜์—ˆ๋‹ค๋ฉด, ์„ฑ๊ณต์ด๋‹ค!

DCNv2/ ํด๋”์— ์žˆ๋Š” testcpu.py, testcuda.py๋ฅผ ์‹คํ–‰์‹œ์ผœ๋„ ์˜จ์ „ํžˆ ๋™์ž‘ํ•˜์ง€๋Š” ์•Š์„ ๊ฒƒ์ด๋‹ค. ๊ทธ๋ž˜๋„ ๊ดœ์ฐฎ๋‹ค. ๋‹ค์Œ ๋‹จ๊ณ„๋กœ ๋„˜์–ด๊ฐ€์ž.

3. Run Demo

์ด์ œ <CenterNet>์˜ demo.py๋ฅผ ์‹คํ–‰์‹œ์ผœ ์ž˜ ๋™์ž‘ํ•˜๋Š”์ง€ ํ™•์ธํ•ด๋ณด์ž.

๋จผ์ € ๋™์ž‘์— ํ•„์š”ํ•œ ๋ชจ๋ธ์„ ๋‹ค์šด ๋ฐ›๋Š”๋‹ค. CenterNet GitHub์˜ MODEL ZOO์—์„œ ๋‹ค์šด ๋ฐ›์„ ์ˆ˜ ์žˆ๋‹ค. ctdet_coco_dla_2x.pth๋ฅผ ๋‹ค์šด๋ฐ›์•„์„œ models/ ํด๋”์— ๋„ฃ์–ด์ฃผ์ž.

์ด์ œ ์•„๋ž˜์˜ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•ด๋ณด์ž!

cd src
python demo.py ctdet --demo ../images/17790319373_bd19b24cfc_k.jpg --load_model ../models/ctdet_coco_dla_2x.pth --debug 2

์ •์ƒ์ ์œผ๋กœ ์‹คํ–‰๋˜๋ฉด, ์•„๋ž˜์˜ ์‚ฌ์ง„๋“ค์ด ๋‚˜์˜ฌ ๊ฒƒ์ด๋‹ค!!

๋„-์•!!