This reporsitory is a simple example of YOLO real-time object detection.
It provides a basic Python program to capture video from camera and detect objects in real-time.
To run this reporsitory, you need to follow the steps one by one.
As for the environment, I suggest using python>=3.8. (I use python=3.12)
git clone https://github.com/SiriusAhu/YOLO_Real_Time_Objection_Detection_Simple_ExampleIf you're using Anaconda, you can create a virtual environment by:
conda create -n <env_name> python=3.12Here,
<env_name>is the name of your virtual environment. e.g.conda create -n yolo python=3.12
conda activate <env_name>You can choose to install the packages in two ways:
CPUorGPUversion.
UltraLytics provides a fantastic module called ultralytics, which contains almost all the required packages for using yolo.
So you can just install ultralytics by:
pip install ultralyticsUnfortunately, by testing, I found that ultralytics sometimes doesn't download GPU version of torch, torchaudio and torchvision correctly.
Instead you need to install them manually.
Follow the INSTALL PYTORCH part in the PyTorch official website to install torch, torchaudio and torchvision first.
The command is like this (but don't just copy and paste it, you need to check the website for the correct command):
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118You can use this command to check the installation:
pip freezeYou can check if
torch,torchaudio,torchvisionandultralyticsare GPU versions by checking whether they containcuXXXin their names.
Then for further check if you install torch correctly, you can run the following code in Python:
import torch
print(torch.cuda.is_available())If it returns True, then you have installed torch correctly.
Just execute run.py with python (in your virtual environment)
python run.pyNote: Click Q to quit the program.
Currently, only few arguments are provided:
-mor--model: Model to use. Enter8nfor YOLOv8n,5sfor YOLOv5s. (default:8n)-vor--verbose: Set toTruefor verbose output formodel.predict(). (default:False)-dor--device: Device to use.0for CPU,1for GPU. (default:0)-cor--camera: Camera to use.0for the first camera. Index is based on your system's camera index. Try to change this value if you meet errors. (default:0)