Managing empty spaces efficiently is a common challenge in parking lots, retail shelves, and warehouses. This project demonstrates how to use YOLOv8 on Jetson Nano to detect and count empty spaces in real-time, providing a cost-effective and efficient solution powered by edge AI.
In my previous blogs, "Get Started With Jetson Nano Developer Kit:https://www.hackster.io/pattshibang/get-started-with-jetson-nano-developer-kit-281c38" and "Running YOLOv12 on Jetson Nano 4GB: A Comprehensive Guide:https://www.hackster.io/pattshibang/running-yolov12-on-jetson-nano-4gb-a-comprehensive-guide-f9042e, " we explored the basics of setting up the Jetson Nano and running the YOLOv12 model for object detection. Additionally, in "Fall Detection on Jetson Nano: Customizing YOLOv8:https://www.hackster.io/pattshibang/fall-detection-on-jetson-nano-customizing-yolov8-f10879, " we delved into customizing YOLOv8 for a specific use case. Building on that foundation, we will now explore Real-Time Empty Space Detection & Counting with YOLOv8.
YOLOv8 (You Only Look Once, Version 8) https://docs.ultralytics.com/models/yolov8/. Is a state-of-the-art object detection model known for its speed and accuracy. Its ability to quickly and accurately identify objects in real-time makes it an ideal choice for empty space detection applications. By customizing YOLOv8, we can train the model to specifically recognize Empty Space, enhancing its effectiveness.
The Jetson Nano, a powerful yet affordable edge AI platform developed by NVIDIA, is an excellent choice for deploying YOLOv8-based empty space detection systems. Its compact size, low power consumption, and robust GPU capabilities make it well-suited for running complex AI models at the edge.
2.Hardware ConfigurationIn this tutorial we used Roboflow dataset https://universe.roboflow.com/test-shyto/available_storage as shows in the figure.
Download the dataset with your desire format as shows on this figure.
The dataset is well-organized and includes images annotated in JSON format, divided into three categories: train (494 images), test(74 images), and valid(140 images). It features three classes (available_1, available_2, available_3). The YAML file and additional text files provide configuration settings and instructions to facilitate the use of the dataset in machine learning workflows.
5.Training the ModelTo train YOLOv8 or later versions (as YOLOv8 is an Ultralytics product), refer to the Ultralytics documentation (https://docs.ultralytics.com/) for detailed instructions. Customizing YOLOv8 with an Empty Space dataset, as demonstrated in the Real-Time Empty Space Detection & Counting with YOLOv8 tutorial, involves training YOLOv8 on a specific target dataset tailored to your application.
5.1. Configuring the Training Environment:
- Use the provided YAML file to configure the training parameters. This file will include paths to the dataset on your computer, number of classes, and other necessary settings.
- An example YAML configuration might look like this:
train: /path/to/train/images
val: /path/to/valid/images
test:/path/to/valid/images
nc: 3 # Number of classes
names: [available_1, available_2, available_3]
5.2. Train the Model
# Import necessary libraries
from plotly.subplots import make_subplots
import plotly.graph_objs as go
from ultralytics import YOLO
# Load the model.
model = YOLO('yolov8n.pt')
# Training.
results = model.train(
data=r"C:\Users\user\Documents\ALL DATASET\Available-storage-dataset\data.yaml",
imgsz=640,
epochs=50,
batch=8,
name='avst'
)
# Extract training metrics
metrics = results.metrics
# Create a subplot with two subplots (training and validation losses)
fig = make_subplots(rows=1, cols=2, subplot_titles=("Training Loss", "Validation Loss"))
# Add training loss trace
fig.add_trace(go.Scatter(x=list(range(len(metrics['train']['loss']))), y=metrics['train']['loss'], mode='lines', name='Training Loss'))
# Add validation loss trace
fig.add_trace(go.Scatter(x=list(range(len(metrics['val']['loss']))), y=metrics['val']['loss'], mode='lines', name='Validation Loss'))
# Update layout
fig.update_layout(title="Training and Validation Loss Over Epochs",
xaxis_title="Epoch",
yaxis_title="Loss",
showlegend=True)
# Show the plot
fig.show()
5.3. Empty space Architecture
The figure below illustrates the empty space detection architecture. It involves fine-tuning the pretrained YOLOv8 model by freezing certain layers' weights and passing the output through a dense layer for fall motion classification.
5.4.Train the Model
The evaluation results demonstrate a Mean Average Precision (mAP) of 99%, a Precision of 99%, and a Recall of 99%. The figures provide a visualization of our model's performance, illustrating its robustness in detecting falls through training result graphs and a confusion matrix.
The snippet of Python code makes an inference to detect, in real time, whether a space is empty or available.
import cv2
from ultralytics import YOLO
model = YOLO("empty_space.onnx")
cap=cv2.VideoCapture(0)
while cap.isOpened():
success,frame = cap.read()
if success:
results=model(frame)
annotated_frame = results[0].plot()
cv2.imshow("Empty space detection Inference",annotated_frame)
if cv2.waitKey(1) & 0xFF == ord("q"):
break
else:
break
cap.release()
cv2.destroyAllWindows()
The
figure below show the empty space and counting them in real-time
Comments
Please log in or sign up to comment.