ultralytics / yolov5

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

Dear author, can you provide a visualization scheme for YOLOV5 feature graphs during detect.py? Thank you! #2259

Closed 113HQ closed 3 years ago

113HQ commented 3 years ago

๐Ÿš€ Feature

Motivation

Pitch

Alternatives

Additional context

github-actions[bot] commented 3 years ago

๐Ÿ‘‹ Hello @113HQ, 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 screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom training โ“ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

For business inquiries or professional support requests please visit https://www.ultralytics.com or email Glenn Jocher at glenn.jocher@ultralytics.com.

Requirements

Python 3.8 or later with all requirements.txt dependencies installed, including torch>=1.7. To install run:

$ pip install -r requirements.txt

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

CI CPU testing

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), testing (test.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit.

glenn-jocher commented 3 years ago

@113HQ well, what features do you want to visualize exactly? The models typically have hundreds of layers and each layer has hundreds of feature maps.

113HQ commented 3 years ago

Example๏ผŒthe three nodes of the PANet(#17ใ€#20ใ€#23)

---Original--- From: "Glenn Jocher"<notifications@github.com> Date: Mon, Feb 22, 2021 03:40 AM To: "ultralytics/yolov5"<yolov5@noreply.github.com>; Cc: "113HQ"<948107836@qq.com>;"Mention"<mention@noreply.github.com>; Subject: Re: [ultralytics/yolov5] Dear author, can you provide a visualization scheme for YOLOV5 feature graphs during detect.py? Thank you! (#2259)

@113HQ well, what features do you want to visualize exactly? The models typically have hundreds of layers and each layer has hundreds of feature maps.

โ€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

glenn-jocher commented 3 years ago

@113HQ yes but this is what i mean, within each of these 3 stages (17, 20 and 23) there are very many feature maps. If we take yolov5l.yaml for example, layer 17 has 256 feature maps, layer 20 has 512 and layer 23 has 1024 feature maps. So there are almost 1800 feature maps that you can look at in just the YOLOv5l output layers (for a single input image).

https://github.com/ultralytics/yolov5/blob/master/models/yolov5l.yaml

113HQ commented 3 years ago

Yes๏ผŒI know. I just want to know what the feature maps inside look like. Can we just choose layer 17 as an example? (for a single input image)

---Original--- From: "Glenn Jocher"<notifications@github.com> Date: Mon, Feb 22, 2021 12:15 PM To: "ultralytics/yolov5"<yolov5@noreply.github.com>; Cc: "113HQ"<948107836@qq.com>;"Mention"<mention@noreply.github.com>; Subject: Re: [ultralytics/yolov5] Dear author, can you provide a visualization scheme for YOLOV5 feature graphs during detect.py? Thank you! (#2259)

@113HQ yes but this is what i mean, within each of these 3 stages (17, 20 and 23) there are very many feature maps. If we take yolov5l.yaml for example, layer 17 has 256 feature maps, 20 has 512 and 23 has 1024 feature maps. So there are almost 1800 feature maps that you can look at in just the YOLOv5l output layers (for a single input image).

https://github.com/ultralytics/yolov5/blob/master/models/yolov5l.yaml

โ€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

glenn-jocher commented 3 years ago

@113HQ well, yes its certainly possible to build a visualizer. You could make maybe a 4x3 matplotlib grid, put the original image in the top left subplot, then in each of the rows put the first 3 feature maps from the output layers. You could do this by updating the model forward method to capture the outputs at the layers you were interested in, then it's just a matter of plotting and displaying them nicely. The place you'd capture the feature maps is here. I don't have a lot of free time to work on this, but if you want to get started and submit a PR that would great! https://github.com/ultralytics/yolov5/blob/095d2c11d89892cd9c0c4d034cd1c768a0dba11c/models/yolo.py#L120-L136

glenn-jocher commented 3 years ago

@113HQ BTW, a single feature map may be in my opinion a shallow set of information, as you are looking at a 2d spatial slice but are not aptly observing relationships across the feature space (as the convolutions do).

I guess an analogy is that you would be viewing the R, G, B layers of a color image by themselves, when it helps to view them together to get the complete picture.

113HQ commented 3 years ago

Ok๏ผŒI''ll have a try. Thanks

---Original--- From: "Glenn Jocher"<notifications@github.com> Date: Mon, Feb 22, 2021 13:04 PM To: "ultralytics/yolov5"<yolov5@noreply.github.com>; Cc: "113HQ"<948107836@qq.com>;"Mention"<mention@noreply.github.com>; Subject: Re: [ultralytics/yolov5] Dear author, can you provide a visualization scheme for YOLOV5 feature graphs during detect.py? Thank you! (#2259)

@113HQ BTW, a single feature map may be in my opinion a shallow set of information, as you are looking at a 2d spatial slice but are not aptly observing relationships across the feature space (as the convolutions do).

I guess an analogy is that you would be viewing the R, G, B layers of a color image by themselves, when it helps to view them together to get the complete picture.

โ€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

JiaLim98 commented 3 years ago

Hi @glenn-jocher,

Do you have any image for the entire architecture of YOLOv5? For example: image obtained from this link.

If you do not have a nicely plotted one, a hand sketched version will do as well, I can make it nicely myself. I have looked through all YOLOv5 publications but none of them has one image regarding the architecture. I guess getting one from you is much straightforward, otherwise making one will have misunderstanding issues and draw it wrongly. Hope you have one :D.

Many thanks for the great work on YOLOv5!

zhiqwang commented 3 years ago

Hi @JiaLim98 ,

Maybe you could check #280 and this (yolov5s release 3.1 specially).

JiaLim98 commented 3 years ago

Hi @zhiqwang,

Thank you so much! Do you have one for v4.0? because my work uses only v4.0. To my knowledge, there are major changes in the architecture between v3.1 and v4.0 right?

JiaLim98 commented 3 years ago

I found one following the blog you attached, here. Is this correct?

Just to double confirm, @glenn-jocher, do you agree with the diagrams plotted? Do those directly reflect what YOLOv5 is doing?

glenn-jocher commented 3 years ago

@JiaLim98 yes, there were architectural changes between v3.1 and v4.0: the C3() modules replaced CSPBottleneck() modules, and SiLU() replaced HardSwish(). We actually haven't plotted the model ourselves, we typically just use the model yaml files a first order approximation of the structure, and also use Netron to view the block diagram (sometimes looks better with ONNX exported models than the pytorch ones), and sometimes the interactive TF graph view is useful also (when it works): https://github.com/ultralytics/yolov5/blob/7a6870b81f31db40b06d2e899801febbeed96696/train.py#L324

The linked models are good too, they seem correct.

github-actions[bot] commented 3 years ago

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.

WANGCHAO1996 commented 3 years ago

Ok๏ผŒI''ll have a try. Thanks โ€ฆ ---Original--- From: "Glenn Jocher"<notifications@github.com> Date: Mon, Feb 22, 2021 13:04 PM To: "ultralytics/yolov5"<yolov5@noreply.github.com>; Cc: "113HQ"<948107836@qq.com>;"Mention"<mention@noreply.github.com>; Subject: Re: [ultralytics/yolov5] Dear author, can you provide a visualization scheme for YOLOV5 feature graphs during detect.py? Thank you! (#2259) @113HQ BTW, a single feature map may be in my opinion a shallow set of information, as you are looking at a 2d spatial slice but are not aptly observing relationships across the feature space (as the convolutions do). I guess an analogy is that you would be viewing the R, G, B layers of a color image by themselves, when it helps to view them together to get the complete picture. โ€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

Ok๏ผŒI''ll have a try. Thanks โ€ฆ ---Original--- From: "Glenn Jocher"<notifications@github.com> Date: Mon, Feb 22, 2021 13:04 PM To: "ultralytics/yolov5"<yolov5@noreply.github.com>; Cc: "113HQ"<948107836@qq.com>;"Mention"<mention@noreply.github.com>; Subject: Re: [ultralytics/yolov5] Dear author, can you provide a visualization scheme for YOLOV5 feature graphs during detect.py? Thank you! (#2259) @113HQ BTW, a single feature map may be in my opinion a shallow set of information, as you are looking at a 2d spatial slice but are not aptly observing relationships across the feature space (as the convolutions do). I guess an analogy is that you would be viewing the R, G, B layers of a color image by themselves, when it helps to view them together to get the complete picture. โ€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

Hello, have you realized the visualization of feature map? Thank you

glenn-jocher commented 3 years ago

@WANGCHAO1996 @zhiqwang @113HQ @JiaLim98 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).

https://github.com/ultralytics/yolov5/blob/20d45aa4f18d7df7148fc6dd69a9c0607003f004/models/yolo.py#L158-L160

To receive this update:

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 ๐Ÿš€!

layer_8_SPP_features