Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

predict images and video test quantized model #847

Open
1 task done
minstai11 opened this issue Sep 24, 2024 · 19 comments
Open
1 task done

predict images and video test quantized model #847

minstai11 opened this issue Sep 24, 2024 · 19 comments
Labels
question A HUB question that does not involve a bug

Comments

@minstai11
Copy link

Search before asking

Question

I am interested in why model.predict are processing video and prediction in a way that 320x240 it is using 192x224 rescaling. Why is is done by the method? our model is trained on 224x224x3 input. Do we need to rescale image to represent right bounding boxes?
video 1/1 (frame 2583/2686) C:\output_video_3.mp4: 192x224 1 car, 20.0ms
One more question how to test quantized model in tflite format? I get wrong bounding boxes.

Additional

No response

@minstai11 minstai11 added the question A HUB question that does not involve a bug label Sep 24, 2024
@UltralyticsAssistant
Copy link
Member

👋 Hello @minstai11, thank you for raising an issue about the Ultralytics HUB 🚀! An Ultralytics engineer will be with you shortly, but in the meantime, you can explore our comprehensive HUB Docs for guidance:

If this is a 🐛 Bug Report, please provide a Minimum Reproducible Example (MRE) to help us debug the issue effectively.

For your questions regarding image rescaling and testing quantized models, the more details you can provide about your environment and model configurations, the better we can assist.

Thank you for your patience and engagement with the Ultralytics community! 😊

@minstai11
Copy link
Author

minstai11 commented Sep 27, 2024

I am using virtual environment and VS code tool. I am using simple script
import torch
from ultralytics import YOLO

