작성자 | 장원준 |
일 시 | 2024. 3. 28 (목) 18:00 ~ 21:00 |
장 소 | 복지관 b128-1호 |
참가자 명단 | 임혜진, 이재영, 성창민, 김명원, 장원준 |
사 진 | ![]() |
!pip install ultralytics
from ultralytics import YOLO
import cv2
import os
import urllib
!pip install ultralytics 로 패키지를 불러오고
YOLO 를 불러옵니다.
그 후 필요한 라이브러리들을 가져옵니다.
!unzip "/content/climbing.v1i.yolov8-obb.zip"
https://universe.roboflow.com/climbing-rmbhd/climbing-eeqyl/dataset/1/images
climbing Object Detection Dataset and Pre-Trained Model by climbing
287 open source hold images plus a pre-trained climbing model and API. Created by climbing
universe.roboflow.com
roboflow 에 labeling 이 다 되어있는 데이터를 YOLO v8 버전으로 다운 받고 코랩에 업로드 하여서 압축해제를 해주는 코드를 작성하였다.
!yolo train data=/content/data.yaml epochs=100
colab 에 저장한 data 의 경로를 적어주고 epochs 값을 100으로 지정한 뒤 train 시켜주는 코드입니다.
!yolo detect weights='/content/cliving_hold_yolov8_weight.pt'
모델 가중치(weights)를 지정합니다.
YOLO를 활용해서 비디오에 있는 객체를 세그멘트화 하는 코드입니다.
results = model(source="/content/climbing.mp4", stream=True)
# 결과 이미지를 저장할 디렉토리
output_dir = "/content/output_images/"
# 디렉토리가 존재하지 않으면 생성
import os
os.makedirs(output_dir, exist_ok=True)
for i, r in enumerate(results):
# 현재 프레임의 이미지 가져오기
frame = r.orig_img
# 결과 이미지 저장
image_path = os.path.join(output_dir, f"result_{i}.jpg")
cv2.imwrite(image_path, frame)
YOLO 모델을 사용하여 주어진 비디오 파일에서 객체를 감지하고 결과 이미지를 저장하는 코드입니다. 비디오에서 객체를 감지하고 각 프레임의 결과 이미지를 지정된 디렉토리에 저장하는 코드입니다.
cv2.imshow(results)
결과 값을 opencv 라이브러리를 활용한 코드로 보여줍니다.
!yolo detect weight=/content/runs/detect/train3/weights/best.pt source=/content/climbing.mp4
욜로 라이브러리를 활용해서 가중치값을 저장하는 코드입니다.
실제로 학습을 시키고 결과값을 도출해낸 코드입니다.
cliving YOLOv8.ipynb
Colaboratory notebook
colab.research.google.com
비록 데이터셋을 직접 만들지는 않았지만 학습을 시키기전에 일일이 찾아보면서 라벨링이 되어있는게 얼마나 편한가(?)를 느꼈습니다. 또한 YOLOv5 보다 YOLOv8이 굉장히 더 성능이 좋다는걸 느끼게 되었다..!