Annotating a YOLOv8 Dataset Using Label Studio
About 856 wordsAbout 3 min...
Abstract
This article will explain how to annotate a YOLOv8 dataset using Label Studio, as well as how to extract image frames from video files using Python.
Download/Install
pip install label-studio opencv-python
Extracting Frames from Video Files
import cv2
def main(source: str, s: int = 60) -> None:
"""
:param source: Video Files
:param s: Frame extraction interval, defaulting to saving one frame every 60 frames
:return:
"""
video = cv2.VideoCapture(source)
frame_num = 0
success, frame = video.read()
while success:
if frame_num % s == 0:
cv2.imwrite(f"./images/{frame_num // s}.png", frame)
success, frame = video.read()
frame_num += 1
video.release()
cv2.destroyAllWindows()
if __name__ == '__main__':
main('./videos/sample.mp4')
Image Annotation
label-studio start
Export Dataset
.
│ classes.txt
│ notes.json
│
├─images
│ a4d2cef8-hutao_bg.jpg
│
└─labels
a4d2cef8-hutao_bg.txt
Note: The filenames in the images
and labels
subfolders must correspond exactly to each other.
.
│ classes.txt
│ notes.json
│
├─images
│ ├─test
│ │ a4d2cef8-hutao_bg.jpg
│ │
│ ├─train
│ │ a4d2cef8-hutao_bg.jpg
│ │
│ └─val
│ a4d2cef8-hutao_bg.jpg
│
└─labels
├─test
│ a4d2cef8-hutao_bg.txt
│
├─train
│ a4d2cef8-hutao_bg.txt
│
└─val
a4d2cef8-hutao_bg.txt
Note: In the data.yaml
file, nc
represents the total number of label categories in the dataset, and names
refers to the names of these labels. This information can be found in the classes.txt
file.
File contents
# dataset path
train: ./images/train
val: ./images/val
test: ./images/test
# number of classes
nc: 3
# class names
names: [
"bag",
"hutao",
"other person",
]
Directory structure
.
│ classes.txt
│ data.yaml
│ notes.json
│
├─images
│ ├─test
│ │ a4d2cef8-hutao_bg.jpg
│ │
│ ├─train
│ │ a4d2cef8-hutao_bg.jpg
│ │
│ └─val
│ a4d2cef8-hutao_bg.jpg
│
└─labels
├─test
│ a4d2cef8-hutao_bg.txt
│
├─train
│ a4d2cef8-hutao_bg.txt
│
└─val
a4d2cef8-hutao_bg.txt
With this, a custom dataset suitable for YOLOv8 has been successfully created. In our next issue, we will explain how to train a custom dataset using YOLOv8(Training/inference on a custom dataset in Label Studio using YOLOv8)。.
Powered by Waline v3.3.0