Run YOLOv12 on Linux / Ubuntu: Step-by-Step Installation Guide
The You Only Look Once (YOLO) framework represents a seminal advancement in real-time object detection, widely implemented across domains such as autonomous navigation, surveillance, and robotics.
The latest iteration, YOLOv12, significantly improves computational efficiency and detection accuracy. This article presents a rigorous, stepwise approach to configuring and deploying YOLOv12 on Linux and Ubuntu systems.
System Prerequisites
Prior to installation, ensure that your system satisfies the following requirements:
- NVIDIA GPU (Optional): To leverage hardware acceleration, install the appropriate NVIDIA driver and CUDA (11.8 or later).
- Git: Install Git if it is not already present:
sudo apt install git
- Python 3.11 or Later: Verify installation using:
python3 --version
Installation Procedure
1. System Preparation
Execute the following commands to install necessary system dependencies:
Install NVIDIA GPU Driver and CUDA (Optional): Refer to the NVIDIA Developer Portal for platform-specific instructions.
Install Git:
sudo apt install git
Install Python 3.11 or Later:
sudo apt update
sudo apt install python3.11
2. Repository Acquisition
Clone the official YOLOv12 repository from GitHub:
git clone https://github.com/sunsmarterjie/yolov12.git
cd yolov12
3. Establishing a Virtual Environment
Isolating dependencies within a virtual environment prevents conflicts and enhances reproducibility.
Using venv:
python3.11 -m venv yolov12-env
source yolov12-env/bin/activate
Using Conda:
conda create -n yolov12 python=3.11
conda activate yolov12
4. Dependency Installation
Install all requisite dependencies, including PyTorch and FlashAttention:
wget https://github.com/Dao-AILab/flash-attention/releases/download/v2.7.3/flash_attn-2.7.3+cu11torch2.2cxx11abiFALSE-cp311-cp311-linux_x86_64.whl
pip install flash_attn-2.7.3+cu11torch2.2cxx11abiFALSE-cp311-cp311-linux_x86_64.whl
pip install -r requirements.txt
pip install -e .
5. Validation of Installation
Confirm the integrity of the installation with:
python -c "from ultralytics import YOLO; print('YOLOv12 installed successfully')"
Executing YOLOv12
Once configured, YOLOv12 can be deployed for object detection tasks.
Sample Implementation
The following Python script demonstrates inference on an image:
from ultralytics import YOLO
# Load the trained model
model = YOLO("path/to/model.pt") # Utilize a pre-trained model
# Perform inference
results = model("path/to/image.jpg")
# Post-process results
for result in results:
boxes = result.boxes # Bounding boxes
probs = result.probs # Confidence scores
# result.show() # Visualize output
result.save("output.jpg") # Store processed image
Troubleshooting Strategies
- Dependency Conflicts: Ensure the virtual environment is active and dependencies are properly installed.
- CUDA/Driver Issues: If utilizing a GPU, validate that the NVIDIA driver and CUDA toolkit are correctly installed.
Optimization Recommendations
- Hardware Acceleration: Utilize a GPU to enhance inference speed.
- Custom Dataset Training: Refer to the official documentation for guidelines on fine-tuning YOLOv12 on bespoke datasets.
Future Enhancements
Given the iterative progression of YOLO models, subsequent versions are anticipated to offer superior efficiency and feature enhancements. Maintaining an updated computational environment, including Python and CUDA, ensures continued compatibility and optimal performance.
Appendices
Appendix A: Essential Commands
Command | Functionality |
---|---|
git clone https://github.com/sunsmarterjie/yolov12.git |
Clone the YOLOv12 repository |
conda create -n yolov12 python=3.11 |
Generate a dedicated Conda environment |
pip install -r requirements.txt |
Install project dependencies |
python -c "from ultralytics import YOLO; print('YOLOv12 installed successfully')" |
Verify installation |
Appendix B: Troubleshooting Checklist
- Python Compatibility: Confirm installation of Python 3.11 or newer.
- Git Availability: Verify Git installation.
- CUDA Configuration: Ensure correct setup of NVIDIA drivers and CUDA toolkit.
- Dependency Issues: Activate the virtual environment and reinstall dependencies if discrepancies arise.
Final Considerations
YOLOv12 embodies state-of-the-art advancements in real-time object detection. By adhering to the procedural framework outlined in this guide, researchers and developers can efficiently establish and utilize YOLOv12 within Linux and Ubuntu environments, facilitating its deployment in diverse real-world applications.
Conclusion
Deploying YOLOv12 on Linux and Ubuntu involves methodical steps, including configuring the environment, acquiring the repository, setting up a virtual environment, installing dependencies, and performing verification.