This project focuses on training YOLOv8 on a Falling Dataset with the goal of enabling real-time fall detection. It constitutes a comprehensive initiative aimed at harnessing the capabilities of YOLOv8, a cutting-edge object detection model, to enhance the efficiency of fall detection in real-time scenarios.
To install YOLOv8, please follow this link, which contains comprehensive documentation that will be beneficial to you: https://docs.ultralytics.com/
In this project, I used the Roboflow dataset :https://universe.roboflow.com/hero-d6kgf/yolov5-fall-detection
-To understand well the training process follow this link :https://docs.ultralytics.com/modes/train/#why-choose-ultralytics-yolo-for-training -To customize YOLOv8 for the fall dataset, run the following command :
from ultralytics import YOLO
# Load the model.
model = YOLO('yolov8n.pt')
# Training.
results = model.train(
data=r"D:\ALL DATASET\Fall_Dataset\data.yaml",
imgsz=640,
epochs=100,
batch=8,)
To find the weight(pre-trained model) after training YOLOv8 on a Fall dataset, use the best.pt file, which is automatically stored in the runs/detect/train/weights directory.
from ultralytics import YOLO
model = YOLO(r'D:\My-Pretrain\f-e-100.pt') # f-e-100.pt it is the weight (best.pt I change to f-e-100)
from IPython.display import Image
# Display the image
Image(filename=r'C:\Users\user\YOLOhuit-FALL-detection\runs\detect\train3\labels_correlogram.jpg', width=600)
from IPython.display import Image
# Display the image
Image(filename=r'C:\Users\user\YOLOhuit-FALL-detection\runs\detect\train3\labels.jpg', width=600)
from IPython.display import Image
# Display the image
Image(filename=r'C:\Users\user\YOLOhuit-FALL-detection\runs\detect\train3\results.png', width=600)
from IPython.display import Image
# Display the image
Image(filename=r'C:\Users\user\YOLOhuit-FALL-detection\runs\detect\val5\confusion_matrix_normalized.png', width=600)
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
image_paths = [
r'C:\Users\user\YOLOhuit-FALL-detection\runs\detect\val5\F1_curve.png',
r'C:\Users\user\YOLOhuit-FALL-detection\runs\detect\val5\P_curve.png',
r'C:\Users\user\YOLOhuit-FALL-detection\runs\detect\val5\PR_curve.png',
r'C:\Users\user\YOLOhuit-FALL-detection\runs\detect\val5\R_curve.png'
]
fig, axs = plt.subplots(2, 2, figsize=(15, 15))
for i, ax in enumerate(axs.flatten()):
img = mpimg.imread(image_paths[i])
ax.imshow(img)
ax.axis('off')
plt.tight_layout()
plt.show()
# Prediction fall detection
from PIL import Image
# from PIL
im1 = Image.open(r"C:\deep\c8.jpg")
results = model.predict(source=im1, save=True)
display(Image.open('runs/detect/predict5/c8.jpg'))
im1 = Image.open(r"C:\deep\c12.jpg")
results = model.predict(source=im1, save=True)
display(Image.open('runs/detect/predict5/c12.jpg'))
im1 = Image.open(r"C:\deep\f7.jpg")
results = model.predict(source=im1, save=True)
display(Image.open('runs/detect/predict5/f7.jpg'))