facebookresearch / pytorchvideo

A deep learning library for video understanding research.
https://pytorchvideo.org/
Apache License 2.0
3.33k stars 411 forks source link

Feature Extraction #51

Open gpmarques opened 3 years ago

gpmarques commented 3 years ago

🚀 Feature

It would be great if the models API had an easy way to instantiate a model with the purpose of feature extraction!

Meanwhile, is there any workaround?

kalyanvasudev commented 3 years ago

I'm not sure if I follow you fully. Do mean a way to load models without heads heads? (i.e, only stems and backbone)

gpmarques commented 3 years ago

Yes, that would work. Because nowadays if I load a pre-trained model, how can I get the output from intermediate layers?

danikv commented 3 years ago

you can just access the model final block by model.blocks[-1] , depending on the network type you can change the number of output features or the entire block. For my use case I only changed the projection layer which is basically the number of output features:

  model_name = "slow_r50"
  model = torch.hub.load("facebookresearch/pytorchvideo", model=model_name, pretrained=True)
  model.blocks[-1].proj = nn.Linear(2048, 10)
kalyanvasudev commented 3 years ago

@gpmarques , we are also working on an API update for models which would allow you to not load head and get the intermediate features from the backbone.

gpmarques commented 3 years ago

@danikv ooh, ok I get it! Thanks.

@kalyanvasudev that's great to know! Thanks for the support.