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

Need help aggregating the feature maps into smaller data #3619

Closed
rocketsfallonrocketfalls opened this issue Jun 15, 2021 · 4 comments
Closed
Labels
question Further information is requested

Comments

@rocketsfallonrocketfalls
Copy link

rocketsfallonrocketfalls commented Jun 15, 2021

Can anyone help me understand what are the dimensions of the feature vectors explicitly for and how can I use them for my application?

My actual problem:

  • I want to calculate similarity based on image features calculated by the network.
  • Using the features I obtain using yolov5m cause computational problems as I have to load these vectors for hundreds of images and perform operations on them.

In my application in particular, I get 3 sets of feature maps for a single image flowing into the Detect layer. Their dimensions are:

  1. 192 x 32 x 40
  2. 384 x 16 x 20
  3. 768 x 8 x 10

My actual question:

  • How can I downsize/dimensionally-reduce these data for similarity checking purposes?
@rocketsfallonrocketfalls rocketsfallonrocketfalls added the question Further information is requested label Jun 15, 2021
@glenn-jocher
Copy link
Member

@rocketsfallonrocketfalls you may want to see AdaptiveAvgPool2d for averaging over the last 2 spatial dimensions.

https://pytorch.org/docs/stable/generated/torch.nn.AdaptiveAvgPool2d.html

@glenn-jocher
Copy link
Member

@rocketsfallonrocketfalls 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).

yolov5/models/yolo.py

Lines 158 to 160 in 20d45aa

if feature_vis and m.type == 'models.common.SPP':
feature_visualization(x, m.type, m.i)

To receive this update:

  • Gitgit pull from within your yolov5/ directory or git clone https://github.com/ultralytics/yolov5 again
  • PyTorch Hub – Force-reload with model = torch.hub.load('ultralytics/yolov5', 'yolov5s', force_reload=True)
  • Notebooks – View updated notebooks Open In Colab Open In Kaggle
  • Dockersudo docker pull ultralytics/yolov5:latest to update your image Docker Pulls

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

@rocketsfallonrocketfalls
Copy link
Author

@glenn-jocher, @Zigars, that's great news, thanks a lot!

@rocketsfallonrocketfalls
Copy link
Author

2D Pooling seems to work fine for now :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants