### Install Ultralytics and Run System Checks Source: https://github.com/ultralytics/hub/blob/main/hub.ipynb Installs the ultralytics package and its dependencies, then runs a check to verify system setup for Ultralytics training. This ensures your environment is ready for model training. ```python %pip install ultralytics from ultralytics import YOLO, checks, hub checks() # Verify system setup for Ultralytics training ``` -------------------------------- ### Verify System Configuration (Python) Source: https://context7.com/ultralytics/hub/llms.txt Performs a comprehensive check of the system's configuration, including Python and PyTorch versions, CUDA availability, GPU and CPU information, RAM, disk space, and the installed Ultralytics package version. This is crucial for ensuring a smooth training process. ```python from ultralytics import checks # Perform comprehensive system check checks() # Output includes: # - Python version # - PyTorch version # - CUDA availability and version # - GPU information (model, memory) # - CPU and RAM information # - Disk space availability # - Ultralytics package version # Example output: # Ultralytics 8.3.99 🚀 Python-3.11.11 torch-2.6.0+cu124 CUDA:0 (Tesla T4, 15095MiB) # Setup complete ✅ (2 CPUs, 12.7 GB RAM, 39.6/112.6 GB disk) ``` -------------------------------- ### YOLO Dataset YAML Configuration (YAML) Source: https://github.com/ultralytics/hub/blob/main/README.md Example YAML configuration file for a custom dataset compatible with YOLO format. Specifies dataset paths, image directories, and class names. ```yaml # Example YAML configuration for a custom dataset path: ../datasets/coco8 # dataset root directory (relative or absolute) train: images/train # training images (relative to 'path') val: images/val # validation images (relative to 'path') test: # test images (optional) # Class labels names: 0: person 1: bicycle 2: car 3: motorcycle # Add more classes as needed ``` -------------------------------- ### Ultralytics HUB - Login, Load Model, and Train Source: https://github.com/ultralytics/hub/blob/main/hub.ipynb Demonstrates the core functionality of training a YOLO model using Ultralytics HUB. It involves logging in with an API key, loading a pre-trained model from HUB using its ID, and starting the training process. Replace placeholders with your actual API key and model ID. ```python # Login 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() ``` -------------------------------- ### Load YOLO Models from Ultralytics HUB (Python) Source: https://context7.com/ultralytics/hub/llms.txt Loads a YOLO model directly from Ultralytics HUB using its model ID or URL. This allows for immediate use of pre-trained models for training or inference without manual download and setup. ```python from ultralytics import YOLO # Load model from HUB using model URL or ID model = YOLO("https://hub.ultralytics.com/models/abc123xyz") # Alternative: Load using just the model ID model = YOLO("abc123xyz") # Load a specific model architecture for new training model = YOLO("yolo11n.pt") # nano model model = YOLO("yolo11s.pt") # small model model = YOLO("yolo11m.pt") # medium model ``` -------------------------------- ### Prepare and Zip Dataset for Upload (Bash) Source: https://context7.com/ultralytics/hub/llms.txt This script outlines the steps to create the necessary directory structure for a dataset, copy training and validation images and labels, create a YAML configuration file, and finally zip the dataset for upload to Ultralytics HUB. It assumes a specific directory layout for images and labels. ```bash # Create dataset structure mkdir -p coco8/images/train coco8/images/val mkdir -p coco8/labels/train coco8/labels/val # Add your images and labels cp /path/to/train/images/* coco8/images/train/ cp /path/to/train/labels/* coco8/labels/train/ cp /path/to/val/images/* coco8/images/val/ cp /path/to/val/labels/* coco8/labels/val/ # Create YAML configuration cat > coco8/coco8.yaml << EOF path: train: images/train val: images/val names: 0: class1 1: class2 EOF # Zip the dataset for upload zip -r coco8.zip coco8 # Upload via HUB web interface at https://hub.ultralytics.com/datasets ``` -------------------------------- ### Zip Dataset for Upload (Bash) Source: https://github.com/ultralytics/hub/blob/main/README.md Command to zip a dataset directory for upload to Ultralytics HUB. Ensures the zipped archive matches the directory and YAML file name for easy processing. ```bash # Zip the dataset directory for upload zip -r coco8.zip coco8 ``` -------------------------------- ### Pose Estimation Dataset Configuration (YAML) Source: https://context7.com/ultralytics/hub/llms.txt Configures datasets for pose estimation tasks, including keypoint definitions and augmentation settings. Uses YAML format to specify dataset paths, keypoint shapes, and class information. ```yaml # coco8-pose.yaml - Pose Estimation Dataset path: # dataset root dir (leave empty for HUB) train: images/train val: images/val test: # Keypoints kpt_shape: [17, 3] # number of keypoints, number of dims (2 for x,y or 3 for x,y,visible) flip_idx: [0, 2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 16, 15] # Classes names: 0: person # Label format (in .txt files): # ... # Example: 0 0.5 0.5 0.3 0.6 0.45 0.35 2 0.55 0.35 2 0.50 0.40 2 ... ``` -------------------------------- ### Cloud Model Training with Ultralytics HUB (Python) Source: https://context7.com/ultralytics/hub/llms.txt Initiates YOLO model training on cloud resources via Ultralytics HUB. Supports basic and advanced training configurations including hyperparameters, dataset paths, and device selection. ```python from ultralytics import YOLO, hub # Complete training workflow hub.login("your_api_key") model = YOLO("https://hub.ultralytics.com/models/your_model_id") # Basic training results = model.train() # Advanced training with hyperparameters results = model.train( data="coco8.yaml", epochs=100, imgsz=640, batch=16, device="cpu", # or "cuda:0" for GPU patience=50, save=True, plots=True ) # Access training results print(f"Training metrics: {results.results_dict}") ``` -------------------------------- ### Object Detection Dataset Configuration (YAML) Source: https://context7.com/ultralytics/hub/llms.txt Defines the structure and paths for an object detection dataset using YAML format. Specifies image locations, validation sets, and class names compatible with YOLO architecture. ```yaml # coco8.yaml - Object Detection Dataset path: # dataset root dir (leave empty for HUB) train: images/train # train images (relative to 'path') 4 images val: images/val # val images (relative to 'path') 4 images test: # test images (optional) # Classes names: 0: person 1: bicycle 2: car 3: motorcycle 4: airplane 5: bus 6: train 7: truck # Example directory structure: # coco8/ # ├── coco8.yaml # ├── images/ # │ ├── train/ # │ │ ├── image1.jpg # │ │ └── image2.jpg # │ └── val/ # │ ├── image3.jpg # │ └── image4.jpg # └── labels/ # ├── train/ # │ ├── image1.txt # │ └── image2.txt # └── val/ # ├── image3.txt # └── image4.txt ``` -------------------------------- ### Configure Instance Segmentation Dataset (YAML) Source: https://context7.com/ultralytics/hub/llms.txt Defines the structure and class names for instance segmentation datasets. It specifies the paths for training and validation data, and the mapping of class IDs to names. The label format requires normalized polygon coordinates for segmentation masks. ```yaml # coco8-seg.yaml - Instance Segmentation Dataset path: # dataset root dir (leave empty for HUB) train: images/train val: images/val test: # Classes names: 0: person 1: bicycle 2: car # Label format (in .txt files): # ... # Normalized polygon coordinates for segmentation mask # Example: 0 0.1 0.2 0.15 0.25 0.2 0.3 0.15 0.35 0.1 0.3 ``` -------------------------------- ### Export Trained Models to Various Formats (Python) Source: https://context7.com/ultralytics/hub/llms.txt Loads a trained YOLO model and exports it to multiple formats suitable for deployment. Supported formats include ONNX, TensorFlow (SavedModel, TFLite), and CoreML. Options like image size, half-precision quantization, and ONNX simplification can be specified. ```python from ultralytics import YOLO # Load trained model model = YOLO("path/to/best.pt") # Export to ONNX format model.export(format="onnx") # Export to TensorFlow formats model.export(format="saved_model") model.export(format="tflite") # Export to CoreML for iOS model.export(format="coreml") # Export to multiple formats with options model.export( format="onnx", imgsz=640, half=True, # FP16 quantization simplify=True, opset=12 ) # Supported formats: # pytorch, torchscript, onnx, openvino, tensorrt, coreml, # saved_model, pb, tflite, edgetpu, tfjs, paddle, ncnn ``` -------------------------------- ### Authenticate with Ultralytics HUB (Python) Source: https://context7.com/ultralytics/hub/llms.txt Authenticates your local environment with Ultralytics HUB using an API key. This is necessary to access cloud training and model management features. Ensure your API key is kept secure. ```python from ultralytics import hub # Login to HUB using your API key from https://hub.ultralytics.com/settings?tab=api+keys hub.login("your_api_key_here") # Example with actual API key format (replace with your own) hub.login("1a2b3c4d5e6f7g8h9i0j") ``` -------------------------------- ### Perform Model Inference and Prediction (Python) Source: https://context7.com/ultralytics/hub/llms.txt Loads a YOLO model and performs predictions on various sources like images, videos, or webcam streams. It allows customization of parameters such as confidence threshold, NMS IOU, image size, and the device to use. The results object contains detected bounding boxes, masks, keypoints, and probabilities. ```python from ultralytics import YOLO # Load model model = YOLO("yolo11n.pt") # Predict on single image results = model.predict("image.jpg") # Predict with custom parameters results = model.predict( source="image.jpg", conf=0.25, # confidence threshold iou=0.45, # NMS IOU threshold imgsz=640, # image size save=True, # save results device="cuda:0" # GPU device ) # Process results for result in results: boxes = result.boxes # bounding boxes masks = result.masks # segmentation masks (if available) keypoints = result.keypoints # keypoints (if available) probs = result.probs # class probabilities (for classification) # Print detections for box in boxes: class_id = int(box.cls[0]) confidence = float(box.conf[0]) bbox = box.xyxy[0].tolist() print(f"Class: {class_id}, Confidence: {confidence:.2f}, BBox: {bbox}") # Predict on video results = model.predict(source="video.mp4", save=True, stream=True) # Predict on webcam results = model.predict(source=0, show=True, stream=True) ``` -------------------------------- ### Validate and Benchmark Models (Python) Source: https://context7.com/ultralytics/hub/llms.txt Validates the performance of a trained YOLO model on a specified dataset and benchmarks its performance across different export formats. It provides metrics like mAP, precision, and recall for validation, and inference time and accuracy for benchmarking. ```python from ultralytics import YOLO # Load model model = YOLO("yolo11n.pt") # Validate model on dataset metrics = model.val( data="coco8.yaml", batch=16, imgsz=640, device="cuda:0" ) # Access validation metrics print(f"mAP50: {metrics.box.map50}") print(f"mAP50-95: {metrics.box.map}") print(f"Precision: {metrics.box.p}") print(f"Recall: {metrics.box.r}") # Benchmark model across formats results = model.benchmark( data="coco8.yaml", imgsz=640, half=True, device="cuda:0" ) # Compare format performance # Results show inference time, mAP, and file size for each format ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.