Load the YOLO model (this can be YOLOv5 or YOLOv8 depending on what you're using)
model = YOLO(r'C:\Git\embedded-ai\custom_clean.pt') # 'yolov8n.pt' is an example for the YOLOv8 small model

Run inference on a video
results = model.predict(source=r'C:\Git\embedded-ai\output_video_2.mp4', save=True, conf=0.6)

@glenn-jocher
Copy link
Member

@minstai11 hello! 😊

It looks like you're working with a YOLO model in a virtual environment using VS Code. Let's address your questions:

Image Rescaling

The rescaling you observed (e.g., 192x224) might be due to the model's internal processing to maintain aspect ratio or optimize performance. If your model was trained on 224x224 inputs, ensure your inference input size matches this to get accurate bounding boxes. You can specify the imgsz parameter in your inference call to control this:

results = model.predict(source=r'C:\Git\embedded-ai\output_video_2.mp4', save=True, conf=0.6, imgsz=224)

Testing Quantized Models

For testing quantized models in TFLite format, ensure you're using the correct input size and preprocessing steps. If bounding boxes are incorrect, verify that the model's input dimensions and preprocessing match those used during training.

If you suspect a bug, please ensure you're using the latest version of the Ultralytics packages. If the issue persists, providing a Minimum Reproducible Example (MRE) can help us assist you better.

Feel free to reach out with more details if needed. Happy coding! 🚀

@minstai11
Copy link
Author

Hi, could be that prediction try to keep aspect ration because I feed 320x240 video?

@minstai11
Copy link
Author

still I get video 1/1 (frame 2686/2686) C:\Git\embedded-ai\output_video_2.mp4: 192x224 1 car, 26.0ms
Speed: 0.7ms preprocess, 23.2ms inference, 0.7ms postprocess per image at shape (1, 3, 192, 224) does it mean that images from video was resized to 224x224 because model trained on that input resolution, then predictions is done and then resized to 192x224? I want to understand what is going under predict method?

@minstai11
Copy link
Author

Could it be that in ultralytics HUB preview mode does not work as expected, I see that model.predict method works much better than model preview in ultralytics hub platform. ?

@pderrenger
Copy link
Member

Hello @minstai11! 😊

Thanks for reaching out. It's possible that differences in performance between the model.predict method and the Ultralytics HUB preview could be due to variations in preprocessing, input size, or other configurations.

Key Points to Consider:

  1. Input Size and Aspect Ratio:

    • The model.predict method might adjust the input size to maintain aspect ratio, which can affect the output. Ensure that both the HUB and your local environment are using the same input dimensions.
  2. Preprocessing Steps:

    • Differences in preprocessing (e.g., normalization, resizing) between your local setup and the HUB could lead to variations in results.
  3. Model Configuration:

    • Double-check that the model configurations (e.g., confidence threshold, IoU) are consistent across both environments.

Debugging Steps:

  • Consistency: Ensure that the same model version and parameters are used in both the HUB and your local environment.
  • Latest Versions: Verify that you're using the latest versions of the Ultralytics packages to avoid any known issues.

If you continue to experience discrepancies, please provide more details or a Minimum Reproducible Example (MRE) to help us investigate further.

Feel free to reach out with any more questions. Happy experimenting! 🚀

@minstai11
Copy link
Author

Same package and same model, but I get different result on HUB and model.predict with the same image.

predict

@pderrenger
Copy link
Member

Hello! 😊

Thanks for bringing this to our attention. Differences in results between the HUB and model.predict can sometimes occur due to variations in preprocessing or configuration settings.

Here are a few things to check:

  1. Input Size: Ensure that both environments are using the same input size. You can specify this in your local setup using the imgsz parameter.

  2. Preprocessing: Verify that any preprocessing steps (e.g., normalization) are consistent between the HUB and your local environment.

  3. Model Parameters: Double-check that the confidence threshold and IoU settings are the same in both cases.

  4. Latest Versions: Make sure you're using the latest versions of the Ultralytics packages to avoid any known issues.

If the issue persists, please provide more details or a Minimum Reproducible Example (MRE) to help us investigate further.

Feel free to reach out with any more questions. We're here to help! 🚀

@minstai11
Copy link
Author

image size, which I have used

results_img = model.predict(source=r'C:\Users\stamin\Desktop\image.jpg', save=True, conf=0.6, imgsz=224)
Settings, model parameters are the same.
model.predict gives 0.96 confidence, while in preview mode you can see less than 0.5 and bounding box far away from model.predict.

@minstai11
Copy link
Author

Another issue I have done the same training with Yolo 5 and I got different results with the same data. Different recall graphs and metrics. how could you explane it? it differs by 2 weeks when I trained

@pderrenger
Copy link
Member

Hello @minstai11! 😊

Differences in results between YOLOv5 and YOLOv8 can occur due to several factors:

  1. Model Architecture: YOLOv5 and YOLOv8 have different architectures and improvements, which can lead to variations in performance and metrics.

  2. Training Environment: Ensure that the training environments, including hardware and software versions, are consistent. Even minor differences can affect outcomes.

  3. Hyperparameters: Double-check that all hyperparameters, such as learning rate and batch size, are identical across both training sessions.

  4. Data Augmentation: Variations in data augmentation techniques can also lead to different results. Make sure these settings are consistent.

  5. Package Versions: Verify that you're using the latest versions of the Ultralytics packages. Updates may include optimizations or bug fixes that could impact results.

If you continue to see discrepancies, consider running a controlled experiment to isolate the variables. Feel free to share more details if you need further assistance. Happy experimenting! 🚀

@minstai11
Copy link
Author

No, I have done draining on the same Yolo v5 model.

@pderrenger
Copy link
Member

Hello! 😊

Thanks for the clarification. If you've trained the same YOLOv5 model and are seeing different results, here are a few things to consider:

  1. Environment Consistency: Ensure that your training environment, including hardware and software versions, is consistent across both training sessions.

  2. Data Variability: Check if there were any changes in the dataset, such as additional data or modifications, that might affect the training outcome.

  3. Hyperparameters: Verify that all hyperparameters, like learning rate and batch size, are identical in both training runs.

  4. Package Versions: Make sure you're using the latest versions of the Ultralytics packages. Updates might include optimizations or bug fixes that could impact results.

If the issue persists, try running a controlled experiment to isolate variables. Feel free to share more details if you need further assistance. We're here to help! 🚀

@minstai11
Copy link
Author

No, it is the same data , I have used the same Ultralytics hub, but in 2 weeks difference in time with the same data and my new trained model does not work but previous training has worked, what happened?

@minstai11
Copy link
Author

diff
same model, same dataset different PC, how it could happen? only one day differ and only different PC, also I set pre trained and hub

@pderrenger
Copy link
Member

Hello! 😊

Thanks for reaching out and providing the details. It sounds like you're experiencing some unexpected results with your model training on different PCs. Here are a few things to consider:

  1. Environment Differences: Even if the PCs seem similar, there might be differences in hardware (e.g., GPU type) or software (e.g., CUDA, cuDNN versions) that could affect training outcomes. Double-check these components to ensure consistency.

  2. Random Seed: If a random seed wasn't set during training, variations in initialization or data shuffling could lead to different results. Consider setting a fixed seed for reproducibility:

    import torch
    import random
    import numpy as np
    
    random.seed(42)
    np.random.seed(42)
    torch.manual_seed(42)
  3. Package Versions: Ensure both PCs are using the same versions of all relevant packages, including Ultralytics, PyTorch, and any dependencies.

  4. Resource Availability: Differences in available resources (e.g., RAM, GPU memory) might impact training, especially if one PC is under more load than the other.

If the issue persists, try running a controlled experiment with a fixed seed and consistent environment settings. Feel free to share more details if you need further assistance. We're here to help! 🚀

@minstai11
Copy link
Author

Do you understand I am using Ultralytics HUB, I set the same settings ?!!!

@sergiuwaxmann
Copy link
Member

@minstai11 It could be different versions of torch, ultralytics, etc.

Some models may not be deterministic, particularly when used with GPUs. GPU CUDA ops are inherently optimized to the point where speed matters more than reproducibility in some default settings, so it may just be this.

https://pytorch.org/docs/stable/notes/randomness.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question A HUB question that does not involve a bug
Projects
None yet
Development

No branches or pull requests

5 participants