### Install Required Libraries Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-Action-Recognition/readme.md Clone the ultralytics repository, navigate to the action recognition example directory, and install the necessary dependencies. ```bash git clone https://github.com/ultralytics/ultralytics cd examples/YOLOv8-Action-Recognition pip install -U -r requirements.txt ``` -------------------------------- ### Install Libraries and Navigate to Directory Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-SAHI-Inference-Video/readme.md Clone the ultralytics repository, install the required Python packages (sahi and ultralytics), and change the directory to the specific example folder for subsequent commands. ```bash git clone https://github.com/ultralytics/ultralytics pip install -U sahi ultralytics cd ultralytics/examples/YOLOv8-SAHI-Inference-Video ``` -------------------------------- ### Install YOLOv12 and Dependencies Source: https://github.com/sunsmarterjie/yolov12/blob/main/README.md Use conda to create an environment and install necessary packages including supervision and flash-attn. Then activate the environment, clone the repository, and install the project and its requirements. ```bash conda create -n yolov12 python=3.11 supervision flash-attn conda activate yolov12 git clone https://github.com/sunsmarterjie/yolov12 && cd yolov12 pip install -r requirements.txt pip install -e . ``` -------------------------------- ### Install Ultralytics from Source Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/tutorial.ipynb Installs the 'ultralytics' library directly from its main branch on GitHub using pip. This is useful for getting the latest development version. ```bash # Pip install from source !pip install git+https://github.com/ultralytics/ultralytics@main ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/RTDETR-ONNXRuntime-Python/README.md Installs all necessary Python packages listed in the requirements.txt file. Ensure you have Python and pip installed. ```bash pip install -r requirements.txt ``` -------------------------------- ### Install Ultralytics and Run Checks Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/hub.ipynb Installs the ultralytics package and runs system checks. Ensure you have the necessary dependencies and hardware. ```python %pip install ultralytics from ultralytics import YOLO, checks, hub checks() ``` -------------------------------- ### Install Dependencies and Run Inference Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-OpenCV-ONNX-Python/README.md Installs project dependencies from requirements.txt and runs the main inference script with a specified ONNX model and image. Ensure you have the necessary model file (e.g., yolov8n.onnx) and an image file (e.g., image.jpg) in the project directory. ```bash pip install -r requirements.txt python main.py --model yolov8n.onnx --img image.jpg ``` -------------------------------- ### Install tflite-runtime Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-TFLite-Python/README.md Install the tflite-runtime package for loading TFLite models. ```bash pip install tflite-runtime ``` -------------------------------- ### Install ONNX Runtime for CPU Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/RTDETR-ONNXRuntime-Python/README.md Installs the CPU-only version of ONNX Runtime. Use this if you do not have an NVIDIA GPU. ```bash pip install onnxruntime ``` -------------------------------- ### Run YOLOv8 Inference with ONNXRuntime (CPU) Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-ONNXRuntime-Rust/README.md Perform inference using a YOLOv8 ONNX model with ONNXRuntime on the CPU. This is the basic command to get started with inference. ```bash cargo run --release -- --model --source ``` -------------------------------- ### Install and Check Ultralytics Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/tutorial.ipynb Install the ultralytics package and run checks to ensure the environment is set up correctly. This is the first step before using any YOLO11 functionalities. ```python %pip install ultralytics import ultralytics ultralytics.checks() ``` -------------------------------- ### Install ONNX Runtime with GPU Support Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/RTDETR-ONNXRuntime-Python/README.md Installs the GPU-accelerated version of ONNX Runtime. Requires an NVIDIA GPU and compatible drivers. ```bash pip install onnxruntime-gpu ``` -------------------------------- ### Clone YOLOv8 OpenVINO C++ Inference Repository Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-OpenVINO-CPP-Inference/README.md Clone the repository and navigate to the example directory. This is the first step to set up the project. ```bash git clone https://github.com/ultralytics/ultralytics.git cd ultralytics/YOLOv8-OpenVINO-CPP-Inference ``` -------------------------------- ### Quick Start Action Recognition Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-Action-Recognition/readme.md Run the action recognition script with default settings for a quick inference test. ```python python action_recognition.py ``` -------------------------------- ### Install Required Packages Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-Segmentation-ONNXRuntime-Python/README.md Install the necessary Python packages for YOLOv8 segmentation with ONNX Runtime. Use `onnxruntime-gpu` for GPU acceleration or `onnxruntime` for CPU. ```bash pip install ultralytics pip install onnxruntime-gpu # For GPU support # pip install onnxruntime # Use this instead if you don't have an NVIDIA GPU pip install numpy pip install opencv-python ``` -------------------------------- ### Clone and Build YOLOv8 C++ Inference Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-LibTorch-CPP-Inference/README.md Clone the ultralytics repository, install Python dependencies, navigate to the C++ inference example, and build the project using CMake and Make. ```bash git clone ultralytics cd ultralytics pip install . cd examples/YOLOv8-LibTorch-CPP-Inference mkdir build cd build cmake .. make ./yolov8_libtorch_inference ``` -------------------------------- ### CMake Project Setup Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-CPP-Inference/CMakeLists.txt Basic CMake configuration for a C++ project. Sets the minimum required version and project details. ```cmake cmake_minimum_required(VERSION 3.5) project(Yolov8CPPInference VERSION 0.1) ``` -------------------------------- ### Select YOLO11 Logger (Comet or TensorBoard) Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/tutorial.ipynb This code snippet allows you to select a logger for YOLO11 training, choosing between Comet and TensorBoard. It also handles the necessary installations and setup for the selected logger. ```python #@title Select YOLO11 🚀 logger {run: 'auto'} logger = 'Comet' #@param ['Comet', 'TensorBoard'] if logger == 'Comet': %pip install -q comet_ml import comet_ml; comet_ml.init() elif logger == 'TensorBoard': %load_ext tensorboard %tensorboard --logdir . ``` -------------------------------- ### YOLOv8 Inference Profiling Results Example Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-ONNXRuntime-Rust/README.md Example output showing the time breakdown for each inference stage when using TensorRT FP16 on an RTX 3060Ti. This helps in identifying performance bottlenecks. ```text ==> 0 [Model Preprocess]: 12.75788ms [ORT H2D]: 237.118µs [ORT Inference]: 507.895469ms [ORT D2H]: 191.655µs [Model Inference]: 508.34589ms [Model Postprocess]: 1.061122ms ==> 1 [Model Preprocess]: 13.658655ms [ORT H2D]: 209.975µs [ORT Inference]: 5.12372ms [ORT D2H]: 182.389µs [Model Inference]: 5.530022ms [Model Postprocess]: 1.04851ms ==> 2 [Model Preprocess]: 12.475332ms [ORT H2D]: 246.127µs [ORT Inference]: 5.048432ms [ORT D2H]: 187.117µs [Model Inference]: 5.493119ms [Model Postprocess]: 1.040906ms ``` -------------------------------- ### Install tensorflow-gpu for NVIDIA GPU Users Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-TFLite-Python/README.md Install tensorflow-gpu to leverage GPU acceleration with NVIDIA GPUs. Ensure compatible GPU drivers are installed. ```bash pip install tensorflow-gpu ``` -------------------------------- ### Run YOLOv5 Segmentation Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLO-Series-ONNXRuntime-Rust/README.md Example command to run a YOLOv5 segmentation task with specified scale. ```shell cargo run -r -- --task segment --ver v5 --scale n # YOLOv5-Segment ``` -------------------------------- ### Combined Action Recognition Options Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-Action-Recognition/readme.md Example demonstrating the combination of multiple command-line options for advanced configuration, including source, device, video classifier model, custom labels, and FP16 inference. ```python python action_recognition.py --source "https://www.youtube.com/watch?v=dQw4w9WgXcQ" --device 0 --video-classifier-model "microsoft/xclip-base-patch32" --labels "dancing" "singing a song" --fp16 ``` -------------------------------- ### Install tensorflow for CPU Version Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-TFLite-Python/README.md Install the CPU version of TensorFlow for CPU usage or non-NVIDIA GPUs. ```bash pip install tensorflow ``` -------------------------------- ### Run YOLOv10 Detection Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLO-Series-ONNXRuntime-Rust/README.md Example command to run a YOLOv10 detection task with specified scale. ```shell cargo run -r -- --task detect --ver v10 --scale n # YOLOv10 ``` -------------------------------- ### Run YOLOv5 Detection Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLO-Series-ONNXRuntime-Rust/README.md Example command to run a YOLOv5 detection task with specified scale. ```shell cargo run -r -- --task detect --ver v5 --scale n # YOLOv5 ``` -------------------------------- ### Run YOLOv8 Segmentation Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLO-Series-ONNXRuntime-Rust/README.md Example command to run a YOLOv8 segmentation task with specified scale. ```shell cargo run -r -- --task segment --ver v8 --scale n # YOLOv8-Segment ``` -------------------------------- ### Run YOLOv11 Detection Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLO-Series-ONNXRuntime-Rust/README.md Example command to run a YOLOv11 detection task with specified scale. ```shell cargo run -r -- --task detect --ver v11 --scale n # YOLO11 ``` -------------------------------- ### Build and Run YOLOv8 C++ Inference Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-CPP-Inference/README.md Steps to clone the repository, install dependencies, build the C++ project, and run inference. Ensure ONNX models are placed correctly and adjust paths as needed. ```bash git clone ultralytics cd ultralytics pip install . cd examples/YOLOv8-CPP-Inference # Add a **yolov8\_.onnx** and/or **yolov5\_.onnx** model(s) to the ultralytics folder. # Edit the **main.cpp** to change the **projectBasePath** to match your user. # Note that by default the CMake file will try to import the CUDA library to be used with the OpenCVs dnn (cuDNN) GPU Inference. # If your OpenCV build does not use CUDA/cuDNN you can remove that import call and run the example on CPU. mkdir build cd build cmake .. make ./Yolov8CPPInference ``` -------------------------------- ### Clone Ultralytics Repo and Install Editable Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/tutorial.ipynb Clones the 'ultralytics' repository from GitHub to the 'main' branch and then installs it in editable mode using pip. This is useful for development. ```bash # Git clone and run tests on updates branch !git clone https://github.com/ultralytics/ultralytics -b main %pip install -qe ultralytics ``` -------------------------------- ### Run YOLOv8 Oriented Bounding Box (OBB) Detection Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLO-Series-ONNXRuntime-Rust/README.md Example command to run YOLOv8 OBB detection with specified dimensions and source image. ```shell cargo run -r -- --ver v8 --task obb --scale n --width 1024 --height 1024 --source images/dota.png # YOLOv8-Obb ``` -------------------------------- ### Run YOLOv6 Detection Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLO-Series-ONNXRuntime-Rust/README.md Example command to run a YOLOv6 detection task with specified scale. ```shell cargo run -r -- --task detect --ver v6 --scale n # YOLOv6 ``` -------------------------------- ### Run YOLOv8 Detection Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLO-Series-ONNXRuntime-Rust/README.md Example command to run a YOLOv8 detection task with specified scale. ```shell cargo run -r -- --task detect --ver v8 --scale n # YOLOv8 ``` -------------------------------- ### Run YOLO11 Segmentation Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLO-Series-ONNXRuntime-Rust/README.md Example command to run a YOLO11 segmentation task with specified scale. ```shell cargo run -r -- --task segment --ver v11 --scale n # YOLO8-Segment ``` -------------------------------- ### Run YOLOv7 Detection Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLO-Series-ONNXRuntime-Rust/README.md Example command to run a YOLOv7 detection task with specified scale. ```shell cargo run -r -- --task detect --ver v7 --scale t # YOLOv7 ``` -------------------------------- ### Run YOLOv8 Pose Estimation Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLO-Series-ONNXRuntime-Rust/README.md Example command to run a YOLOv8 pose estimation task with specified scale. ```shell cargo run -r -- --task pose --ver v8 --scale n # YOLOv8-Pose ``` -------------------------------- ### Run YOLOv9 Detection Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLO-Series-ONNXRuntime-Rust/README.md Example command to run a YOLOv9 detection task with specified scale. ```shell cargo run -r -- --task detect --ver v9 --scale t # YOLOv9 ``` -------------------------------- ### Run YOLO11 Oriented Bounding Box (OBB) Detection Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLO-Series-ONNXRuntime-Rust/README.md Example command to run YOLO11 OBB detection with specified dimensions and source image. ```shell cargo run -r -- --ver v11 --task obb --scale n --width 1024 --height 1024 --source images/dota.png # YOLO11-Obb ``` -------------------------------- ### Run FastSAM Segmentation Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLO-Series-ONNXRuntime-Rust/README.md Example command to run FastSAM segmentation using a specific ONNX model. ```shell cargo run -r -- --task segment --ver v8 --model yolo/FastSAM-s-dyn-f16.onnx # FastSAM ``` -------------------------------- ### Run RTDETR Detection Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLO-Series-ONNXRuntime-Rust/README.md Example command to run an RTDETR detection task with specified scale. ```shell cargo run -r -- --task detect --ver rtdetr --scale l # RTDETR ``` -------------------------------- ### Install YOLOv8 Region Counter Dependencies Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-Region-Counter/readme.md Clone the ultralytics repository and navigate to the YOLOv8-Region-Counter directory to prepare for running the script. ```bash git clone https://github.com/ultralytics/ultralytics cd ultralytics/examples/YOLOv8-Region-Counter ``` -------------------------------- ### Run YOLOv8 Detection with Custom Parameters Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLO-Series-ONNXRuntime-Rust/README.md Example of running a YOLOv8 detection task with custom parameters for model path, number of classes, and version. ```shell cargo run -r -- --task detect --ver v8 --nc 6 --model xxx.onnx # YOLOv8 ``` -------------------------------- ### Run YOLO11 Pose Estimation Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLO-Series-ONNXRuntime-Rust/README.md Example command to run a YOLO11 pose estimation task with specified scale. ```shell cargo run -r -- --task pose --ver v11 --scale n # YOLO11-Pose ``` -------------------------------- ### Run YOLOv5 Classification Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLO-Series-ONNXRuntime-Rust/README.md Example command to run a YOLOv5 classification task with specified scale, width, and height. ```shell cargo run -r -- --task classify --ver v5 --scale s --width 224 --height 224 --nc 1000 # YOLOv5 ``` -------------------------------- ### Find and Configure LibTorch Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-LibTorch-CPP-Inference/CMakeLists.txt Adds the LibTorch installation path to CMAKE_PREFIX_PATH, finds the Torch package, and configures C++ flags and include directories. Prints Torch libraries. ```cmake list(APPEND CMAKE_PREFIX_PATH "/path/to/libtorch") set(Torch_DIR "/path/to/libtorch/share/cmake/Torch") find_package(Torch REQUIRED) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}") message("${TORCH_LIBRARIES}") message("${TORCH_INCLUDE_DIRS}") include_directories(${TORCH_INCLUDE_DIRS}) ``` -------------------------------- ### Run YOLOv8 Classification Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLO-Series-ONNXRuntime-Rust/README.md Example command to run a YOLOv8 classification task with specified scale, width, and height. ```shell cargo run -r -- --task classify --ver v8 --scale n --width 224 --height 224 --nc 1000 # YOLOv8 ``` -------------------------------- ### Run YOLO11 Classification Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLO-Series-ONNXRuntime-Rust/README.md Example command to run a YOLO11 classification task with specified scale, width, and height. ```shell cargo run -r -- --task classify --ver v11 --scale n --width 224 --height 224 --nc 1000 # YOLO11 ``` -------------------------------- ### Train and Predict with YOLO11 OBB Model Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/tutorial.ipynb Loads a pretrained YOLO11 OBB model, trains it on DOTA8 for 3 epochs, and then predicts on a sample image. Ensure 'ultralytics' is installed. ```python # Load YOLO11n-obb, train it on DOTA8 for 3 epochs and predict an image with it from ultralytics import YOLO model = YOLO('yolo11n-obb.pt') # load a pretrained YOLO OBB model model.train(data='dota8.yaml', epochs=3) # train the model model('https://ultralytics.com/images/boats.jpg') # predict on an image ``` -------------------------------- ### OpenCV Configuration Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-CPP-Inference/CMakeLists.txt Integrates OpenCV library for computer vision functionalities. Ensures OpenCV is installed and discoverable. ```cmake # OpenCV find_package(OpenCV REQUIRED) include_directories(${OpenCV_INCLUDE_DIRS}) # !OpenCV ``` -------------------------------- ### CUDA Configuration Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-CPP-Inference/CMakeLists.txt Configures the project to use CUDA for accelerated computation. Requires CUDA Toolkit to be installed. ```cmake # CUDA set(CUDA_TOOLKIT_ROOT_DIR "/usr/local/cuda") find_package(CUDA 11 REQUIRED) set(CMAKE_CUDA_STANDARD 11) set(CMAKE_CUDA_STANDARD_REQUIRED ON) # !CUDA ``` -------------------------------- ### Run YOLOv8 Inference with ONNXRuntime (CUDA) Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-ONNXRuntime-Rust/README.md Accelerate YOLOv8 inference by using the CUDA execution provider. Ensure you have a compatible NVIDIA GPU and CUDA toolkit installed. ```bash cargo run --release -- --cuda --model --source ``` -------------------------------- ### Login to Ultralytics HUB and Train Model Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/hub.ipynb Logs into Ultralytics HUB with an API key, loads a specified YOLO model, and starts the training process. Replace placeholders with your actual API key and model ID. ```python # Log in to HUB using your API key (https://hub.ultralytics.com/settings?tab=api+keys) hub.login("YOUR_API_KEY") # Load your model from HUB (replace 'YOUR_MODEL_ID' with your model ID) model = YOLO("https://hub.ultralytics.com/models/YOUR_MODEL_ID") # Train the model results = model.train() ``` -------------------------------- ### Configure Tracking Parameters (CLI) Source: https://github.com/sunsmarterjie/yolov12/blob/main/ultralytics/trackers/README.md Run object tracking from the command line with specified confidence, IoU, and show parameters. ```bash # Configure tracking parameters and run the tracker using the command line interface yolo track model=yolo11n.pt source="https://youtu.be/LNwODJXcvt4" conf=0.3, iou=0.5 show ``` -------------------------------- ### Train and Predict with YOLO11 Detection Model Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/tutorial.ipynb Loads a pretrained YOLO11 detection model, trains it on COCO128 for 3 epochs, and then predicts on a sample image. Ensure 'ultralytics' is installed. ```python # Load YOLO11n, train it on COCO128 for 3 epochs and predict an image with it from ultralytics import YOLO model = YOLO('yolo11n.pt') # load a pretrained YOLO detection model model.train(data='coco8.yaml', epochs=3) # train the model model('https://ultralytics.com/images/bus.jpg') # predict on an image ``` -------------------------------- ### Track Objects with ByteTrack using CLI Source: https://github.com/sunsmarterjie/yolov12/blob/main/ultralytics/trackers/README.md Run object tracking from the command line, specifically selecting the ByteTrack tracker. ```bash # Track using ByteTrack tracker yolo track model=path/to/best.pt tracker="bytetrack.yaml" ``` -------------------------------- ### Build YOLOv8 OpenVINO C++ Inference Project Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-OpenVINO-CPP-Inference/README.md Create a build directory, then configure and compile the project using CMake and make. This prepares the executable for inference. ```bash mkdir build cd build cmake .. make ``` -------------------------------- ### Load Model and Track with Custom Config (CLI) Source: https://github.com/sunsmarterjie/yolov12/blob/main/ultralytics/trackers/README.md Run object tracking from the command line using a specified model and a custom tracker configuration. ```bash yolo track model=yolo11n.pt source="https://youtu.be/LNwODJXcvt4" tracker='custom_tracker.yaml' ``` -------------------------------- ### Configure Tracking Parameters (Python) Source: https://github.com/sunsmarterjie/yolov12/blob/main/ultralytics/trackers/README.md Run the tracker with custom confidence and IoU thresholds, and enable visualization. ```python from ultralytics import YOLO # Configure the tracking parameters and run the tracker model = YOLO("yolo11n.pt") results = model.track(source="https://youtu.be/LNwODJXcvt4", conf=0.3, iou=0.5, show=True) ``` -------------------------------- ### Initialize YOLO Detector Parameters Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-ONNXRuntime-CPP/README.md Set up initialization parameters for the YOLO detector, including confidence thresholds, model path, image size, and CUDA enablement. ```c++ //change your param as you like //Pay attention to your device and the onnx model type(fp32 or fp16) DL_INIT_PARAM params; params.rectConfidenceThreshold = 0.1; params.iouThreshold = 0.5; params.modelPath = "yolov8n.onnx"; params.imgSize = { 640, 640 }; params.cudaEnable = true; params.modelType = YOLO_DETECT_V8; yoloDetector->CreateSession(params); Detector(yoloDetector); ``` -------------------------------- ### Run YOLOv12 Demo Source: https://github.com/sunsmarterjie/yolov12/blob/main/README.md Execute the demo application script using Python. The demo will be accessible at the specified local URL. ```bash python app.py # Please visit http://127.0.0.1:7860 ``` -------------------------------- ### Perform Tracking with Default Tracker (Python) Source: https://github.com/sunsmarterjie/yolov12/blob/main/ultralytics/trackers/README.md Run object tracking on a video stream using the default tracker. Ensure the model is loaded first. ```python # Perform tracking with the model results = model.track(source="https://youtu.be/LNwODJXcvt4", show=True) # Tracking with default tracker ``` -------------------------------- ### Post-Build Commands for Windows Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-ONNXRuntime-CPP/CMakeLists.txt Copies the ONNX Runtime DLL to the executable directory on Windows after the build is complete. ```cmake # For windows system, copy onnxruntime.dll to the same folder of the executable file if (WIN32) add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "${ONNXRUNTIME_ROOT}/lib/onnxruntime.dll" $) endif () ``` -------------------------------- ### Display Help for YOLOv8 ONNXRuntime Rust CLI Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-ONNXRuntime-Rust/README.md View all available command-line arguments for the YOLOv8 ONNXRuntime Rust application. This is useful for understanding all configuration options. ```bash git clone https://github.com/ultralytics/ultralytics cd ultralytics/examples/YOLOv8-ONNXRuntime-Rust cargo run --release -- --help ``` -------------------------------- ### Perform Tracking with ByteTrack Tracker (Python) Source: https://github.com/sunsmarterjie/yolov12/blob/main/ultralytics/trackers/README.md Run object tracking on a video stream specifying ByteTrack as the desired tracker. Ensure the model is loaded first. ```python results = model.track( source="https://youtu.be/LNwODJXcvt4", show=True, tracker="bytetrack.yaml" # Tracking with ByteTrack tracker ) ``` -------------------------------- ### Load and Use YOLO11 Models in Python Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/tutorial.ipynb Demonstrates loading YOLO11 models from scratch or pretrained checkpoints, and performing training, validation, prediction, and export operations. Requires the 'ultralytics' library. ```python from ultralytics import YOLO # Load a model model = YOLO('yolo11n.yaml') # build a new model from scratch model = YOLO('yolo11n.pt') # load a pretrained model (recommended for training) # Use the model results = model.train(data='coco8.yaml', epochs=3) # train the model results = model.val() # evaluate model performance on the validation set results = model('https://ultralytics.com/images/bus.jpg') # predict on an image results = model.export(format='onnx') # export the model to ONNX format ``` -------------------------------- ### Track Objects using CLI Source: https://github.com/sunsmarterjie/yolov12/blob/main/ultralytics/trackers/README.md Execute object tracking from the command line interface using various YOLO models and sources. ```bash # Perform tracking with various models using the command line interface yolo track model=yolo11n.pt source="https://youtu.be/LNwODJXcvt4" # Official Detect model yolo track model=yolo11n-seg.pt source="https://youtu.be/LNwODJXcvt4" # Official Segment model yolo track model=yolo11n-pose.pt source="https://youtu.be/LNwODJXcvt4" # Official Pose model yolo track model=path/to/best.pt source="https://youtu.be/LNwODJXcvt4" # Custom trained model ``` -------------------------------- ### Load Model and Track with Custom Config (Python) Source: https://github.com/sunsmarterjie/yolov12/blob/main/ultralytics/trackers/README.md Load a YOLO model and run tracking on a video source using a custom tracker configuration file. ```python model = YOLO("yolo11n.pt") results = model.track(source="https://youtu.be/LNwODJXcvt4", tracker="custom_tracker.yaml") ``` -------------------------------- ### Run YOLOv8 Inference with ONNXRuntime (TensorRT FP16) Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-ONNXRuntime-Rust/README.md Utilize TensorRT for high-performance inference with FP16 precision. This requires TensorRT and CUDA to be installed and configured. ```bash cargo run --release -- --trt --fp16 --model --source ``` -------------------------------- ### Train and Predict with YOLO11 Classification Model Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/tutorial.ipynb Loads a pretrained YOLO11 classification model, trains it on mnist160 for 3 epochs, and then predicts on a sample image. Ensure 'ultralytics' is installed. ```python # Load YOLO11n-cls, train it on mnist160 for 3 epochs and predict an image with it from ultralytics import YOLO model = YOLO('yolo11n-cls.pt') # load a pretrained YOLO classification model model.train(data='mnist160', epochs=3) # train the model model('https://ultralytics.com/images/bus.jpg') # predict on an image ``` -------------------------------- ### Define Executable and Link Libraries Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-LibTorch-CPP-Inference/CMakeLists.txt Creates the main executable target 'yolov8_libtorch_inference' from the source file 'main.cc' and links it with LibTorch and OpenCV libraries. Sets the C++ standard for the target. ```cmake add_executable(yolov8_libtorch_inference "${CMAKE_CURRENT_SOURCE_DIR}/main.cc") target_link_libraries(yolov8_libtorch_inference ${TORCH_LIBRARIES} ${OpenCV_LIBS}) set_property(TARGET yolov8_libtorch_inference PROPERTY CXX_STANDARD 17) ``` -------------------------------- ### Enable Debug Mode for YOLOv8 Region Counter Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-Region-Counter/readme.md This bash command shows how to run the YOLOv8 region counter script with the --debug flag enabled. Use this to get more insights during inference, which can be helpful for troubleshooting. ```bash python yolov8_region_counter.py --source "path to video file" --debug ``` -------------------------------- ### Define Counting Regions with Polygons and Rectangles Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-Region-Counter/readme.md This Python snippet demonstrates how to define custom counting regions using shapely Polygons. It includes examples for both a pentagonal region and a rectangular region, specifying their names, coordinates, initial counts, dragging status, and colors. ```python from shapely.geometry import Polygon counting_regions = [ { "name": "YOLOv8 Polygon Region", "polygon": Polygon( [(50, 80), (250, 20), (450, 80), (400, 350), (100, 350)] ), # Polygon with five points (Pentagon) "counts": 0, "dragging": False, "region_color": (255, 42, 4), # BGR Value "text_color": (255, 255, 255), # Region Text Color }, { "name": "YOLOv8 Rectangle Region", "polygon": Polygon([(200, 250), (440, 250), (440, 550), (200, 550)]), # Rectangle with four points "counts": 0, "dragging": False, "region_color": (37, 255, 225), # BGR Value "text_color": (0, 0, 0), # Region Text Color }, ] ``` -------------------------------- ### Manual ONNXRuntime Linking (Linux/macOS) Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLO-Series-ONNXRuntime-Rust/README.md Export the ORT_DYLIB_PATH environment variable to point to the ONNX Runtime shared library for manual linking. ```shell export ORT_DYLIB_PATH=/path/to/onnxruntime/lib/libonnxruntime.so.1.19.0 ``` -------------------------------- ### Running Action Recognition with Custom Labels Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-Action-Recognition/readme.md Execute the action recognition script with custom labels for zero-shot video classification. Specify the video source and a space-separated list of desired action labels. ```bash python action_recognition.py --source https://www.youtube.com/watch?v=dQw4w9WgXcQ --labels "dancing" "singing" "jumping" ``` -------------------------------- ### Project and C++ Standard Configuration Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-ONNXRuntime-CPP/CMakeLists.txt Sets the minimum CMake version, project name, version, and enforces C++17 standard for filesystem support. ```cmake cmake_minimum_required(VERSION 3.5) set(PROJECT_NAME Yolov8OnnxRuntimeCPPInference) project(${PROJECT_NAME} VERSION 0.0.1 LANGUAGES CXX) # -------------- Support C++17 for using filesystem ------------------# set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) ``` -------------------------------- ### Multithreaded Object Tracking with YOLO Source: https://github.com/sunsmarterjie/yolov12/blob/main/ultralytics/trackers/README.md Demonstrates how to run object tracking on multiple video streams concurrently using Python's threading module. Each thread processes a different video file with a specified YOLO model. Ensure video files and models are correctly specified. ```Python import threading import cv2 from ultralytics import YOLO def run_tracker_in_thread(filename, model): """Starts multi-thread tracking on video from `filename` using `model` and displays results frame by frame.""" video = cv2.VideoCapture(filename) frames = int(video.get(cv2.CAP_PROP_FRAME_COUNT)) for _ in range(frames): ret, frame = video.read() if ret: results = model.track(source=frame, persist=True) res_plotted = results[0].plot() cv2.imshow("p", res_plotted) if cv2.waitKey(1) == ord("q"): break # Load the models model1 = YOLO("yolo11n.pt") model2 = YOLO("yolo11n-seg.pt") # Define the video files for the trackers video_file1 = "path/to/video1.mp4" video_file2 = "path/to/video2.mp4" # Create the tracker threads tracker_thread1 = threading.Thread(target=run_tracker_in_thread, args=(video_file1, model1), daemon=True) tracker_thread2 = threading.Thread(target=run_tracker_in_thread, args=(video_file2, model2), daemon=True) # Start the tracker threads tracker_thread1.start() tracker_thread2.start() # Wait for the tracker threads to finish tracker_thread1.join() tracker_thread2.join() # Clean up and close windows cv2.destroyAllWindows() ``` -------------------------------- ### Action Recognition on Local Video File Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-Action-Recognition/readme.md Run action recognition on a local video file by providing the path to the video. ```python python action_recognition.py --source path/to/video.mp4 ``` -------------------------------- ### CMake Build Configuration Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-ONNXRuntime-CPP/README.md Configure the build process using CMake. Specify build flags like WIN32, LINUX, or APPLE based on your operating system. ```bash mkdir build && cd build cmake .. # compiled in a win32 system cmake -D WIN32=TRUE .. # compiled in a linux system cmake -D LINUX=TRUE .. # compiled in an apple system cmake -D APPLE=TRUE .. ``` -------------------------------- ### Track Objects via CLI Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/object_tracking.ipynb Use the Ultralytics CLI to perform object tracking on a video file. Ensure the 'save' argument is set to True to save the output. ```bash !yolo track source="/path/to/video/file.mp4" save=True ``` -------------------------------- ### Configuration File and Model Copying Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-ONNXRuntime-CPP/CMakeLists.txt Copies dataset configuration (coco.yaml) and the YOLOv8 model (yolov8n.onnx) to the build directory. Also creates an 'images' directory. ```cmake # Download https://raw.githubusercontent.com/ultralytics/ultralytics/main/ultralytics/cfg/datasets/coco.yaml # and put it in the same folder of the executable file configure_file(coco.yaml ${CMAKE_CURRENT_BINARY_DIR}/coco.yaml COPYONLY) # Copy yolov8n.onnx file to the same folder of the executable file configure_file(yolov8n.onnx ${CMAKE_CURRENT_BINARY_DIR}/yolov8n.onnx COPYONLY) # Create folder name images in the same folder of the executable file add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/images ) ``` -------------------------------- ### CMakeLists.txt Configuration for YOLOv8 OpenVINO C++ Inference Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-OpenVINO-CPP-Inference/CMakeLists.txt This snippet shows the complete CMakeLists.txt file used to build a C++ application for YOLOv8 inference with OpenVINO. It sets the C++ standard, finds OpenCV, includes OpenVINO runtime headers, and links the necessary libraries. ```cmake cmake_minimum_required(VERSION 3.12) project(yolov8_openvino_example) set(CMAKE_CXX_STANDARD 14) find_package(OpenCV REQUIRED) include_directories( ${OpenCV_INCLUDE_DIRS} /path/to/intel/openvino/runtime/include ) add_executable(detect main.cc inference.cc ) target_link_libraries(detect ${OpenCV_LIBS} /path/to/intel/openvino/runtime/lib/intel64/libopenvino.so ) ``` -------------------------------- ### Basic Action Recognition with Custom Labels Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-Action-Recognition/readme.md Perform action recognition on a YouTube video, specifying custom labels like 'dancing' and 'singing a song'. ```python python action_recognition.py --source "https://www.youtube.com/watch?v=dQw4w9WgXcQ" --labels "dancing" "singing a song" ``` -------------------------------- ### Run YOLOv8 Inference with OpenVINO C++ Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-OpenVINO-CPP-Inference/README.md Execute the compiled program to perform inference on an image using a specified model. The model can be in ONNX or OpenVINO IR format. ```bash ./detect ``` -------------------------------- ### Train and Predict with YOLO11 Pose Model Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/tutorial.ipynb Loads a pretrained YOLO11 pose model, trains it on COCO8-pose for 3 epochs, and then predicts on a sample image. Requires the 'ultralytics' library. ```python # Load YOLO11n-pose, train it on COCO8-pose for 3 epochs and predict an image with it from ultralytics import YOLO model = YOLO('yolo11n-pose.pt') # load a pretrained YOLO pose model model.train(data='coco8-pose.yaml', epochs=3) # train the model model('https://ultralytics.com/images/bus.jpg') # predict on an image ``` -------------------------------- ### Initialize and Train YOLO Model in Python Source: https://github.com/sunsmarterjie/yolov12/blob/main/ultralytics/cfg/models/README.md Initialize a YOLOv11n model from a YAML configuration file and train it using the COCO8 dataset for 100 epochs in a Python environment. Optionally, load a pre-trained model checkpoint. ```python from ultralytics import YOLO # Initialize a YOLO11n model from a YAML configuration file model = YOLO("model.yaml") # If a pre-trained model is available, use it instead # model = YOLO("model.pt") # Display model information model.info() # Train the model using the COCO8 dataset for 100 epochs model.train(data="coco8.yaml", epochs=100) ``` -------------------------------- ### Action Recognition on CPU Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-Action-Recognition/readme.md Force the inference to run on the CPU, useful when a GPU is unavailable or not desired. ```python python action_recognition.py --device cpu ``` -------------------------------- ### Run Tests on Cloned Ultralytics Repository Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/tutorial.ipynb Executes the test suite for the 'ultralytics' library after cloning the repository. This command is used to verify the integrity of the codebase. ```bash # Run tests (Git clone only) !pytest ultralytics/tests ``` -------------------------------- ### YOLOv8 Instance Segmentation with TensorRT and FP16 Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-ONNXRuntime-Rust/README.md Runs instance segmentation using a YOLOv8 ONNX model with TensorRT and FP16 precision. It processes an image and plots the results. ```bash cargo run --release -- --trt --fp16 --model ../assets/weights/yolov8m-seg.onnx --source ../assets/images/0172.jpg --plot ``` -------------------------------- ### Find and Configure OpenCV Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-LibTorch-CPP-Inference/CMakeLists.txt Locates the OpenCV library using its CMake configuration directory and prints its status and details. Includes OpenCV headers for the project. ```cmake set(OpenCV_DIR "/path/to/opencv/lib/cmake/opencv4") find_package(OpenCV REQUIRED) message(STATUS "OpenCV library status:") message(STATUS " config: ${OpenCV_DIR}") message(STATUS " version: ${OpenCV_VERSION}") message(STATUS " libraries: ${OpenCV_LIBS}") message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}") include_directories(${OpenCV_INCLUDE_DIRS}) ``` -------------------------------- ### Run YOLOv8-SAHI Inference with Save Option Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-SAHI-Inference-Video/readme.md Execute the yolov8_sahi.py script to perform object detection on a video file. This command includes the --save-img flag to save the detection results as images. ```python python yolov8_sahi.py --source "path/to/video.mp4" --save-img ``` -------------------------------- ### Train YOLOv11n Model via CLI Source: https://github.com/sunsmarterjie/yolov12/blob/main/ultralytics/cfg/models/README.md Use this command to train a YOLOv11n model using the coco8 dataset for 100 epochs via the CLI. ```bash yolo task=detect mode=train model=yolo11n.yaml data=coco8.yaml epochs=100 ``` -------------------------------- ### Run YOLOv8 Region Counting with Custom Model Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-Region-Counter/readme.md Execute the region counter script on a video file using a specified YOLOv8 model file, saving results and displaying the output. ```python python yolov8_region_counter.py --source "path/to/video.mp4" --save-img --weights "path/to/model.pt" ``` -------------------------------- ### YOLOv8 Classification with Dynamic Shape on CPU Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-ONNXRuntime-Rust/README.md Runs a dynamic shape ONNX classification model on CPU. It processes an image with specified height and width, plots the result, and profiles the execution. ```bash cargo run --release -- --model ../assets/weights/yolov8m-cls-dyn.onnx --source ../assets/images/dog.jpg --height 224 --width 224 --plot --profile ``` -------------------------------- ### Run YOLOv8 Inference with ONNX Runtime Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-ONNXRuntime/README.md Executes the YOLOv8 model using ONNX Runtime for object detection on a specified image. Adjust model path, image path, and thresholds as needed. ```bash python main.py --model yolov8n.onnx --img image.jpg --conf-thres 0.5 --iou-thres 0.5 ``` -------------------------------- ### Instance Segmentation and Object Tracking in Python Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/object_tracking.ipynb This Python script performs instance segmentation and object tracking on a video. It loads a YOLO model, processes video frames, annotates detected objects with tracking IDs, and saves the output video. ```python from collections import defaultdict import cv2 from ultralytics import YOLO from ultralytics.utils.plotting import Annotator, colors # Dictionary to store tracking history with default empty lists track_history = defaultdict(lambda: []) # Load the YOLO model with segmentation capabilities model = YOLO("yolo11n-seg.pt") # Open the video file cap = cv2.VideoCapture("path/to/video/file.mp4") # Retrieve video properties: width, height, and frames per second w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS)) # Initialize video writer to save the output video with the specified properties out = cv2.VideoWriter("instance-segmentation-object-tracking.avi", cv2.VideoWriter_fourcc(*"MJPG"), fps, (w, h)) while True: # Read a frame from the video ret, im0 = cap.read() if not ret: print("Video frame is empty or video processing has been successfully completed.") break # Create an annotator object to draw on the frame annotator = Annotator(im0, line_width=2) # Perform object tracking on the current frame results = model.track(im0, persist=True) # Check if tracking IDs and masks are present in the results if results[0].boxes.id is not None and results[0].masks is not None: # Extract masks and tracking IDs masks = results[0].masks.xy track_ids = results[0].boxes.id.int().cpu().tolist() # Annotate each mask with its corresponding tracking ID and color for mask, track_id in zip(masks, track_ids): annotator.seg_bbox(mask=mask, mask_color=colors(int(track_id), True), label=str(track_id)) # Write the annotated frame to the output video out.write(im0) # Display the annotated frame cv2.imshow("instance-segmentation-object-tracking", im0) # Exit the loop if 'q' is pressed if cv2.waitKey(1) & 0xFF == ord("q"): break # Release the video writer and capture objects, and close all OpenCV windows out.release() cap.release() cv2.destroyAllWindows() ``` -------------------------------- ### Run YOLOv8-SAHI Inference with Custom Weights Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-SAHI-Inference-Video/readme.md Perform object detection on a video file using a specified YOLOv8 model weight file. This command allows you to use different model variants like 'yolo11n.pt'. ```python python yolov8_sahi.py --source "path/to/video.mp4" --save-img --weights "yolo11n.pt" ``` -------------------------------- ### Run YOLOv8 Region Counting with Save Results Source: https://github.com/sunsmarterjie/yolov12/blob/main/examples/YOLOv8-Region-Counter/readme.md Execute the region counter script on a video file, saving detection results as images and displaying the output. ```python python yolov8_region_counter.py --source "path/to/video.mp4" --save-img --view-img ```