2021.03.20.-2021.06.01.
โ
โ
๋ฒ์ฃ ์๋ฐฉ์ ์ํด ์ฌ์ฉํ๊ณ ์๋ CCTV๋ฅผ ๊ด๋ฆฌํ ์ธ๋ ฅ์ด ๋ถ์กฑํ์ฌ ์ด๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํ์ฌ ์ธ๊ณต์ง๋ฅ์ด ํญ๋ ฅํ์๋ฅผ ๊ฐ์งํ ์ ์๋๋ก ์ธ๊ณต์ง๋ฅ์ ๋ชจ๋ธ๋ง ๋ฐ ํ์ต์ํค๊ณ , ์ค์ ํ๊ฒฝ์ ๋ฐ๋ก ์ ์ฉํ ์ ์๋ ์ธ๊ณต์ง๋ฅ ๊ฐ๋ฐํ์๋ค.
โ

์์์ด yolo network๋ก ์ ๋ฌ๋๋ฉด ๋ค์์ ๊ฒฝ๊ณ๋ฐ์ค์ ๊ทธ๋ฆฌ๋ ์ ์ ํตํด์ ๊ฐ์ ์ป์ด ์ด๋ฅผ ๊ฐ์ฒด๋ก ๊ฒ์ถํ๋ค.
โ
YOLO๋ฅผ ํ์ต์ํค๊ธฐ ์ํด ํ์ต๊ณผ ํธ๋ ์ด๋ ๋ฐ์ดํฐ๋ฅผ ์ ์ํ๋ data ํ์ผ, CNN ๋ ์ด์ด์ ๊ตฌ์กฐ๋ฅผ ์ ์ํ๋ cfgํ์ผ, ํ์ต์ํจ ๊ฐ์ค์น ์ ๋ณด๊ฐ ๋ค์ด์๋ weights ํ์ผ ์ธ ๊ฐ์ง๊ฐ ํ์ํ๋ค.
โ
YOLO์์๋ ๊ธฐ๋ณธ์ ์ธ ๊ฐ์ฒด๊ฒ์ถ์ ๋ํ cfgํ์ผ๊ณผ weights ํ์ผ์ ์ ๊ณตํ๋ค.
โ
์ด๋ฅผ ํ์ฉํ ์๋ ์์ง๋ง ์ฐ๋ฆฌ๋ ํ์ง์ด ๋ฎ๊ฑฐ๋ ์ด๋์ด ๊ณจ๋ชฉ์์ ๋ ์ ํํ ๊ฐ์ฒด ์ธ์์ ์ํ๊ธฐ์ ์ด์ ๋ํ ํ์ต ๋ฐ์ดํฐ์ ์ ํตํด ๊ฐ์ฒด ์ธ์์ ํ์ตํ ํ ํญ๋ ฅํ์์ ๋ํ ํ์ต๋ ์งํํ์๋ค.
โ

ํ์ต๋ ์ธ๊ณต์ง๋ฅ์๊ฒ ์์์ ํ์ด์ฃผ๋ฉด YOLO network๊ฐ ์ธ์ํ์ฌ ๋ค์์ ๊ฒฝ๊ณ๋ฐ์ค์ NMS ์ค์ ๊ฒฝ๊ณ ๋ฐ์ค๋ฅผ ํตํด ๊ฐ์ฒด ๊ฒ์ถ๊ณผ ํญ๋ ฅ์ธ์์ ํ๊ฑฐ๋ ํด๋์ค๋ฅผ ํํํ 7X7 ๊ทธ๋ฆฌ๋ ์ ์ ํตํด ๊ฐ์ฒด ๊ฒ์ถ ๋ฐ ํญ๋ ฅ์ธ์์ ํ๋ค.
โ
ํญ๋ ฅ๊ณผ ๊ฐ์ฒด๋ ๊ฐ๊ฐ fight์ person์ผ๋ก ์ ํ๋์ ํจ๊ป ์์์ ๋ค๋ชจ ๋ฐ์ค๋ก ๋์์ ํ์ธ์ด ๊ฐ๋ฅํ๋ค.
โ
โ
์คํํ๊ฒฝ์ ๋ค์๊ณผ ๊ฐ๋ค.
โ
Windows 10
OpenCV
Visual Studio
Cuda 10.1
NVIDIA GeForce GTX 660
โ
โ
โ
Yolo v3๋ฅผ ์ด์ฉํด ํ์ต์ํค๊ธฐ ์ ์ธํ ํด์ผํ ๋ถ๋ถ์ด ์๋ค.
โ

