Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

[feat] Add backbone API #204

Merged
merged 23 commits into from
Apr 7, 2021
Merged

[feat] Add backbone API #204

merged 23 commits into from
Apr 7, 2021

Conversation

tchaton
Copy link
Contributor

@tchaton tchaton commented Apr 6, 2021

What does this PR do?

@ImageClassifier.backbones(name="username/resnet18")
def fn_resnet(pretrained: bool = True):
    model = torchvision.models.resnet18(pretrained)
    backbone = nn.Sequential(*list(model.children())[:-2])
    num_features = model.fc.in_features
    # backbones need to return the num_features to build the head
    return backbone, num_features

print(ImageClassifier.available_backbones())

model = ImageClassifier(backbone="username/resnet18", num_classes=datamodule.num_classes)

Fixes #167

Before submitting

  • Was this discussed/approved via a Github issue? (no need for typos and docs improvements)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests? [not needed for typos/docs]
  • Did you verify new and existing tests pass locally with your changes?
  • If you made a notable change (that affects users), did you update the CHANGELOG?

PR review

  • Is this pull request ready for review? (if not, please submit in draft mode)

@tchaton tchaton self-assigned this Apr 6, 2021
@tchaton tchaton added this to the 0.2 milestone Apr 6, 2021
@codecov
Copy link

codecov bot commented Apr 6, 2021

Codecov Report

Merging #204 (41228ba) into master (6a4948a) will increase coverage by 0.21%.
The diff coverage is 92.12%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #204      +/-   ##
==========================================
+ Coverage   86.31%   86.53%   +0.21%     
==========================================
  Files          56       57       +1     
  Lines        2674     2732      +58     
==========================================
+ Hits         2308     2364      +56     
- Misses        366      368       +2     
Flag Coverage Δ
unittests 86.53% <92.12%> (+0.21%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
flash/data/utils.py 96.84% <ø> (-0.04%) ⬇️
flash/text/classification/model.py 93.75% <ø> (-0.19%) ⬇️
flash/vision/backbones.py 81.15% <77.77%> (-3.78%) ⬇️
flash/data/base_viz.py 98.24% <92.85%> (+2.65%) ⬆️
flash/core/model.py 93.97% <100.00%> (+0.26%) ⬆️
flash/core/registry.py 100.00% <100.00%> (ø)
flash/data/data_module.py 78.60% <100.00%> (+0.11%) ⬆️
flash/data/process.py 84.41% <100.00%> (-0.46%) ⬇️
flash/utils/imports.py 100.00% <100.00%> (ø)
flash/vision/__init__.py 100.00% <100.00%> (ø)
... and 7 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6a4948a...41228ba. Read the comment docs.

flash/core/registry.py Outdated Show resolved Hide resolved
flash/core/registry.py Outdated Show resolved Hide resolved
flash/core/registry.py Outdated Show resolved Hide resolved
flash/core/registry.py Outdated Show resolved Hide resolved
flash/core/registry.py Outdated Show resolved Hide resolved
flash/core/registry.py Show resolved Hide resolved
flash/core/registry.py Outdated Show resolved Hide resolved
Copy link
Contributor

@edgarriba edgarriba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor typing and left some general comments

flash/core/registry.py Outdated Show resolved Hide resolved
flash/vision/backbones.py Outdated Show resolved Hide resolved
flash/vision/backbones.py Outdated Show resolved Hide resolved
flash/vision/backbones.py Outdated Show resolved Hide resolved
flash/vision/backbones.py Outdated Show resolved Hide resolved
flash/vision/backbones.py Outdated Show resolved Hide resolved
flash/vision/classification/model.py Show resolved Hide resolved
flash/vision/classification/model.py Outdated Show resolved Hide resolved
tests/core/test_registry.py Outdated Show resolved Hide resolved
flash/core/model.py Outdated Show resolved Hide resolved
flash/core/model.py Outdated Show resolved Hide resolved
flash/core/model.py Outdated Show resolved Hide resolved
flash/vision/backbones.py Outdated Show resolved Hide resolved
flash/vision/classification/model.py Outdated Show resolved Hide resolved
flash/vision/detection/model.py Outdated Show resolved Hide resolved
flash/vision/detection/model.py Outdated Show resolved Hide resolved
tests/core/test_registry.py Outdated Show resolved Hide resolved
flash/core/registry.py Outdated Show resolved Hide resolved
Copy link
Contributor

@carmocca carmocca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does registering a function to multiple registries or with multiple names work properly? We should test it

flash/core/model.py Outdated Show resolved Hide resolved
tests/vision/test_backbones.py Outdated Show resolved Hide resolved
tests/core/test_registry.py Outdated Show resolved Hide resolved
tests/core/test_registry.py Outdated Show resolved Hide resolved
flash_examples/finetuning/image_classification.py Outdated Show resolved Hide resolved
flash/core/registry.py Outdated Show resolved Hide resolved
flash/core/registry.py Outdated Show resolved Hide resolved
flash/core/registry.py Outdated Show resolved Hide resolved
flash/core/registry.py Outdated Show resolved Hide resolved
flash/core/registry.py Outdated Show resolved Hide resolved
@pep8speaks
Copy link

pep8speaks commented Apr 7, 2021

Hello @tchaton! Thanks for updating this PR.

Line 120:17: W503 line break before binary operator

Comment last updated at 2021-04-07 23:11:56 UTC

@carmocca carmocca enabled auto-merge (squash) April 7, 2021 22:59
@carmocca carmocca merged commit 7853efd into master Apr 7, 2021
@carmocca carmocca deleted the backbone_api branch April 7, 2021 23:29
@@ -16,145 +29,102 @@ class FlashRegistry:

backbones = FlashRegistry("backbones")

@backbones.register_function()
@backbones
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Backbone API
6 participants