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

Add latest TorchVision models on fastai #3791

Merged
merged 1 commit into from
Sep 14, 2022
Merged

Conversation

datumbox
Copy link
Contributor

@datumbox datumbox commented Sep 12, 2022

Fixes #3789

Implements a variation of option 2 as discussed on the issue:

  • We remove automatically any submodule imported in torchvision.models such as detection, video etc.
  • We remove any callable that is not a model such as get_weights(), list_models() etc
  • Exposes only TorchVision's model builders, model classes and model weights.
  • Cleans up after itself to avoid exposing variables.
  • Works across TorchVision versions and is compatible with static analysis / IDEs.

Here are all the imports using the latest TorchVision main:

from fastai.vision.models.tvm import *

for a in list(globals().keys()):
    print(a)
Output
__name__
__doc__
__package__
__loader__
__spec__
__annotations__
__builtins__
__file__
__cached__
alexnet
AlexNet
AlexNet_Weights
ConvNeXt
ConvNeXt_Tiny_Weights
ConvNeXt_Small_Weights
ConvNeXt_Base_Weights
ConvNeXt_Large_Weights
convnext_tiny
convnext_small
convnext_base
convnext_large
DenseNet
DenseNet121_Weights
DenseNet161_Weights
DenseNet169_Weights
DenseNet201_Weights
densenet121
densenet161
densenet169
densenet201
EfficientNet
EfficientNet_B0_Weights
EfficientNet_B1_Weights
EfficientNet_B2_Weights
EfficientNet_B3_Weights
EfficientNet_B4_Weights
EfficientNet_B5_Weights
EfficientNet_B6_Weights
EfficientNet_B7_Weights
EfficientNet_V2_S_Weights
EfficientNet_V2_M_Weights
EfficientNet_V2_L_Weights
efficientnet_b0
efficientnet_b1
efficientnet_b2
efficientnet_b3
efficientnet_b4
efficientnet_b5
efficientnet_b6
efficientnet_b7
efficientnet_v2_s
efficientnet_v2_m
efficientnet_v2_l
googlenet
GoogLeNet
GoogLeNetOutputs
GoogLeNet_Weights
Inception3
InceptionOutputs
Inception_V3_Weights
inception_v3
MNASNet
MNASNet0_5_Weights
MNASNet0_75_Weights
MNASNet1_0_Weights
MNASNet1_3_Weights
mnasnet0_5
mnasnet0_75
mnasnet1_0
mnasnet1_3
MobileNetV2
MobileNet_V2_Weights
mobilenet_v2
MobileNetV3
MobileNet_V3_Large_Weights
MobileNet_V3_Small_Weights
mobilenet_v3_large
mobilenet_v3_small
RegNet
RegNet_Y_400MF_Weights
RegNet_Y_800MF_Weights
RegNet_Y_1_6GF_Weights
RegNet_Y_3_2GF_Weights
RegNet_Y_8GF_Weights
RegNet_Y_16GF_Weights
RegNet_Y_32GF_Weights
RegNet_Y_128GF_Weights
RegNet_X_400MF_Weights
RegNet_X_800MF_Weights
RegNet_X_1_6GF_Weights
RegNet_X_3_2GF_Weights
RegNet_X_8GF_Weights
RegNet_X_16GF_Weights
RegNet_X_32GF_Weights
regnet_y_400mf
regnet_y_800mf
regnet_y_1_6gf
regnet_y_3_2gf
regnet_y_8gf
regnet_y_16gf
regnet_y_32gf
regnet_y_128gf
regnet_x_400mf
regnet_x_800mf
regnet_x_1_6gf
regnet_x_3_2gf
regnet_x_8gf
regnet_x_16gf
regnet_x_32gf
ResNet
ResNet18_Weights
ResNet34_Weights
ResNet50_Weights
ResNet101_Weights
ResNet152_Weights
ResNeXt50_32X4D_Weights
ResNeXt101_32X8D_Weights
ResNeXt101_64X4D_Weights
Wide_ResNet50_2_Weights
Wide_ResNet101_2_Weights
resnet18
resnet34
resnet50
resnet101
resnet152
resnext50_32x4d
resnext101_32x8d
resnext101_64x4d
wide_resnet50_2
wide_resnet101_2
ShuffleNetV2
ShuffleNet_V2_X0_5_Weights
ShuffleNet_V2_X1_0_Weights
ShuffleNet_V2_X1_5_Weights
ShuffleNet_V2_X2_0_Weights
shufflenet_v2_x0_5
shufflenet_v2_x1_0
shufflenet_v2_x1_5
shufflenet_v2_x2_0
SqueezeNet
SqueezeNet1_0_Weights
SqueezeNet1_1_Weights
squeezenet1_0
squeezenet1_1
VGG
VGG11_Weights
VGG11_BN_Weights
VGG13_Weights
VGG13_BN_Weights
VGG16_Weights
VGG16_BN_Weights
VGG19_Weights
VGG19_BN_Weights
vgg11
vgg11_bn
vgg13
vgg13_bn
vgg16
vgg16_bn
vgg19
vgg19_bn
VisionTransformer
ViT_B_16_Weights
ViT_B_32_Weights
ViT_L_16_Weights
ViT_L_32_Weights
ViT_H_14_Weights
vit_b_16
vit_b_32
vit_l_16
vit_l_32
vit_h_14
SwinTransformer
Swin_T_Weights
Swin_S_Weights
Swin_B_Weights
Swin_V2_T_Weights
Swin_V2_S_Weights
Swin_V2_B_Weights
swin_t
swin_s
swin_b
swin_v2_t
swin_v2_s
swin_v2_b

Static analysis / IDE intelligence works:
image

Overall it's not the most elegant solution but it checks several of the boxes we discussed. Unfortunately, we are constrained by our Backwards compatibility guarantees and the fact that we can't pin fastai to the latest TorchVision version. If you would like to explore other ideas, I am happy to close this and send another PR.

cc @jph00

@jph00
Copy link
Member

jph00 commented Sep 13, 2022

Yes, it is a big ugly! But looks like it does the job, and doesn't seem too hard to maintain. I hope you might consider adding __all__ in the future to make this kind of thing easier (and to support interactive use more generally).

Many thanks for the PR. Great to see all this terrific models in tvm nowadays.

@datumbox
Copy link
Contributor Author

@jph00 I see some failures but they seem unrelated. Let me know if you need me to check/change something.

Yes, it is a big ugly! But looks like it does the job, and doesn't seem too hard to maintain. I hope you might consider adding all in the future to make this kind of thing easier (and to support interactive use more generally).

I agree. I'll speak with the team to see if we can add a models.backbones or models.classification space. It's probably going to take multiple versions until you can use it (unless you pin fastai to the latest PyTorch version which I probably suspect you don't want to do). I'll let you know when we add something like this and follow up with more contributions.

Looking forward working with you closer on the future!

@jph00 jph00 merged commit b3f2580 into fastai:master Sep 14, 2022
@datumbox datumbox deleted the add_tv_models branch September 14, 2022 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose more of TorchVision's backbones via fastai.vision.models
2 participants