๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๊ธฐํƒ€

PyTorch๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์‹ค์‹œ๊ฐ„ ์ฐจ์„  ๊ฐ์ง€ (Lane Detection) ๋ชจ๋ธ ํ•™์Šต์‹œํ‚ค๊ธฐ

by Whiimsy 2023. 9. 5.

๐ŸŒฏ ์†Œ๊ฐœ

 

GitHub - IrohXu/lanenet-lane-detection-pytorch: Unofficial implemention of lanenet model for real time lane detection Pytorch Ve

Unofficial implemention of lanenet model for real time lane detection Pytorch Version - GitHub - IrohXu/lanenet-lane-detection-pytorch: Unofficial implemention of lanenet model for real time lane d...

github.com

lanenet-lane-detection-pytorch ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋Š” ์‹ค์‹œ๊ฐ„ ์ฐจ์„  ๊ฐ์ง€๋ฅผ ์œ„ํ•œ lanenet ๋ชจ๋ธ์˜ ๋น„๊ณต์‹ ๊ตฌํ˜„์ธ PyTorch ๋ฒ„์ „์ž„. ๋‚œ PyTorch๊ฐ€ ๋ญํ•˜๋Š” ๊ฑด์ง€๋„ ๋ชฐ๋ž์Œ.

- ๐Ÿ“ lanenet ๋ชจ๋ธ

- ๐Ÿ“ PyTorch

 

PyTorch๋ฅผ ์‚ฌ์šฉํ•ด IEEE IV ํ•™ํšŒ ๋…ผ๋ฌธ "Towards End-to-End Lane Detection: an Instance Segmentation Approach"์„ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•œ ์ฐจ์„  ๊ฐ์ง€๋ฅผ ์œ„ํ•œ ์‹ฌ์ธต ์‹ ๊ฒฝ๋ง์„ ๊ตฌํ˜„ํ•œ๋‹ค๊ณ  ํ•จ. 

- ๐Ÿ“ ์‹ฌ์ธต ์‹ ๊ฒฝ๋ง(DNN, Deep neural Network)

 

์ด ๋ชจ๋ธ์˜ ๊ตฌ์„ฑ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Œ.

1. ENet ์ธ์ฝ”๋”

2. ์ด์ง„ ์‹œ๋งจํ‹ฑ ๋ถ„ํ• ์„ ์œ„ํ•œ ENet ๋””์ฝ”๋”

3. ํŒ๋ณ„ ์†์‹ค ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด ์ธ์Šคํ„ด์Šค ์‹œ๋งจํ‹ฑ ๋ถ„ํ• ์„ ์œ„ํ•œ ENet ๋””์ฝ”๋”

 

๋ฉ”์ธ ๋„คํŠธ์›Œํฌ ์•„ํ‚คํ…์ฒ˜๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Œ.

 

ํ•™์Šต์˜ ๊ฒฐ๊ณผ ์•„๋ž˜์™€ ๊ฐ™์€ ๊ฒฐ๊ณผ๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ๋‹ค๊ณ  ํ•จ.

input์œผ๋กœ ์ฒซ๋ฒˆ์งธ ์‚ฌ์ง„์„ ๋„ฃ์œผ๋ฉด instance output์œผ๋กœ ๋‘๋ฒˆ์งธ ์‚ฌ์ง„์„, binary output์œผ๋กœ ์„ธ๋ฒˆ์งธ ์‚ฌ์ง„์„ ์–ป์„ ์ˆ˜ ์žˆ์Œ.

 

๐Ÿซ” ์ค€๋น„

1. Git (๋‚ด ๋ฒ„์ „ : git version 2.42.0.windows.1)

2. Python (๋‚ด ๋ฒ„์ „ : Python 3.11.0)

3. PyCharm Community Edition 2023.2.1

4. CUDA Toolkit (๋‚ด ๋ฒ„์ „ : V11.7.64)

 

๐Ÿฅซ ์‹œ์ž‘

Git Clone

๋ช…๋ น ํ”„๋กฌํ”„ํŠธ๋ฅผ ํ‚ค๊ณ  ์›ํ•˜๋Š” ์œ„์น˜๋กœ ์ด๋™ํ•ด lanenet-lane-detection-pytorch ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ ํด๋ก ํ•จ. 

git clone https://github.com/IrohXu/lanenet-lane-detection-pytorch.git

