Welcome to ROSMASTER A1 repository
9.Dataset annotation
Dataset annotation
Dataset annotation1. Dataset collection1.1. Extract images1.2. Dataset path2. Label Studio Usage2.1. Label Studio Installation2.2. Launch Label Studio2.2.1. Shared folder permissions2.2.2. Start Label Studio2.2.3. Access Label StudioHostSame LANFirst time use3. Dataset labeling3.1. Create a project3.2. Project name3.3. Import training set3.4, Label setting3.5. Dataset annotation3.6. Export dataset3.7. Dataset directory framework3.8. Dataset configuration fileReferences
To identify specific objects or improve the accuracy of object recognition, users need to train the model themselves, and the collection and annotation of data sets are an indispensable part.
1. Dataset collection
Description: For recognition in specific situations, users can use a camera to record videos of objects from various angles, and then capture pictures from the video as training sets
1.1. Extract images
Provide a simple example: extract a frame of image from the video every 15 frames as a data set
ximport cv2import os# Path to the input video filevideo_file = '/home/jetson/ultralytics/ultralytics/data/yahboom_data/orange_video/orange.mkv'# Path to the output folder to save the framesoutput_folder = '/home/jetson/ultralytics/ultralytics/data/yahboom_data/orange_pic'# Check if the output folder exists, if not, create itif not os.path.exists(output_folder):os.makedirs(output_folder)# Open the video file using OpenCVcap = cv2.VideoCapture(video_file)# Get the total number of frames in the videototal_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))# Get the frames per second (fps) of the videofps = cap.get(cv2.CAP_PROP_FPS)# Frame counter to keep track of the current frame numberframe_number = 0# Define the interval for extracting frames (every 15th frame)frame_interval = 15# Initialize a new counter for saved frames (starting from 1)saved_frame_number = 1while True:ret, frame = cap.read()# If the frame is not successfully read, exit the loopif not ret:break# Save every 15th frameif frame_number % frame_interval == 0:# Format the frame number starting from 1 (e.g., 1.png, 2.png)image_name = f'{saved_frame_number}.png'image_path = os.path.join(output_folder, image_name)# Save the current frame as a PNG imagecv2.imwrite(image_path, frame)print(f'Saving frame {frame_number}/{total_frames} as {image_name}')# Increment the saved frame countersaved_frame_number += 1# Increment the frame counter for the videoframe_number += 1# Release the video capture objectcap.release()# Print message when processing is completeprint("Video processing complete! Every 15th frame saved as an image!")
1.2. Dataset path
Sample Video:/home/jetson/ultralytics/ultralytics/data/yahboom_data/orange_video
Sample image:/home/jetson/ultralytics/ultralytics/data/yahboom_data/orange_pic
2. Label Studio Usage
Label Studio is an open source data annotation platform used for data annotation and annotation task management, supporting various types of data input and annotation formats.
2.1. Label Studio Installation
xxxxxxxxxxdocker pull heartexlabs/label-studio:latest

2.2. Launch Label Studio
2.2.1. Shared folder permissions
Share the prepared dataset to the folder corresponding to Label Studio:
xxxxxxxxxxsudo chmod 777 /home/jetson/ultralytics/ultralytics/data/
2.2.2. Start Label Studio
xxxxxxxxxxsudo docker run -it -p 8080:8080 -v /home/jetson/ultralytics/ultralytics/data:/label-studio/data heartexlabs/label-studio:latest label-studio --log-level DEBUG

2.2.3. Access Label Studio
Host
Access method for Jetson Orin series development board. You need to enter your username and password for the first time.
xxxxxxxxxxhttp://localhost:8080/

Same LAN
Devices in the same LAN can be accessed based on the motherboard IP:8080
xxxxxxxxxxhttp://motherboard IP:8080/ # For example: http://192.168.2.114:8080/

First time use
For the first time use, you need to register and log in to your account, and the account information is set by factory settings (the account information is false):
xxxxxxxxxxAccount: yahboom@163.comPassword: yahboom@163.com


After registration is completed, the website will automatically log in:

3. Dataset labeling
The demonstration dataset is on the main board, so access Label Studio on the main board.
3.1. Create a project

3.2. Project name
You can name the project as you like, based on your own training set:

3.3. Import training set
Manually import the prepared dataset: Do not import too many images at a time. It is recommended to select 50-100 images each time and then import them multiple times.

3.4, Label setting
We are demonstrating the recognition of oranges, so select "Object Detection"

To delete a built-in tag:

Add new tags:

3.5. Dataset annotation
Click to annotate all tasks:
Labeling steps: first click the label "Orange" and then use the mouse to select the corresponding orange in the picture. After completion, click Submit to enter the next labeling

If the selected object is not the finished orange, you can click on the selected box to readjust the positions of the edges:

3.6. Export dataset
Select YOLO format for export, and the browser will automatically download a compressed package


3.7. Dataset directory framework
Directory framework corresponding to the compressed package exported using Label Studio:
xxxxxxxxxx.├── images├── labels├── classes.txt└── notes.json
We need to export images and labels from Label Studio into train (training set) and val (validation set), with a ratio of about 8:2: the images and labels in train and val need to have one-to-one correspondence in name.
xxxxxxxxxx.├── classes.txt├── notes.json├── train│ ├── images│ └── labels└── val├── images└── labels
3.8. Dataset configuration file
Contains the paths of the training set and validation set, as well as the number and names of categories.
xxxxxxxxxxpath: /home/jetson/ultralytics/ultralytics/data/yahboom_data/orange_datatrain: train/imagesval: val/imagesnc: 1# Classesnames:0: Orange
