Closed xinxin342 closed 4 years ago
Hello @xinxin342, thank you for your interest in our work! Please visit our Custom Training Tutorial to get started, and see our Jupyter Notebook , Docker Image, and Google Cloud Quickstart Guide for example environments.
If this is a bug report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.
If this is a custom model or data training question, please note Ultralytics does not provide free personal support. As a leader in vision ML and AI, we do offer professional consulting, from simple expert advice up to delivery of fully customized, end-to-end production solutions for our clients, such as:
For more information please visit https://www.ultralytics.com.
@xinxin342 we are open to PRs, so if you would like to work on this and submit a PR we'd be happy to review!
@ xinxin342我们对PR保持开放,因此,如果您要从事此工作并提交PR,我们将很高兴进行审查!
Sorry, I'm completely out of my depth, but I see that it looks like YOLOv4 can do this.
@xinxin342 feature map visualization is something you can inject into the model forward function at the location of your choosing. It's up to you exactly where in the model you'd want to visualize this, as there are hundreds of layers and thousands of maps.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
@xinxin342 good news 😃! Feature map visualization was added ✅ in PR #3804 by @Zigars today. This allows for visualizing feature maps from any part of the model from any function (i.e. detect.py, train.py, test.py). Feature maps are saved as *.png files in runs/features/exp directory. To turn on feature visualization set feature_vis=True
in the model forward method and define the layer you want to visualize (default is SPP layer).
To receive this update:
git pull
from within your yolov5/
directory or git clone https://github.com/ultralytics/yolov5
againmodel = torch.hub.load('ultralytics/yolov5', 'yolov5s', force_reload=True)
sudo docker pull ultralytics/yolov5:latest
to update your image Thank you for spotting this issue and informing us of the problem. Please let us know if this update resolves the issue for you, and feel free to inform us of any other issues you discover or feature requests that come to mind. Happy trainings with YOLOv5 🚀!
Can you tell me more about how to implement the feature maps functionality? I assumed from above that, if we're after the SPP layer, we just needed to go into yolo.py and change visualize=False to True in: def _forward_once(self, x, profile=False, visualize=True). Clearly this isn't enough. What am I missing?
@MLDavies 👋 Hello! Thanks for asking about feature visualization. YOLOv5 🚀 features can be visualized through all stages of the model from input to output. To visualize features from a given source run detect.py
with the --visualize
flag:
python detect.py --weights yolov5s.pt --source data/images/bus.jpg --visualize
An example Notebook visualizing bus.jpg features with YOLOv5s is shown below:
All stages are visualized by default, each with its own PNG showing the first 32 feature maps output from that stage. You can open any PNG for a closer look. For example the first 32 feature maps of the Focus() layer output are shown in stage0_Focus_features.png
:
Feature maps may be customized by updating the feature_visualization()
function in utils/plots.py
:
https://github.com/ultralytics/yolov5/blob/bb5ebc290e5d630a081d7cbc5a9725ed8cea0a24/utils/plots.py#L403-L427
Good luck 🍀 and let us know if you have any other questions!
Perfect. Love yolov5! Ya, I was (mistakenly) trying to call --visualize on train.py rather than detect.py. Thanks for what you do, and for your responses.
@glenn-jocher I run the following script python detect.py --weights yolov5s.pt --source data/images/bus.jpg --visualize
. Instead of obtaining results as you shown, here how it looks for stage22_Concat_features
@wanglegoc --visualize works correctly. I just tested right now:
@glenn-jocher can we use this feature for yolov4 architecture ? if not what are the changes to be made to the code
@abhigoku10 The feature map visualization is specific to the YOLOv5 architecture and is not directly compatible with YOLOv4. Porting this feature to YOLOv4 would require significant modifications to the codebase, including changes to the network architecture, model forward method, and visualization logic. If you are interested in adding feature map visualization to YOLOv4, I recommend referring to the YOLOv5 implementation as a reference and making the necessary adaptations to the YOLOv4 codebase. Good luck!
🚀 Feature
Maybe we can add one more function to Yolov5 that can conveniently show the feature maps of convolutional layers and detection layers?
Motivation
Pitch
So we can visually see where the model's attention is.
Alternatives
Additional context