๊ฐ€์ƒ ํ™˜๊ฒฝ ์„ธํŒ…

ํด๋ก ํ•œ ๋ ˆํฌ์ง€ํ† ๋ฆฌ ๊ฒฝ๋กœ๋กœ ์ด๋™ํ•ด์„œ ๊ฐ€์ƒ ํ™˜๊ฒฝ์„ ์ƒ์„ฑํ•˜๋Š” ๋ช…๋ น์–ด ์ž…๋ ฅ. ๋ช…๋ น์–ด๋ฅผ ๋ถ„๋ฆฌํ•ด๋ณด๋ฉด python(Python ์ธํ„ฐํ”„๋ฆฌํ„ฐ ์‹คํ–‰) -m venv(๊ฐ€์ƒ ํ™˜๊ฒฝ ๊ด€๋ฆฌํ•˜๋Š” venv ๋ชจ๋“ˆ ์‹คํ–‰) venv(๊ฐ€์ƒ ํ™˜๊ฒฝ ์ด๋ฆ„ ์„ค์ •)๋ผ๋Š” ์˜๋ฏธ์ž„.

python -m venv venv

 

๊ฐ€์ƒ ํ™˜๊ฒฝ ์‹คํ–‰

์•„๋ž˜ ๋ช…๋ น์–ด๋กœ ๊ฐ€์ƒ ํ™˜๊ฒฝ ํ™œ์„ฑํ™” ์‹คํ–‰. ๊ฐ€์ƒ ํ™˜๊ฒฝ์ด ์‹คํ–‰๋˜๋ฉด ๋ช…๋ น ํ”„๋กฌํ”„ํŠธ์˜ ํ”„๋กฌํฌํŠธ ๋งจ ์•ž์— ๊ฐ€์ƒ ํ™˜๊ฒฝ์˜ ์ด๋ฆ„์ด ํ‘œ์‹œ๋จ. ๊ฐ€์ƒ ํ™˜๊ฒฝ ๋น„ํ™œ์„ฑํ™”๋Š” `deactivate` ๋ช…๋ น์–ด๋กœ ๊ฐ€๋Šฅ.

venv\Scripts\activate

 

์˜์กด์„ฑ ๋ชฉ๋ก ์„ค์น˜

= requirements.txt ์„ค์น˜

ํ† ์น˜ ๋ฒ„์ „ ์ž˜๋ชป ๊น”์Œ.. cuda 1.7๊ณผ ํ˜ธํ™˜๋˜๋Š” ๋ฒ„์ „์œผ๋กœ ๋‹ค์‹œ ์„ค์น˜ ํŒ€์žฅ๋‹˜ ์ตœ๊ณ 

scikit-image๋„ ์•ˆ๊น”์Œ

ํ›ˆ๋ จ

์ผ๋‹จ ํŒŒ์ด์ฐธ ์ผœ๋ณด๊ธฐ

๋‚ด ์ฟ ๋‹ค๊ฐ€ ์ž˜ ๋„๋Š”์ง€ ํ™•์ธ

์•„์ฃผ ๊ตฟ

์ฒซ ํ›ˆ๋ จ ์™„๋ฃŒ loss๊ฐ€ 1์„ ๋„˜์Œ

best_model.pth ํŒŒ์ผ์ด ์—…๋ฐ์ดํŠธ๋จ

๋กœ๊ทธ๋„ ์ž˜ ๋“ค์–ด์˜ด

์ฒซ ํ›ˆ๋ จ ์„ฑ๊ณผ ํ™•์ธํ•˜๊ธฐ

์งฑ๋ฉ์ฒญ

๋” ๋นก์„ธ๊ฒŒ ํ›ˆ๋ จ์‹œํ‚ค๊ธฐ

