-
Notifications
You must be signed in to change notification settings - Fork 709
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
Feature Extractor Refactor #451
Feature Extractor Refactor #451
Conversation
Please let me know if this looks good @samet-akcay |
@ashishbdatta, there will probably be merge conflicts due to #453. I'll review it anyway, and let you know |
I'd be in the favour of supporting any layer but it might be tricky with this new design as timm requires layer indices. Because the model isn't initialized, it is hard to know the layer id which corresponds to the name. Here is an idea - Instead of splitting based on layers:
- block 1: 1
- block 2: 2
- block 3: 3 layers:
- avgpool: 4 Since we only need the id, the layer key here might be unnecessary, it would make it readable for the users. As this will be a breaking change we can club this with the CLI upgrade and make it part of the 0.4.x release. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with Ashwin that it would be good to support any layer. Maybe we could write a function that maps the layer name to out_index used by timm.create_model.
We could do something like def _map_layer_to_idx(self) -> List[int]:
idx = []
# Create temp model to search child nodes
features = timm.create_model(
backbone,
pretrained,
features_only,
)
for i in self.layers
# Search children nodes and return index they are found at
idx.append(list(dict(features.named_children()).keys()).index(i))
return idx Only problem is that this would return indices of For e.g., in a |
…on incase this changes for future models; added documentation to layer name -> indices function
…eatures this allows the user to get pooled/unpooled features or change pooling if needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests should pass with these changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for migrating the feature extractor.
Thanks @ashishbdatta. Looking good! |
Description
FeatureExtractor
class to leverage models fromtimm
rather thantorchvision
. By usingtimm
we can easily access the features we care about rather than relying onforward_hooks
Changes
Checklist