classes : ๋ฐ์ดํฐ ์ข ๋ฅ์ ์, fight์ person 2๊ฐ๋ก ์ค์
max_batches : 4000 x classes์ ๊ฐ์
steps : ์์์ ์ค์ ํ max_batches ์ฌ์ด์ฆ์ 80%์ 90%๋ฅผ ์ค์
โ
โ
Yolo-mark ๋ฅผ ์ด์ฉํ์ฌ ๋ผ๋ฒจ๋ง์ ์ํํ๋ค.

yolo – mark๋ฅผ ํตํด ์ค๋ด์ธ ์ฌ๋ ๊ฐ์ฒด์ ํญ๋ ฅํ์ ์ฅ๋ฉด์ ๋ผ๋ฒจ๋งํ์ฌ YOLO๊ฐ ํ์ตํ ์ ์๋ data์ธ txtํ์ผ๋ก ๋ง๋ค์ด ์ค๋ค.
โ
์ด์ ๊ฐ์ ๋ฐ์ดํฐ์ ์ ์ค๋ด์ธ ํฉ์ณ 1600์ฅ์ ๋ผ๋ฒจ๋ง ํ์๊ณ ์ด๋ฅผ ํ์ตํ๋ค.
โ

๋ผ๋ฒจ๋ง์ ์ํํ๊ฒ ๋๋ฉด ๋ค์๊ณผ ๊ฐ์ด txt์ ์ซ์๊ฐ ์๋ค.
โ
cmd์์ ์์์ ์ ๋ ฅํ์ฌ ์ถ๋ ฅ๊ฒฐ๊ณผ๋ฅผ ํ์ธํ ์ ์๋ ๋ช ๋ น์ด๋ ๋ค์๊ณผ ๊ฐ๋ค.
>> darknet.exe detector demo data/obj.data testcfg/yolov3-tiny.cfg backup/yolov3-tiny_final.weights -i 0 data\fight\data2.mp4
>> darknet.exe detector demo data/obj.data testcfg/yolov3-tiny.cfg backup/yolov3-tiny_final.weights -i 0 (ํ์ธํ ๋์์ ํ์ผ)
์ถ๊ฐ๋ก ํ์ต์ ์ํ๋ ๊ฒฝ์ฐ๋ ๋ค์๊ณผ ๊ฐ์ด ์ ๋ ฅํ๋ค.
darknet detector train data\obj.data testcfg\yolov3-tiny.cfg backup/yolov3-tiny_final.weights -gpu 0

2000ํ๋ฅผ ํ์ต ํ ํ ๊ฐ์ฒด ๊ฒ์ถ์ ๊ฒฐ๊ณผ๋ ์์ ๊ฐ๋ค.
โ
โ

5000๋ฒ๋์ ์์ค๋ฅ ๊ทธ๋ํ๋ ์์ ๊ฐ๋ค.
โ