[TuSimple

Ace the Lane Detection Challenge

www.kaggle.com](https://www.kaggle.com/datasets/manideep1108/tusimple)

TUSimple ๋ฐ์ดํ„ฐ์…‹ ๋‹ค์šด๋กœ๋“œํ•˜๊ณ 

ํ›ˆ๋ จ์‹œํ‚ค๊ธฐ

๊ทธ ์ „์— ๋„ˆ๋ฌด ์˜ค๋ž˜ ๊ฑธ๋ ค์„œ ํ›ˆ๋ จ์‹œํ‚ค๊ณ  ์ž˜๊ฑฐ๋‹ˆ๊นŒ ๋‚˜์ค‘์— ์–ผ๋งˆ๋‚˜ ๊ฑธ๋ ธ๋Š”์ง€ ํ™•์ธ ์šฉ๋„๋กœ epoch ํ•˜๋‚˜ ์ฐ์„ ๋•Œ๋งˆ๋‹ค ํƒ€์ž„์Šคํƒฌํ”„๋„ ๊ฐ™์ด ์ฐ๊ธฐ

train.py์— ์•„๋ž˜ ์ฝ”๋“œ ์ถ”๊ฐ€

import datetime

# ...

for epoch in range(num_epochs):
    current_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    print(f'[{current_time}] Epoch {epoch}/{num_epochs - 1}')
    print('-' * 10)

    # ๋‚˜๋จธ์ง€ ์ฝ”๋“œ๋Š” ๊ทธ๋Œ€๋กœ ์œ ์ง€ํ•ฉ๋‹ˆ๋‹ค.

์ž์•ผ์ง•

python train.py: Python ์Šคํฌ๋ฆฝํŠธ "train.py"๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค. ์ด ์Šคํฌ๋ฆฝํŠธ๋Š” ๋ชจ๋ธ ํ›ˆ๋ จ์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

--dataset path/to/tusimpledataset/training: ์ด ํ”Œ๋ž˜๊ทธ๋Š” ์‚ฌ์šฉํ•  ๋ฐ์ดํ„ฐ์…‹์˜ ๊ฒฝ๋กœ๋ฅผ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค. "path/to/tusimpledataset/training" ๋ถ€๋ถ„์€ ์‹ค์ œ ๋ฐ์ดํ„ฐ์…‹์ด ์žˆ๋Š” ๋””๋ ‰ํ† ๋ฆฌ ๊ฒฝ๋กœ๋กœ ๋Œ€์ฒด๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ด ๋””๋ ‰ํ† ๋ฆฌ๋Š” ํ›ˆ๋ จ ๋ฐ์ดํ„ฐ๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

--loss_type CrossEntropyLoss: ์ด ํ”Œ๋ž˜๊ทธ๋Š” ์‚ฌ์šฉํ•  ์†์‹ค ํ•จ์ˆ˜์˜ ์œ ํ˜•์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์—์„œ "CrossEntropyLoss"๋ฅผ ์‚ฌ์šฉํ•˜๋„๋ก ์„ค์ •๋˜์–ด ์žˆ์œผ๋ฏ€๋กœ, ํ›ˆ๋ จ ์ค‘์— ๋ชจ๋ธ์˜ ์˜ˆ์ธก๊ณผ ์‹ค์ œ ๋ ˆ์ด๋ธ” ๊ฐ„์˜ ๊ต์ฐจ ์—”ํŠธ๋กœํ”ผ ์†์‹ค์„ ์ตœ์†Œํ™”ํ•˜๋ ค๊ณ  ์‹œ๋„ํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๋‹ค๋ฅธ ์†์‹ค ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ํ•ด๋‹น ์†์‹ค ํ•จ์ˆ˜์˜ ์ด๋ฆ„์„ ์—ฌ๊ธฐ์— ์ง€์ •ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

... 9์›” 5์ผ 00:43์— ์‹œ์ž‘ํ•œ ํ›ˆ๋ จ์ด 9์›” 6์ผ 03:34์— ๋๋‚ฌ์Œ. 27์‹œ๊ฐ„ ๊ฑธ๋ฆผ...

 

python train.py --dataset ./tusimpledataset/TUSimple/train_set/training ์ด 172m, ํ‰๊ท ์ ์œผ๋กœ 7๋ถ„์”ฉ,

 

python train.py --dataset ./tusimpledataset/TUSimple/train_set/training --loss_type CrossEntropyLoss ์ด 166m, ํ‰๊ท ์ ์œผ๋กœ 7๋ถ„์”ฉ,

python train.py --dataset ./tusimpledataset/TUSimple/train_set/training --model_type DeepLabv3+ ์ด 1328m, ํ‰๊ท ์ ์œผ๋กœ 53์”ฉ ๊ฑธ๋ ธ์Œ.

 

ํ…Œ์ŠคํŠธ

๋จผ์ € ์šฐ๋ฆฐ ๋งˆ์ง€๋ง‰์— LaneNet ๋ชจ๋ธ์ด ์•„๋‹ˆ๋ผ DeepLabv3+ ๋ชจ๋ธ๋กœ ํ›ˆ๋ จ์‹œ์ผฐ๊ธฐ ๋•Œ๋ฌธ์— ํ…Œ์ŠคํŠธ๋„ DeepLabv3+ ๋ชจ๋ธ ํƒ€์ž…์œผ๋กœ ๋ฐ”๊ฟ”์„œ ์‹คํ–‰์‹œ์ผœ์•ผ ํ•จ.

python test.py --img ./data/tusimple_test_image/0.jpg --model_type DeepLabv3+

๊ทผ๋ฐ ํ…Œ์ŠคํŠธํ•˜๋Š”๋ฐ 10s๋‚˜ ๊ฑธ๋ฆผ.. ํ…Œ์ŠคํŠธ ๊ฒฐ๊ณผ๋Š” test_output ํด๋”์— ์ €์žฅ๋จ. ํ™•์ธํ•ด๋ณด๋ฉด 

์ˆœ์„œ : input, instance_output, binary_output

๋‹ค๋ฅธ ์‚ฌ์ง„ ๋Œ๋ ค๋ณด๋‹ˆ 4s ๋‚˜์˜ค๊ธดํ•จ.

์ด๋ฒˆ์—๋Š” ์ข€ ํœ˜์–ด์ง€๋Š” ๋„๋กœ ์ฐจ์„ ์œผ๋กœ ํ…Œ์ŠคํŠธํ•ด๋ด„. ๋˜ 4s ๊ฑธ๋ฆผ.

์ด๋ฒˆ์—” ๋”ฐ๋กœ ๋‹ค์šด๋กœ๋“œ ๋ฐ›์€ TUSimple ๋ฐ์ดํ„ฐ์…‹์˜ test_set์—์„œ ์ฐจ์„ ์— ๊ทธ๋ฆผ์ž๊ฐ€ ๋“œ๋ฆฌ์šด ์‚ฌ์ง„์œผ๋กœ ํ…Œ์ŠคํŠธํ•ด๋ด„. ์ƒ๊ฐ๋ณด๋‹ค ์•„์ฃผ ์ž˜ํ•จ. ์˜ค๋ฅธ์ชฝ์œผ๋กœ ๊ฐˆ๋ผ์ง€๋Š” ์ฐจ์„ ๊นŒ์ง€ ์ž˜ ํ‘œํ˜„๋œ ๋“ฏ.

ํ…Œ์ŠคํŠธ ๋ช‡ ๊ฐœ ๋” ํ•ด๋ด„. ์•ž ์ฐจ์— ์˜ํ•ด ๋„๋กœ๊ฐ€ ๊ฐ€๋ ค์ง€๋Š” ๊ฒฝ์šฐ์—๋„ ๋„๋กœ๋ฅผ ์ž˜ ๊ฒ€์ถœํ•จ.

์ผ๋‹จ ์‹ค์‹œ๊ฐ„์œผ๋กœ ์ฐจ์„  ๊ฒ€์ถœ์„ ํ•ด์•ผํ•˜๋Š”๋ฐ 4s๋‚˜ ๊ฑธ๋ฆฌ๋Š” ๊ฒŒ ๋ฌธ์ œ์ž„. ๋ผ์ฆˆ๋ฒ ๋ฆฌํŒŒ์ด๋กœ ๋Œ๋ฆฌ๋ฉด ๋” ์˜ค๋ž˜ ๊ฑธ๋ฆฐ๋‹ค ํ•จ.. PNG ํŒŒ์ผ ์•ˆ๋จ. ์„ธ๋กœ ์˜์ƒ์ธ ๊ฒฝ์šฐ ์ด๋ฏธ์ง€๊ฐ€ ์ฐŒ๋ถ€๋จ.

'๊ธฐํƒ€' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

20240514  (0) 2024.05.14
์กฐ์•„  (1) 2024.05.14
20240508  (0) 2024.05.08
ํ‹ฐ์Šคํ† ๋ฆฌ ๋ฐฑ์ฟผํŠธ(Tstroy back quote) ์ˆ˜์ •ํ•˜๊ธฐ  (0) 2021.01.07