Giter VIP home page Giter VIP logo

Comments (6)

github-actions avatar github-actions commented on June 29, 2024

πŸ‘‹ Hello @fbarbe00, thank you for your interest in Ultralytics YOLOv8 πŸš€! We recommend a visit to the Docs for new users where you can find many Python and CLI usage examples and where many of the most common questions may already be answered.

If this is a πŸ› Bug Report, please provide a minimum reproducible example to help us debug it.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results.

Join the vibrant Ultralytics Discord 🎧 community for real-time conversations and collaborations. This platform offers a perfect space to inquire, showcase your work, and connect with fellow Ultralytics users.

Install

Pip install the ultralytics package including all requirements in a Python>=3.8 environment with PyTorch>=1.8.

pip install ultralytics

Environments

YOLOv8 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

Ultralytics CI

If this badge is green, all Ultralytics CI tests are currently passing. CI tests verify correct operation of all YOLOv8 Modes and Tasks on macOS, Windows, and Ubuntu every 24 hours and on every commit.

from ultralytics.

glenn-jocher avatar glenn-jocher commented on June 29, 2024

@fbarbe00 hi there,

Thank you for bringing this to our attention and providing a detailed report along with a reproducible code example. This is very helpful! 😊

It appears that the max_det parameter is being retained across subsequent predictions even when it is not explicitly set. This behavior is indeed unexpected and could be indicative of a bug.

To help us investigate further, could you please confirm the following:

  1. Are you using the latest versions of torch and ultralytics? If not, please upgrade to the latest versions and try running your code again:

    pip install --upgrade torch ultralytics
  2. If the issue persists after upgrading, please provide any additional details that might help us reproduce the bug, such as the specific model architecture and any custom modifications you might have made.

In the meantime, as a workaround, you can reinitialize the model object before each prediction to ensure that the max_det parameter does not carry over:

from ultralytics import YOLO

model = YOLO(f"../{CURRENT_MODEL}.pt")
result = model(image, iou=0.9, conf=0.01)[0]
print(f"1. Loaded model, no max_det - Number of predictions: {len(result.boxes.conf)}") # 32

model = YOLO(f"../{CURRENT_MODEL}.pt")
result = model(image, iou=0.9, conf=0.01, max_det=1)[0]
print(f"2. Reinitialized model, max_det=1 - Number of predictions: {len(result.boxes.conf)}") # 1

model = YOLO(f"../{CURRENT_MODEL}.pt")
result = model(image, iou=0.9, conf=0.01)[0]
print(f"3. Reinitialized model, no max_det - Number of predictions: {len(result.boxes.conf)}") # 32

This should ensure that each prediction is independent of the previous ones.

Please let us know if this resolves the issue or if you need further assistance. We appreciate your patience and cooperation as we work to improve our models.

from ultralytics.

fbarbe00 avatar fbarbe00 commented on June 29, 2024

Hey! Thanks for your reply. As I wrote in the environment section, this was with Ultralytics v8.2.31 and torch-2.2.2+cu121
I have updated both ultralytics and torch, and can confirm that the issue still persists

from ultralytics.

glenn-jocher avatar glenn-jocher commented on June 29, 2024

Hi @fbarbe00,

Thank you for the update and for confirming that you're using the latest versions of ultralytics and torch. We appreciate your diligence in testing this.

Given that the issue persists, it seems there might be a bug with how the max_det parameter is being retained across predictions. To ensure we can investigate this thoroughly, could you please provide a minimal reproducible example that demonstrates the issue? This will help us reproduce the bug on our end and work towards a solution. You can find guidelines for creating a minimal reproducible example here.

In the meantime, as a workaround, you can reinitialize the model object before each prediction to ensure that the max_det parameter does not carry over:

from ultralytics import YOLO

model = YOLO(f"../{CURRENT_MODEL}.pt")
result = model(image, iou=0.9, conf=0.01)[0]
print(f"1. Loaded model, no max_det - Number of predictions: {len(result.boxes.conf)}") # 32

model = YOLO(f"../{CURRENT_MODEL}.pt")
result = model(image, iou=0.9, conf=0.01, max_det=1)[0]
print(f"2. Reinitialized model, max_det=1 - Number of predictions: {len(result.boxes.conf)}") # 1

model = YOLO(f"../{CURRENT_MODEL}.pt")
result = model(image, iou=0.9, conf=0.01)[0]
print(f"3. Reinitialized model, no max_det - Number of predictions: {len(result.boxes.conf)}") # 32

This should ensure that each prediction is independent of the previous ones.

Thank you for your patience and cooperation. We're here to help, so please let us know if you need any further assistance!

from ultralytics.

fbarbe00 avatar fbarbe00 commented on June 29, 2024

Hi,

Thank you for the effort of reading and answering most issues.
However, have you guys actually read my initial issue? I had already provided both the version and code to replicate the issue. I actually also already provided the workaround you suggested.

Here's an even more minimal version of the code, that you can run directly:

import torch
from ultralytics import YOLO
model = YOLO("yolov8n.pt")
image = torch.rand(1, 3, 640, 640)
result = model(image, iou=0.9, conf=0.01)[0]
print(f"1. Loaded model, no max_det - Number of predictions: {len(result.boxes.conf)}")

result = model(image, iou=0.9, conf=0.01, max_det=1)[0]
print(f"2. Same model obj, max_det=1 - Number of predictions: {len(result.boxes.conf)}")


result = model(image, iou=0.9, conf=0.01)[0]
print(f"3. Same model obj, no max_det - Number of predictions: {len(result.boxes.conf)}")

model = YOLO("yolov8n.pt")
result = model(image, iou=0.9, conf=0.01)[0]

print(f"4. Loaded model, no max_det - Number of predictions: {len(result.boxes.conf)}")

Note that since the image is random, it might not always return more than one box (but usually does, since the conf is so low)

from ultralytics.

glenn-jocher avatar glenn-jocher commented on June 29, 2024

Hi @fbarbe00,

Thank you for your detailed follow-up and for providing a more minimal code example. We appreciate your effort in helping us understand and reproduce the issue. 😊

I have reviewed your code and can confirm that the behavior you're experiencing with the max_det parameter being retained across predictions is indeed unexpected. This looks like a bug that needs further investigation.

Here’s a concise summary of the issue:

  1. Setting max_det=1 limits the number of predictions to one.
  2. Subsequent predictions without max_det still return only one prediction until the model is reloaded.

Your minimal reproducible example is very helpful. We will investigate this behavior further to identify the root cause and work on a fix.

In the meantime, as a workaround, reinitializing the model before each prediction, as you mentioned, ensures that the max_det parameter does not carry over. Here’s a quick reminder of that approach:

from ultralytics import YOLO
import torch

model = YOLO("yolov8n.pt")
image = torch.rand(1, 3, 640, 640)

# Initial prediction without max_det
result = model(image, iou=0.9, conf=0.01)[0]
print(f"1. Loaded model, no max_det - Number of predictions: {len(result.boxes.conf)}")

# Prediction with max_det=1
result = model(image, iou=0.9, conf=0.01, max_det=1)[0]
print(f"2. Same model obj, max_det=1 - Number of predictions: {len(result.boxes.conf)}")

# Reinitialize model to reset parameters
model = YOLO("yolov8n.pt")
result = model(image, iou=0.9, conf=0.01)[0]
print(f"3. Reinitialized model, no max_det - Number of predictions: {len(result.boxes.conf)}")

We appreciate your patience and understanding as we work to resolve this issue. If you have any further questions or additional details to share, please feel free to let us know.

from ultralytics.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.