์ต์ข ์ ์ผ๋ก person ๊ฐ์ฒด์ fight๋ผ๋ ํญ๋ ฅํ์๋ฅผ ๊ฒ์ถํ ๊ฒฐ๊ณผ๋ ๋ค์๊ณผ ๊ฐ์ ์ถ๋ ฅ์ ๋ณด์ธ๋ค.
โ
์ฒซ๋ฒ์งธ ์ฌ์ง์ ์ค๋ด ํญ๋ ฅํ์ ์์์ ์ ๋ ฅ data๋ก ์ง์ด๋ฃ์ด ๊ฐ์ฒด๋ 34%, 37%์ ์ ํ๋๋ฅผ ๋ณด์ด๊ณ ํญ๋ ฅํ์๋ 55%์ ์ ํ๋๋ฅผ ๋ณด์ด๋ฉฐ ํญ๋ ฅํ์๋ผ๋ ์ถ๋ ฅ์ ํ๋ฉด์์ ๊ทธ๋ ค์ค๋ค.
โ
๋๋ฒ์งธ ์ฌ์ง์ ์ค์ธ ํญ๋ ฅํ์ ์์์ ์ ๋ ฅ data๋ก ์ง์ด๋ฃ์ด ๊ฐ์ฒด๋ฅผ 40%, 53%์ ์ ํ๋๋ก ๊ฒ์ถํ๊ณ ํญ๋ ฅํ์๋ 38%์ ์ ํ๋๋ก ํ์ธํ์ฌ ์ถ๋ ฅ์ผ๋ก ๋ํ๋๋ค.
โ
์น ์บ ์ ํตํ์ฌ ๊ฐ์ฒด ์ธ์์ ํ ๊ฒฝ์ฐ๋ ๋ค์๊ณผ ๊ฐ์ ์์ค์ฝ๋๋ฅผ ์ฌ์ฉํ๋ค.
โ
import cv2
import numpy as np
# ์น์บ ์ ํธ ๋ฐ๊ธฐ
VideoSignal = cv2.VideoCapture(0)
# YOLO ๊ฐ์ค์น ํ์ผ๊ณผ CFG ํ์ผ ๋ก๋
YOLO_net = cv2.dnn.readNet("yolo-obj_16000.weights","yolo-obj.cfg")
# YOLO NETWORK ์ฌ๊ตฌ์ฑ
classes = []
with open("coco.names", "r") as f:
classes = [line.strip() for line in f.readlines()]
layer_names = YOLO_net.getLayerNames()
output_layers = [layer_names[i[0] - 1] for i in YOLO_net.getUnconnectedOutLayers()]
while True:
# ์น์บ ํ๋ ์
ret, frame = VideoSignal.read()
h, w, c = frame.shape
# YOLO ์
๋ ฅ
blob = cv2.dnn.blobFromImage(frame, 0.00392, (416, 416), (0, 0, 0),
True, crop=False)
YOLO_net.setInput(blob)
outs = YOLO_net.forward(output_layers)
class_ids = []
confidences = []
boxes = []
for out in outs:
for detection in out:
scores = detection[5:]
class_id = np.argmax(scores)
confidence = scores[class_id]
if confidence > 0.5:
# Object detected
center_x = int(detection[0] * w)
center_y = int(detection[1] * h)
dw = int(detection[2] * w)
dh = int(detection[3] * h)
# Rectangle coordinate
x = int(center_x - dw / 2)
y = int(center_y - dh / 2)
boxes.append([x, y, dw, dh])
confidences.append(float(confidence))
class_ids.append(class_id)
indexes = cv2.dnn.NMSBoxes(boxes, confidences, 0.45, 0.4)
for i in range(len(boxes)):
if i in indexes:
x, y, w, h = boxes[i]
label = str(classes[class_ids[i]])
score = confidences[i]
# ๊ฒฝ๊ณ์์์ ํด๋์ค ์ ๋ณด ์ด๋ฏธ์ง์ ์
๋ ฅ
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 0, 255), 5)
cv2.putText(frame, label, (x, y - 20), cv2.FONT_ITALIC, 0.5,
(255, 255, 255), 1)
cv2.imshow("YOLOv3", frame)
if cv2.waitKey(100) > 0:
break
โ
โ
โ
[1] https://www.index.go.kr/potal/main/EachDtlPageDetail.do?idx_cd=2855
[2] CCTV ํตํฉ๊ด์ ์ผํฐ ์ด์์คํ ๋ฐ ๊ฐ์ ๋ฐฉ์, p32
[3] Girshick, R., Donahue, J., Darrell, T. and Malik, J., Rich feature hierarchies for accurate object detection and semantic segmentation. CVPR, pp.580-587, 2014.
[4] Girshick, R. Fast r-cnn, ICCV, pp.1440-1448, 2015.
[5] Ren, S., He, K., Girshick, R., & Sun, J., Faster rcnn: Towards real-time object detection with region proposal networks, NIPS, pp.91-99, 2015.
[6] https://jjjhong.tistory.com/25
[8] http://www.dbpia.co.kr/journal/articleDetail?nodeId=NODE06281351
[9] http://daddynkidsmakers.blogspot.com/2020/05/yolo.html
๋ฐ์ดํฐ ์ ๊ณต : https://aihub.or.kr/aidata/139
'ํ๋ก์ ํธ > AI' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| [AI] EfficientNet์ ์ด์ฉํ ์ปดํจํฐ ๋ถ๋ฅ (0) | 2023.01.02 |
|---|---|
| [AI] Yolo v4๋ฅผ ์ด์ฉํ ๊ฐ์์ง ์ธ์ ์ธ๊ณต์ง๋ฅ (0) | 2023.01.02 |