Skip to content

Hyperparameter Tuning and Object Counting #799

Closed

Description

@RickStor

Search before asking

Question

Hello, can I use the Ultralytics Hub to fine-tune a model's hyperparameters?
Additionally, is it possible to perform object counting with this platform?

Additional

No response

Activity

  1. github-actions commented on Aug 12, 2024

    @github-actions

    👋 Hello @RickStor, thank you for raising an issue about Ultralytics HUB 🚀! Please visit our HUB Docs to learn more:

    • Quickstart. Start training and deploying YOLO models with HUB in seconds.
    • Datasets: Preparing and Uploading. Learn how to prepare and upload your datasets to HUB in YOLO format.
    • Projects: Creating and Managing. Group your models into projects for improved organization.
    • Models: Training and Exporting. Train YOLOv5 and YOLOv8 models on your custom datasets and export them to various formats for deployment.
    • Integrations. Explore different integration options for your trained models, such as TensorFlow, ONNX, OpenVINO, CoreML, and PaddlePaddle.
    • Ultralytics HUB App. Learn about the Ultralytics App for iOS and Android, which allows you to run models directly on your mobile device.
      • iOS. Learn about YOLO CoreML models accelerated on Apple's Neural Engine on iPhones and iPads.
      • Android. Explore TFLite acceleration on mobile devices.
    • Inference API. Understand how to use the Inference API for running your trained models in the cloud to generate predictions.

    If this is a 🐛 Bug Report, please provide screenshots and steps to reproduce your problem to help us get started working on a fix.

    If this is a ❓ Question, please provide as much information as possible, including dataset, model, environment details etc. so that we might provide the most helpful response.

    We try to respond to all issues as promptly as possible. Thank you for your patience!

  2. pderrenger commented on Aug 13, 2024

    @pderrenger
    Member

    @RickStor hello!

    Thank you for reaching out with your questions. I'm happy to help!

    Hyperparameter Tuning

    Yes, you can fine-tune a model's hyperparameters using Ultralytics HUB. The platform provides an intuitive interface for adjusting various hyperparameters to optimize your model's performance. You can access these settings in the training configuration section when you initiate a new training session. For more detailed guidance, you can refer to the Models section in our documentation.

    Object Counting

    Absolutely, object counting is possible with Ultralytics HUB. Once you have trained your YOLO model, you can use it to detect and count objects in images or video streams. The platform supports real-time deployment, which makes it ideal for applications that require object counting. You can deploy your model using the Ultralytics HUB App and leverage its capabilities for tasks such as counting objects in a live feed.

    If you have any more questions or need further assistance, feel free to ask. We're here to help!

  3. RickStor commented on Aug 13, 2024

    @RickStor
    Author
  4. pderrenger commented on Aug 14, 2024

    @pderrenger
    Member

    Hi @RickStor,

    Thank you for your detailed follow-up!

    For your university paper on people counting, it sounds like you're on the right track. Here are a few steps and tips to help you get the results you're looking for:

    Previewing Results

    In the Ultralytics HUB, the preview tab should indeed show the detected objects, including people, in your images. If you're not seeing any results, here are a few things to check:

    1. Model Accuracy: Ensure that your model has been trained adequately and has a good accuracy rate. Sometimes, insufficient training data or incorrect annotations can lead to poor detection results.
    2. Threshold Settings: Check the confidence threshold settings in the preview tab. If the threshold is set too high, the model might not display detections that it is less confident about.

    Deployment

    While the preview tab should give you an initial idea of your model's performance, deploying the model can provide more robust and consistent results. Deployment is not strictly necessary for counting people in a static image, but it can help in fine-tuning and validating your model's performance in a real-world scenario.

    Counting People

    To count the number of people in an image, you can use the following approach:

    1. Detection: Use the model to detect all instances of people in the image.
    2. Counting: Sum the number of detected instances.

    Here is a simple example of how you might count people in an image using Python after deploying your model:

    import cv2
    from ultralytics import YOLO
    
    # Load your trained model
    model = YOLO('path/to/your/model.pt')
    
    # Load the image
    image = cv2.imread('path/to/your/image.jpg')
    
    # Perform inference
    results = model(image)
    
    # Extract the number of people detected
    people_count = sum(1 for result in results if result['class'] == 'person')
    
    print(f'Number of people detected: {people_count}')

    This code assumes you have deployed your model and have the necessary libraries installed. Adjust the paths and class names as needed.

    If you continue to face issues, please ensure you are using the latest version of the Ultralytics HUB and YOLO models. Sometimes, updates can resolve unexpected behavior.

    Feel free to reach out if you have any more questions or need further assistance. Good luck with your paper!

  5. RickStor commented on Aug 15, 2024

    @RickStor
    Author
  6. glenn-jocher commented on Aug 16, 2024

    @glenn-jocher
    Member

    Hi @RickStor,

    Thank you for your kind words and for following up with additional questions!

    Training a YOLO Model Locally

    To train a YOLO model from scratch in your local environment, you can follow these steps:

    1. Clone the YOLOv5 or YOLOv8 Repository:

      git clone https://github.com/ultralytics/yolov5.git  # or yolov8
      cd yolov5  # or yolov8
    2. Install Dependencies:

      pip install -r requirements.txt
    3. Prepare Your Dataset:
      Ensure your dataset is in the correct format (e.g., COCO or YOLO format). You can use tools like Roboflow to help with dataset preparation.

    4. Train Your Model:

      python train.py --img 640 --batch 16 --epochs 50 --data path/to/your/dataset.yaml --cfg models/yolov5s.yaml --weights '' --name custom_yolov5s
      • --img: Image size.
      • --batch: Batch size.
      • --epochs: Number of training epochs.
      • --data: Path to your dataset configuration file.
      • --cfg: Model configuration file.
      • --weights: Path to pre-trained weights (use '' for training from scratch).
      • --name: Name of your training run.

    Counting People in an Image

    For counting people in an image, you can use the following approach after deploying your model:

    import cv2
    from ultralytics import YOLO
    
    # Load your trained model
    model = YOLO('path/to/your/model.pt')
    
    # Load the image
    image = cv2.imread('path/to/your/image.jpg')
    
    # Perform inference
    results = model(image)
    
    # Extract the number of people detected
    people_count = sum(1 for result in results if result['class'] == 'person')
    
    print(f'Number of people detected: {people_count}')

    Additional Tips

    • Model Accuracy: Ensure your model is well-trained with a sufficient amount of annotated data.
    • Threshold Settings: Adjust the confidence threshold to ensure all relevant detections are captured.
    • Deployment: While not strictly necessary for static images, deploying your model can help validate its performance in real-world scenarios.

    If you encounter any issues, please ensure you are using the latest versions of the Ultralytics HUB and YOLO models. Updates often resolve unexpected behavior.

    Feel free to reach out if you have any more questions or need further assistance. Good luck with your paper!

  7. RickStor commented on Aug 20, 2024

    @RickStor
    Author
  8. RickStor commented on Aug 20, 2024

    @RickStor
    Author
  9. glenn-jocher commented on Aug 21, 2024

    @glenn-jocher
    Member

    Hi @RickStor,

    Thank you for your detailed questions and for continuing the discussion!

    Specifying Classes for Training

    Yes, you can specify that the training objective is only to identify certain classes such as "persons" and "pedestrian". When preparing your dataset, ensure that your dataset configuration file (.yaml) includes only the classes you are interested in. Here is an example of how you might configure your dataset:

    names:
      0: person
      1: pedestrian

    By doing this, the model will focus on these classes during training.

    Counting Identified Classes in the Preview Tab

    Currently, the Ultralytics HUB Preview tab allows you to visualize the detections but does not provide a direct count of the identified classes. To get the count of identified classes, you would indeed need to use the provided code in a local environment such as Google Colab or Jupyter Notebook. This allows you to perform custom post-processing on the inference results to count the detected instances.

    Adjusting Augmentation Settings and Hyperparameters

    Regarding augmentation settings and hyperparameters, you are correct that the Ultralytics HUB provides a streamlined interface with a limited set of adjustable parameters. For more advanced customization, including setting arguments like hsv_s, hsv_v, scale, etc., you would need to train your model locally. Here is an example of how you can adjust these settings in a local training script:

    # hyp.scratch.yaml
    lr0: 0.01
    momentum: 0.937
    weight_decay: 0.0005
    hsv_h: 0.015
    hsv_s: 0.7
    hsv_v: 0.4
    degrees: 0.0
    translate: 0.1
    scale: 0.5
    shear: 0.0
    perspective: 0.0
    flipud: 0.0
    fliplr: 0.5
    mosaic: 1.0
    mixup: 0.0

    You can then pass this configuration file when initiating your training:

    python train.py --img 640 --batch 16 --epochs 50 --data path/to/your/dataset.yaml --cfg models/yolov5s.yaml --hyp hyp.scratch.yaml --weights '' --name custom_yolov5s

    Summary

    • Specifying Classes: Configure your dataset .yaml file to include only the desired classes.
    • Counting Classes: Use the provided code in a local environment for custom post-processing.
    • Augmentation and Hyperparameters: For advanced settings, train your model locally with a custom hyperparameter configuration file.

    If you have any more questions or need further assistance, feel free to ask. We're here to help! 😊

  10. RickStor commented on Aug 22, 2024

    @RickStor
    Author
  11. glenn-jocher commented on Aug 22, 2024

    @glenn-jocher
    Member

    Hi @RickStor,

    Thank you for reaching out and providing detailed information about your setup and the issue you're encountering.

    Kernel Restart Issue

    The kernel restarting issue you're experiencing can be due to several factors, including memory management, GPU compatibility, or software conflicts. Here are a few steps to help you troubleshoot and resolve this problem:

    1. Update Packages:
      Ensure you have the latest versions of the necessary packages. You can update Ultralytics and other dependencies using the following commands:

      pip install --upgrade ultralytics
      pip install --upgrade torch torchvision torchaudio
    2. Check GPU Compatibility:
      Verify that your GPU drivers and CUDA toolkit are up to date. You can download the latest drivers from the NVIDIA website.

    3. Reduce Batch Size:
      Sometimes, the default batch size may be too large for your system's memory. Try reducing the batch size in your training script:

      results = model.train(data='VisDrone.yaml', epochs=20, batch=4)  # Adjust batch size as needed
    4. Monitor System Resources:
      Keep an eye on your system's resource usage (CPU, GPU, memory) during training. You can use tools like Task Manager on Windows or nvidia-smi for GPU monitoring.

    5. Run in a Different Environment:
      If the issue persists, try running your code in a different environment, such as Google Colab, which provides a cloud-based GPU environment.

    Example Code

    Here is an example of how you might adjust your training script to include a smaller batch size and ensure compatibility:

    import torch
    from ultralytics import YOLO
    
    # Check if CUDA is available
    device = 'cuda' if torch.cuda.is_available() else 'cpu'
    
    # Load your pretrained model
    model = YOLO('yolov8n.pt').to(device)
    
    # Train the model with a smaller batch size
    results = model.train(data='VisDrone.yaml', epochs=20, batch=4)

    Additional Resources

    For more detailed troubleshooting, you can refer to the Ultralytics YOLO documentation and the PyTorch documentation.

    If you continue to experience issues, please ensure you are using the latest versions of all relevant packages and consider trying the training process in a different environment.

    Feel free to reach out if you have any more questions or need further assistance. We're here to help! 😊

  12. RickStor commented on Aug 23, 2024

    @RickStor
    Author
  13. glenn-jocher commented on Aug 24, 2024

    @glenn-jocher
    Member

    Hi @RickStor,

    Thank you for your kind words and for sharing your progress! I'm glad to hear that you've resolved the kernel restart issue and successfully ran YOLOv8n for 50 epochs. Let's address your new questions:

    Specifying Classes for Training

    When you edit the VisDrone.yaml file to include only "person" and "pedestrian," ensure that the class indices are correctly mapped. Here’s a checklist to help you troubleshoot:

    1. Class Names and Indices:
      Make sure the class names and indices in your VisDrone_edited.yaml file are correctly specified. For example:

      names:
        0: person
        1: pedestrian
    2. Annotations:
      Verify that your dataset annotations only include the specified classes. If there are annotations for removed classes, it could cause errors during training.

    3. Data File Path:
      Ensure that the path to your edited YAML file is correct in your training script:

      results = model.train(data='VisDrone_edited.yaml', epochs=20)

    Adjusting Augmentation Settings and Hyperparameters

    To incorporate the desired parameters from the hyp.scratch.yaml file into your training process in a Jupyter notebook, you can pass the hyp parameter in the train method. Here’s how you can modify your code:

    1. Create a Hyperparameter Configuration File:
      Save your hyperparameter settings in a file named hyp.scratch.yaml. For example:

      lr0: 0.01
      momentum: 0.937
      weight_decay: 0.0005
      hsv_h: 0.015
      hsv_s: 0.7
      hsv_v: 0.4
      degrees: 0.0
      translate: 0.1
      scale: 0.5
      shear: 0.0
      perspective: 0.0
      flipud: 0.0
      fliplr: 0.5
      mosaic: 1.0
      mixup: 0.0
    2. Modify Your Training Script:
      Update your training script to include the hyp parameter:

      from ultralytics import YOLO
      
      # Load your pretrained model
      model = YOLO('yolov8n.pt')
      
      # Train the model with custom hyperparameters
      results = model.train(data='VisDrone_edited.yaml', epochs=20, hyp='hyp.scratch.yaml')

    Summary

    • Class Specification: Ensure your VisDrone_edited.yaml file correctly maps the class names and indices and that your dataset annotations match these classes.
    • Hyperparameters: Use the hyp parameter in your training script to include custom hyperparameters from a YAML file.

    If you encounter any further issues or have more questions, feel free to ask. We're here to help! 😊

  14. RickStor commented on Aug 25, 2024

    @RickStor
    Author
  15. 9 remaining items

  16. RickStor commented on Sep 26, 2024

    @RickStor
    Author
  17. glenn-jocher commented on Sep 26, 2024

    @glenn-jocher
    Member

    Hi Ricardo,

    Thank you for your thoughtful message and for diving deep into the YOLO documentation! I'm thrilled to hear about your progress and success with the inference code. 😊

    Evaluating Model Metrics on the Test Set

    To evaluate your model's performance on the test set, you can indeed use the model.val() method. This will provide you with detailed metrics such as precision, recall, and mAP (mean Average Precision), which are essential for understanding how well your model is performing.

    Here's how you can do it:

    1. Validation on the Test Set:
      You can run validation on your test set using the following code:

      # Validate the model on the test set
      results = model.val(data='path/to/VisDrone_edited.yaml', split='test')

      Ensure that your VisDrone_edited.yaml file includes the correct paths for the test set.

    2. Review Metrics:
      After running the validation, you'll receive a summary of the metrics, which will help you assess the model's performance.

    Additional Tips

    • Ensure Data Integrity: Double-check that your test set annotations are correctly formatted and match the classes specified in your YAML file.
    • Latest Versions: Make sure you're using the latest version of the Ultralytics packages to benefit from the latest features and improvements.

    If you have any more questions or need further assistance, feel free to ask. Your learning journey with YOLO is inspiring, and I'm here to support you every step of the way! 🚀

  18. RickStor commented on Sep 27, 2024

    @RickStor
    Author
  19. glenn-jocher commented on Sep 27, 2024

    @glenn-jocher
    Member

    Hi Ricardo,

    Thank you for your thoughtful message and for diving deep into the YOLO documentation! I'm thrilled to hear that the inference process went smoothly and that you're making great progress. 😊

    Evaluating Model Metrics on the Test Set

    To evaluate your model on the test set and generate metrics, you can indeed use the model.val() method. This will provide you with detailed evaluation metrics such as precision, recall, mAP (mean Average Precision), and more.

    Here's how you can do it:

    1. Validation on the Test Set:
      You can specify the path to your test dataset in the model.val() method. Make sure your dataset is structured correctly with images and labels.

      # Validate the model on the test set
      metrics = model.val(data='path/to/VisDrone2019-DET-test-dev')
    2. Review Metrics:
      The metrics variable will contain detailed evaluation results, allowing you to assess the model's performance comprehensively.

    Additional Tips

    • Ensure Latest Versions: Make sure you are using the latest versions of the Ultralytics packages to avoid any unexpected issues.
    • Dataset Structure: Double-check that your test dataset is organized correctly with corresponding images and labels.

    If you have any more questions or need further assistance, feel free to reach out. Your learning journey with YOLO is inspiring, and I'm here to support you every step of the way! 🚀

  20. deleted a comment from pderrenger on Nov 2, 2024
  21. deleted a comment from pderrenger on Nov 2, 2024
  22. deleted a comment from pderrenger on Nov 2, 2024
  23. deleted a comment from pderrenger on Nov 2, 2024
  24. deleted a comment from pderrenger on Nov 2, 2024
  25. pderrenger commented on Nov 3, 2024

    @pderrenger
    Member

    Hi Ricardo,

    Thank you for your kind words and for sharing your progress! I'm delighted to hear that the inference process went smoothly and that you're finding the documentation helpful. 😊

    Evaluating Model Metrics on the Test Set

    To evaluate your model's performance on the test set, you can indeed use the model.val() method. This method is designed to compute metrics such as precision, recall, and mAP (mean Average Precision) on a validation dataset, but you can apply it to your test set as well. Here's how you can do it:

    1. Prepare Your Test Set:
      Ensure that your test set is structured similarly to your training and validation sets, with images and corresponding labels.

    2. Run Validation:
      Use the model.val() method to evaluate your model on the test set. You can specify the path to your test dataset in the data parameter.

      # Evaluate the model on the test set
      metrics = model.val(data='path/to/VisDrone2019-DET-test-dev.yaml')

      Make sure your YAML file for the test set is correctly configured, similar to your training and validation datasets.

    3. Review Metrics:
      The metrics variable will contain various performance metrics that you can use to assess your model's effectiveness on the test set.

    Additional Considerations

    • Ensure Latest Versions: Make sure you are using the latest versions of the Ultralytics packages to avoid any potential issues.
    • Documentation: Feel free to refer to the Ultralytics YOLO documentation for more detailed information on model evaluation and metrics.

    If you have any more questions or need further assistance, feel free to reach out. We're here to help you succeed in your YOLO journey! 🚀

  26. github-actions commented on Nov 23, 2025

    @github-actions

    👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

    For additional resources and information, please see the links below:

    Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

    Thank you for your contributions to YOLO 🚀 and Vision AI ⭐

  27. glenn-jocher commented on Jul 7, 2026

    @glenn-jocher
    Member

    Hi @RickStor, one follow-up on the HUB limitation you found here (only a subset of hyperparameters exposed): with HUB winding down on July 31, 2026, Ultralytics Platform cloud training now exposes the full training-argument set in the train dialog — including the augmentation parameters you asked about (hsv_h/s/v, degrees, scale, mosaic, mixup, and more), with task-aware defaults. Details: https://docs.ultralytics.com/platform/train/cloud-training/

  28. glenn-jocher commented on Nov 18, 2026

    @glenn-jocher
    Member

    Hi @RickStor, your last open question, resuming an interrupted hyperparameter search, is now supported: model.tune(..., resume=True) continues from the saved results (ultralytics/ultralytics#20037, in ultralytics 8.3.103). The earlier tuning, class-filtering and counting questions were answered above. I'm closing this, but please reopen if resume doesn't work for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    StaleStale and schedule for closing soonquestionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions