ultralytics / yolov5

YOLOv5 πŸš€ in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
50k stars 16.16k forks source link

ultralytics>=8.0.232 does not install on Yolov5 #12857

Open gilmotta3 opened 6 months ago

gilmotta3 commented 6 months ago

Search before asking

YOLOv5 Component

Other

Bug

I wonder how this was tested, the ultralytics>=8.0.232 does not install on Jetson Nano no matter what I do. This was added 2 months ago but in the past this package wasn't there . Now pip install it is broken!

pip3 install -r requirements.txt does not work anymore due to the addition of ultralytics.

Collecting ultralytics>=8.0.232 (from -r requirements.txt (line 18)) Could not find a version that satisfies the requirement ultralytics>=8.0.232 (from -r requirements.txt (line 18)) (from versions: ) No matching distribution found for ultralytics>=8.0.232 (from -r requirements.txt (line 18))

Environment

Yolov5, Jetson Nano and Ubuntu 18.04 LTS by NVIDIA, Python 3.6.9

This is a Jetson Nano with CUDA so I cannot upgrade to Pytorch 2.0,etc.

Minimal Reproducible Example

Collecting ultralytics>=8.0.232 (from -r requirements.txt (line 18)) Could not find a version that satisfies the requirement ultralytics>=8.0.232 (from -r requirements.txt (line 18)) (from versions: ) No matching distribution found for ultralytics>=8.0.232 (from -r requirements.txt (line 18))

Additional

No response

Are you willing to submit a PR?

github-actions[bot] commented 6 months ago

πŸ‘‹ Hello @gilmotta3, thank you for your interest in YOLOv5 πŸš€! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

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.

Requirements

Python>=3.8.0 with all requirements.txt installed including PyTorch>=1.8. To get started:

git clone https://github.com/ultralytics/yolov5  # clone
cd yolov5
pip install -r requirements.txt  # install

Environments

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

Status

YOLOv5 CI

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training, validation, inference, export and benchmarks on macOS, Windows, and Ubuntu every 24 hours and on every commit.

Introducing YOLOv8 πŸš€

We're excited to announce the launch of our latest state-of-the-art (SOTA) object detection model for 2023 - YOLOv8 πŸš€!

Designed to be fast, accurate, and easy to use, YOLOv8 is an ideal choice for a wide range of object detection, image segmentation and image classification tasks. With YOLOv8, you'll be able to quickly and accurately detect objects in real-time, streamline your workflows, and achieve new levels of accuracy in your projects.

Check out our YOLOv8 Docs for details and get started with:

pip install ultralytics
glenn-jocher commented 6 months ago

@gilmotta3 hello! 😊 Thank you for reaching out about the installation issue on the Jetson Nano.

It seems like there's been a misunderstanding. The ultralytics package specified in requirements.txt is intended to simplify dependencies handling but is not a separate requirement for YOLOv5 to function.

For Jetson Nano users facing this issue, a workaround is to manually edit the requirements.txt file by commenting out or removing the line containing ultralytics>=8.0.232. After modifying the file, you can proceed with pip3 install -r requirements.txt.

Please ensure that all other dependencies are compatible with your system and Python version. If you encounter any more issues or have further questions, feel free to reach out.

Thanks for being part of the YOLOv5 community! πŸš€

gilmotta3 commented 6 months ago

@glenn-jocher Hi Glen, Thank you for your quick reply. If I don't install the ultralytics as you said the detect.py does not work. so this whole thing got out of sync somehow. I am spending a whole day trying to resolve this issue there should be a better way to communicate to the developers, ultralytics>=8.0.232 should be removed or a comment in the file or somewhere it can be seen. Line 46 of the detect.py is calling ultralytics and therefore it is broken. Thank you for shedding some light into the issue.

glenn-jocher commented 6 months ago

Hi @gilmotta3, thank you for the additional context, and I’m sorry to hear about the trouble you're experiencing. 😞

Let’s try a quick fix. Please open detect.py and comment out or temporarily remove the line that calls ultralytics. It should look something like this:

# import ultralytics  # Comment out or remove this line

Then, proceed without installing the ultralytics package. If detect.py relies on functionalities that are currently unresolved due to this, it may be a recent oversight.

We're continuously working on improving YOLOv5 and sometimes issues like these can slip through. I appreciate your patience and will ensure this feedback is relayed to our development team for a closer look.

For now, please try the suggested workaround and let us know if it resolves the issue. Your feedback is valuable in helping us improve. 🌟

gilmotta3 commented 6 months ago

Hi @glenn-jocher , removing the line import ultralytics is not enough. line 47 from ultralytics.utils.plotting import Annotator needs to be addressed.

I changed it FROM from ultralytics.utils.plotting import Annotator, colors, save_one_box TO from utils.plots import Annotator, colors, save_one_box

but still getting error No Module named 'ultralytics'

It seems nobody has tested this on Jetson Nano and a lot of changes were made since.

gilmotta3 commented 6 months ago

I am also opening a ticket on NVIDIA website and suggesting Jetson Nano users not waste their time. Hopefully my experience will save them time and money.

https://forums.developer.nvidia.com/t/yolov5-no-longer-works-on-jetson-nano/288297

glenn-jocher commented 6 months ago

Hi @gilmotta3, I'm truly sorry to hear about your ongoing issues and the frustration it's causing. We aim for YOLOv5 to be accessible across various platforms, including Jetson Nano, so feedback like yours is crucial.

For the error with No Module named 'ultralytics', it seems like there could be a discrepancy in how our recent updates align with the specific environment on the Jetson Nano. We genuinely appreciate your diligence and the steps you've taken to resolve this issue.

I'll ensure this is flagged with our development team to review the compatibility with Jetson Nano. In the meantime, the modification you made seems like a step in the right direction but might require a more comprehensive fix from our side.

Thank you for your patience and for sharing your experience on the NVIDIA forums. Our goal is to support the community in navigating issues like these, and your insights are incredibly valuable in that process.

We're on it, and we'll work to address these compatibility concerns. πŸ› οΈ

github-actions[bot] commented 5 months ago

πŸ‘‹ 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 ⭐

Jarradmorden commented 5 months ago

still broken..?

glenn-jocher commented 5 months ago

@Jarradmorden hi! Could you please provide more detail on what's still not working? Any error messages or specific behaviors you're observing will help us pinpoint the issue quicker. Thanks for your collaboration and patience! πŸ˜ŠπŸ› οΈ

gilmotta3 commented 5 months ago

@glenn-jocher I'll be honest with you this is still broken, someone is not testing things before comiting the code, maybe this is an opportunity to create unit tests or something to improve the quality. Unfortunately, nobody took me seriously when I raised the issue and I don't have time to be the test engineer so I gave up YOLOv5

glenn-jocher commented 5 months ago

Hi @gilmotta3, I'm really sorry to hear about the difficulties you've encountered. We value your feedback and absolutely agree that thorough testing is crucial. We aim to continuously improve our processes, including the implementation of more comprehensive unit tests. Your experience helps us identify key areas to focus on. Thanks for bringing this to our attention, and we regret any inconvenience caused. πŸ™

fasp-2023 commented 4 months ago

Hi Glen and users of github,

I have a question about overfitting in my model. I have the following graphs: image

Whit this graphs, how can i say that my model is not in overfitting?

I used k-fold cross validation to test my overfitting with k=10. Results is below: image

Can you help me with understanding if i have overfitting?

Thank you very much.

Best Regards,

Philip

glenn-jocher commented 4 months ago

Hi Philip,

Thanks for reaching out with your graphs and the results from your k-fold cross-validation!

To determine if your model is overfitting, you can compare the training loss and validation loss as depicted in your first graph. Here are a few tips:

From your k-fold cross-validation results, check the variance in performance across different folds:

It’s great to see you are using k-fold validation, which itself is a robust method to help prevent overfitting by ensuring that your model is tested on different subsets of data.

If you're still unsure or see signs of overfitting, consider trying techniques such as adding dropout layers, increasing data augmentation, or using regularization methods.

Hope this helps! πŸ˜ŠπŸš€

fasp-2023 commented 4 months ago

Hi Glenn,

Thank you about your response.

Analyzing the graphs and k-fold information, what do you think? What is Glenn's opinion when analyzing this information?

At first glance, it doesn't seem like overfitting to me, as the dataset has been increased.

Thank you very much.

Best Regards

glenn-jocher commented 4 months ago

Hi there,

Thank you for your follow-up. Based on your description and the steps you've taken by adding more data and conducting k-fold validation, it indeed sounds like you're on the right track to mitigating overfitting. If your training and validation losses are close in value and your k-fold results show minimal variability, your model appears to generalize well.

Keep an eye on how well the model performs on entirely unseen data for the ultimate test of overfitting. Keep up the great work! πŸ˜ŠπŸ‘

fasp-2023 commented 4 months ago

I Glenn,

Thank you for your response.

Can you give your opinion, about possible overfitting of my project.

I made several tests in google colab with 50, 286, 590, 690 and 1700 images in my dataset.

The size of my dataset could be a problem in overfitting analisys, taking into account the analysis carried out in previous posts and with the graphs we analyzed as well as the k-fold cross validation?

Should I worry about this? Throughout all the tests carried out, the graphics showed normal behavior.

I look forward to your precious and valuable opinion.

Best Regards

glenn-jocher commented 4 months ago

@fasp-2023 hi there,

Thanks for reaching out with your query!

Given the variety of dataset sizes you've tested and the normal behavior observed in the graphs, it sounds like you're managing the risk of overfitting well. The use of k-fold cross-validation further supports this by ensuring your model's performance is consistent across different subsets of your data.

As long as your training and validation losses are converging and the performance across different k-folds is stable, the size of your dataset should not inherently lead to overfitting. Continue monitoring these metrics as you adjust your dataset size to ensure that the model remains robust.

Keep up the good work! πŸ˜ŠπŸ‘

kostyawhite commented 3 months ago

Hi! I found a workaround for this problem:

  1. git clone https://github.com/ultralytics/yolov5
  2. git checkout v6.2 And then requirements.txt doesn't have ultralytics in it, and I was able to run yolov5s.pt model
glenn-jocher commented 3 months ago

Hi there!

Thanks for sharing your workaround! It's great to hear that checking out an earlier version helped you bypass the issue with the requirements. Your contribution is valuable to the community, and it helps in maintaining the versatility of the YOLOv5 project. Keep up the great work! πŸ˜ŠπŸš€

fasp-2023 commented 3 months ago

Hi Glen,

I have a question about how can generate heatmaps. How i can in google colab generate heatmaps (to showcase which parts of the image the YOLOv5s6 default is focusing on while adding the modules) of a few samples with the original YOLOv5s6 and the my improved YOLOv5s6, in the final i would compare both.

Can you help me please? Do you have a quick guide to this?

Thank you very much for your help and contribution as you are a very knowledgeable person and always available to help.

Best Regards,

Philip

glenn-jocher commented 3 months ago

Hi Philip,

Thank you for your question and for your kind words about the community and the Ultralytics team! 😊

Generating heatmaps to visualize which parts of an image YOLOv5 is focusing on can be a great way to understand and compare model performance. Here’s a quick guide to help you get started with generating heatmaps in Google Colab:

  1. Install Required Libraries: Ensure you have the necessary libraries installed. You can add these to your Colab notebook:

    !pip install torch torchvision matplotlib
  2. Load Your Models: Load both the original YOLOv5s6 and your improved YOLOv5s6 models.

    import torch
    from models.yolo import Model
    
    # Load original YOLOv5s6
    model_original = torch.hub.load('ultralytics/yolov5', 'yolov5s6')
    
    # Load your improved YOLOv5s6
    model_improved = torch.load('path/to/your/improved/yolov5s6.pt')
  3. Generate Heatmaps: You can use Grad-CAM (Gradient-weighted Class Activation Mapping) to generate heatmaps. Here’s a basic implementation:

    import cv2
    import numpy as np
    import matplotlib.pyplot as plt
    from pytorch_grad_cam import GradCAM
    from pytorch_grad_cam.utils.image import show_cam_on_image
    
    def generate_heatmap(model, image_path):
       # Load and preprocess image
       img = cv2.imread(image_path)
       img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
       img_tensor = torch.from_numpy(img).permute(2, 0, 1).float().unsqueeze(0) / 255.0
    
       # Initialize Grad-CAM
       target_layers = [model.model[-1]]  # Last layer
       cam = GradCAM(model=model, target_layers=target_layers, use_cuda=False)
    
       # Generate heatmap
       grayscale_cam = cam(input_tensor=img_tensor)[0]
       heatmap = show_cam_on_image(img / 255.0, grayscale_cam, use_rgb=True)
    
       return heatmap
    
    # Generate heatmaps for both models
    heatmap_original = generate_heatmap(model_original, 'path/to/sample_image.jpg')
    heatmap_improved = generate_heatmap(model_improved, 'path/to/sample_image.jpg')
    
    # Display heatmaps
    plt.figure(figsize=(10, 5))
    plt.subplot(1, 2, 1)
    plt.title('Original YOLOv5s6')
    plt.imshow(heatmap_original)
    plt.subplot(1, 2, 2)
    plt.title('Improved YOLOv5s6')
    plt.imshow(heatmap_improved)
    plt.show()
  4. Compare Results: Visualize and compare the heatmaps to see which parts of the image each model focuses on.

Feel free to adjust the code to fit your specific needs. If you encounter any issues or have further questions, please provide a minimal reproducible example so we can assist you better. You can find more details on creating a minimal reproducible example here.

I hope this helps! Best of luck with your project, and feel free to reach out if you need further assistance.

fasp-2023 commented 3 months ago

Hi Glen,

Thanks for your fast response.

in this moment i have an error that is:

Using cache found in /root/.cache/torch/hub/ultralytics_yolov5_master YOLOv5 πŸš€ v7.0-334-g100a423b Python-3.10.12 torch-2.3.0+cu121 CPU

Fusing layers... YOLOv5s6 summary: 280 layers, 12612508 parameters, 0 gradients, 16.8 GFLOPs Adding AutoShape...

AttributeError Traceback (most recent call last)

in () 6 7 # Load your improved YOLOv5s6 ----> 8 model_improved = torch.load('/content/drive/MyDrive/Colab Notebooks/Filipe/Apresentacao/YOLOv5s6_MOD/best.pt') 2 frames /usr/local/lib/python3.10/dist-packages/torch/serialization.py in find_class(self, mod_name, name) 1437 pass 1438 mod_name = load_module_mapping.get(mod_name, mod_name) -> 1439 return super().find_class(mod_name, name) 1440 1441 # Load the data (which may in turn use persistent_load to load tensors) AttributeError: Can't get attribute 'C2F' on This after executing the code below: import torch from models.yolo import Model # Load original YOLOv5s6 model_original = torch.hub.load('ultralytics/yolov5', 'yolov5s6') # Load your improved YOLOv5s6 model_improved = torch.load('/content/drive/MyDrive/Colab Notebooks/Filipe/Apresentacao/YOLOv5s6_MOD/best.pt') ___________ The common.py file is already the one that C2F has, and the customizable functions. The yolo.py file is also updated Can you hep me to identify what is wrong? Thanks, Philip
glenn-jocher commented 3 months ago

@fasp-2023 hi Philip,

Thank you for your detailed message and for providing the code snippet. It looks like you're encountering an AttributeError related to the C2F module when trying to load your improved YOLOv5s6 model.

To help us better understand and resolve the issue, could you please provide a minimal reproducible example? This will enable us to reproduce the bug on our end and investigate a solution. You can find guidelines on creating a minimal reproducible example here.

In the meantime, here are a few steps you can take to troubleshoot the issue:

  1. Verify Compatibility: Ensure that the version of YOLOv5 you are using is compatible with the model you trained. Sometimes, custom modules like C2F may not be recognized if there are version mismatches.

  2. Update YOLOv5 Repository: Make sure you have the latest version of the YOLOv5 repository:

    !git clone https://github.com/ultralytics/yolov5
    !cd yolov5 && git pull
  3. Check Custom Modules: Ensure that any custom modules or modifications you made (like C2F) are correctly defined and imported in your scripts. You might need to explicitly import the C2F module in your script:

    from models.common import C2F
  4. Loading the Model: When loading a model with custom layers, you might need to specify the custom objects:

    import torch
    from models.common import C2F
    
    # Load your improved YOLOv5s6 with custom layers
    model_improved = torch.load('/content/drive/MyDrive/Colab Notebooks/Filipe/Apresentacao/YOLOv5s6_MOD/best.pt', map_location='cpu')

If the issue persists, please share the minimal reproducible example, and we will be happy to assist you further. Your contributions and engagement with the community are greatly appreciated!

fasp-2023 commented 2 months ago

Hi Glenn,

Thanks for your support.

We can generate Heatmaps using the image from the folder "Detect" and using the google colab to generate a Heatmap for this case?

Thanks for your fast responser.

Best Regards,

Philip

glenn-jocher commented 2 months ago

Hi Philip,

Thank you for your question and for your kind words! 😊

Yes, you can definitely generate heatmaps using images from the "Detect" folder in Google Colab. Here's a step-by-step guide to help you achieve this:

  1. Install Required Libraries: Ensure you have the necessary libraries installed in your Colab environment:

    !pip install torch torchvision matplotlib opencv-python
  2. Load Your Models: Load both the original YOLOv5s6 and your improved YOLOv5s6 models:

    import torch
    from models.yolo import Model
    
    # Load original YOLOv5s6
    model_original = torch.hub.load('ultralytics/yolov5', 'yolov5s6')
    
    # Load your improved YOLOv5s6
    model_improved = torch.load('/content/drive/MyDrive/Colab Notebooks/Filipe/Apresentacao/YOLOv5s6_MOD/best.pt', map_location='cpu')
  3. Generate Heatmaps: Use Grad-CAM to generate heatmaps. Here’s a basic implementation:

    import cv2
    import numpy as np
    import matplotlib.pyplot as plt
    from pytorch_grad_cam import GradCAM
    from pytorch_grad_cam.utils.image import show_cam_on_image
    
    def generate_heatmap(model, image_path):
       # Load and preprocess image
       img = cv2.imread(image_path)
       img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
       img_tensor = torch.from_numpy(img).permute(2, 0, 1).float().unsqueeze(0) / 255.0
    
       # Initialize Grad-CAM
       target_layers = [model.model[-1]]  # Last layer
       cam = GradCAM(model=model, target_layers=target_layers, use_cuda=False)
    
       # Generate heatmap
       grayscale_cam = cam(input_tensor=img_tensor)[0]
       heatmap = show_cam_on_image(img / 255.0, grayscale_cam, use_rgb=True)
    
       return heatmap
    
    # Path to your image in the "Detect" folder
    image_path = '/content/yolov5/runs/detect/exp/image.jpg'
    
    # Generate heatmaps for both models
    heatmap_original = generate_heatmap(model_original, image_path)
    heatmap_improved = generate_heatmap(model_improved, image_path)
    
    # Display heatmaps
    plt.figure(figsize=(10, 5))
    plt.subplot(1, 2, 1)
    plt.title('Original YOLOv5s6')
    plt.imshow(heatmap_original)
    plt.subplot(1, 2, 2)
    plt.title('Improved YOLOv5s6')
    plt.imshow(heatmap_improved)
    plt.show()

This code will generate and display heatmaps for both the original and improved YOLOv5s6 models using an image from the "Detect" folder. Adjust the image_path variable to point to the specific image you want to analyze.

If you encounter any issues or have further questions, please provide a minimal reproducible example so we can assist you better. You can find more details on creating a minimal reproducible example here.

Best of luck with your project, and feel free to reach out if you need further assistance! 😊

fasp-2023 commented 2 months ago

Hi Glen,

Thanks for your suppport.

I run my yolov5s6 code at 1 year ago. I run yesterday the same code and the same files, but metrics is a little diference. What happened? This is normal?

Thanks again.

Beste regards,

Philip

glenn-jocher commented 2 months ago

Hi Philip,

Thank you for reaching out and for your kind words!

It's not uncommon to observe slight variations in metrics when re-running the same code and files after a significant period, such as a year. Several factors could contribute to these differences:

  1. Library Updates: Updates to libraries like torch, numpy, or even YOLOv5 itself can introduce changes in the underlying algorithms or default settings, leading to variations in results.

  2. Hardware Differences: If you are running the code on different hardware (e.g., different GPU or CPU), this can also cause slight differences in performance metrics.

  3. Randomness in Training: Even with the same seed, some operations might introduce slight randomness, especially in deep learning models.

To help us investigate further, could you please provide a minimal reproducible example of your code? This will enable us to reproduce the issue on our end and provide a more accurate diagnosis. You can find guidelines on creating a minimal reproducible example here.

Additionally, please ensure that you are using the latest versions of torch and the YOLOv5 repository. This will help rule out any issues that may have been fixed in recent updates.

# Update YOLOv5 repository
!git clone https://github.com/ultralytics/yolov5
!cd yolov5 && git pull

# Install the latest version of torch
!pip install torch --upgrade

If you continue to experience discrepancies, please share the details, and we'll be happy to assist you further.

Best regards and happy coding! 😊

github-actions[bot] commented 1 month ago

πŸ‘‹ 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 ⭐