Skip to content

Adding min_size to classification and video models #5223

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

Merged
merged 6 commits into from
Jan 20, 2022

Conversation

f-parfenov
Copy link
Contributor

@f-parfenov f-parfenov commented Jan 19, 2022

Fixes #5199, I have added the min_size to classification and video model.

The unit test has been updated and passes for all targeted models.

To obtain the min_size values (including the newer models and the video models) I have adapted the following script from #3944 :

import torch

import test_models as TM
from torchvision.prototype import models

def binarysearch(min_, max_, model):
    while min_ < max_:
        mid = min_ + (max_ - min_) // 2
        success = True
        try:
            _ = model(torch.zeros((1, 3, mid, mid)))
        except Exception as e:
            success = False
        if success:
            max_ = mid      # try smaller
        else:
            min_ = mid + 1  # try bigger
    return min_ # or max_ since max_ == min_ now.

def binarsearch_video(min_, max_, model):
    while min_ < max_:
        mid = min_ + (max_ - min_) // 2
        success = True
        try:
            _ = model(torch.zeros((1, 3, 1, mid, mid)))
        except Exception as e:
            success = False
        if success:
            max_ = mid      # try smaller
        else:
            min_ = mid + 1  # try bigger
    return min_ # or max_ since max_ == min_ now.


if __name__ == "__main__":
    classification_prototype_models = (TM.get_models_from_module(models)
    + TM.get_models_from_module(models.quantization))

    min_dim = 1
    max_dim = 224


    for model in classification_prototype_models:
        eval_model = model(pretrained=False).eval()
        _ = eval_model(torch.zeros((1, 3, max_dim, max_dim)))

        min_viable = binarysearch(min_dim, max_dim, eval_model)
        print(f'Model: {model.__name__} \tMin viable shape = (1, 3, {min_viable}, {min_viable})')


    video_prototype_models = TM.get_models_from_module(models.video)


    for video_model in video_prototype_models:
        eval_model = video_model().eval()
        _ = eval_model(torch.zeros((1, 3, 1, max_dim, max_dim)))

        min_viable = binarsearch_video(min_dim, max_dim, eval_model)
        print(f'Model: {video_model.__name__} \tMin viable shape = (1, 3, 1, {min_viable}, {min_viable})')

Which gave me the following values:

Model: alexnet 	Min viable shape = (1, 3, 63, 63)
Model: densenet121 	Min viable shape = (1, 3, 29, 29)
Model: densenet161 	Min viable shape = (1, 3, 29, 29)
Model: densenet169 	Min viable shape = (1, 3, 29, 29)
Model: densenet201 	Min viable shape = (1, 3, 29, 29)
Model: efficientnet_b0 	Min viable shape = (1, 3, 1, 1)
Model: efficientnet_b1 	Min viable shape = (1, 3, 1, 1)
Model: efficientnet_b2 	Min viable shape = (1, 3, 1, 1)
Model: efficientnet_b3 	Min viable shape = (1, 3, 1, 1)
Model: efficientnet_b4 	Min viable shape = (1, 3, 1, 1)
Model: efficientnet_b5 	Min viable shape = (1, 3, 1, 1)
Model: efficientnet_b6 	Min viable shape = (1, 3, 1, 1)
Model: efficientnet_b7 	Min viable shape = (1, 3, 1, 1)
Model: googlenet 	Min viable shape = (1, 3, 15, 15)
Model: inception_v3 	Min viable shape = (1, 3, 75, 75)
Model: mnasnet0_5 	Min viable shape = (1, 3, 1, 1)
Model: mnasnet0_75 	Min viable shape = (1, 3, 1, 1)
Model: mnasnet1_0 	Min viable shape = (1, 3, 1, 1)
Model: mnasnet1_3 	Min viable shape = (1, 3, 1, 1)
Model: mobilenet_v2 	Min viable shape = (1, 3, 1, 1)
Model: mobilenet_v3_large 	Min viable shape = (1, 3, 1, 1)
Model: mobilenet_v3_small 	Min viable shape = (1, 3, 1, 1)
Model: regnet_y_400mf 	Min viable shape = (1, 3, 1, 1)
Model: regnet_y_800mf 	Min viable shape = (1, 3, 1, 1)
Model: regnet_y_1_6gf 	Min viable shape = (1, 3, 1, 1)
Model: regnet_y_3_2gf 	Min viable shape = (1, 3, 1, 1)
Model: regnet_y_8gf 	Min viable shape = (1, 3, 1, 1)
Model: regnet_y_16gf 	Min viable shape = (1, 3, 1, 1)
Model: regnet_y_32gf 	Min viable shape = (1, 3, 1, 1)
Model: regnet_y_128gf 	Min viable shape = (1, 3, 1, 1)
Model: regnet_x_400mf 	Min viable shape = (1, 3, 1, 1)
Model: regnet_x_800mf 	Min viable shape = (1, 3, 1, 1)
Model: regnet_x_1_6gf 	Min viable shape = (1, 3, 1, 1)
Model: regnet_x_3_2gf 	Min viable shape = (1, 3, 1, 1)
Model: regnet_x_8gf 	Min viable shape = (1, 3, 1, 1)
Model: regnet_x_16gf 	Min viable shape = (1, 3, 1, 1)
Model: regnet_x_32gf 	Min viable shape = (1, 3, 1, 1)
Model: resnet18 	Min viable shape = (1, 3, 1, 1)
Model: resnet34 	Min viable shape = (1, 3, 1, 1)
Model: resnet50 	Min viable shape = (1, 3, 1, 1)
Model: resnet101 	Min viable shape = (1, 3, 1, 1)
Model: resnet152 	Min viable shape = (1, 3, 1, 1)
Model: resnext50_32x4d 	Min viable shape = (1, 3, 1, 1)
Model: resnext101_32x8d 	Min viable shape = (1, 3, 1, 1)
Model: wide_resnet50_2 	Min viable shape = (1, 3, 1, 1)
Model: wide_resnet101_2 	Min viable shape = (1, 3, 1, 1)
Model: shufflenet_v2_x0_5 	Min viable shape = (1, 3, 1, 1)
Model: shufflenet_v2_x1_0 	Min viable shape = (1, 3, 1, 1)
Model: shufflenet_v2_x1_5 	Min viable shape = (1, 3, 1, 1)
Model: shufflenet_v2_x2_0 	Min viable shape = (1, 3, 1, 1)
Model: squeezenet1_0 	Min viable shape = (1, 3, 21, 21)
Model: squeezenet1_1 	Min viable shape = (1, 3, 17, 17)
Model: vgg11 	Min viable shape = (1, 3, 32, 32)
Model: vgg11_bn 	Min viable shape = (1, 3, 32, 32)
Model: vgg13 	Min viable shape = (1, 3, 32, 32)
Model: vgg13_bn 	Min viable shape = (1, 3, 32, 32)
Model: vgg16 	Min viable shape = (1, 3, 32, 32)
Model: vgg16_bn 	Min viable shape = (1, 3, 32, 32)
Model: vgg19 	Min viable shape = (1, 3, 32, 32)
Model: vgg19_bn 	Min viable shape = (1, 3, 32, 32)
Model: vit_b_16 	Min viable shape = (1, 3, 224, 224)
Model: vit_b_32 	Min viable shape = (1, 3, 224, 224)
Model: vit_l_16 	Min viable shape = (1, 3, 224, 224)
Model: vit_l_32 	Min viable shape = (1, 3, 224, 224)
Model: googlenet 	Min viable shape = (1, 3, 15, 15)
Model: inception_v3 	Min viable shape = (1, 3, 75, 75)
Model: mobilenet_v2 	Min viable shape = (1, 3, 1, 1)
Model: mobilenet_v3_large 	Min viable shape = (1, 3, 1, 1)
Model: resnet18 	Min viable shape = (1, 3, 1, 1)
Model: resnet50 	Min viable shape = (1, 3, 1, 1)
Model: resnext101_32x8d 	Min viable shape = (1, 3, 1, 1)
Model: shufflenet_v2_x0_5 	Min viable shape = (1, 3, 1, 1)
Model: shufflenet_v2_x1_0 	Min viable shape = (1, 3, 1, 1)
Model: r3d_18 	Min viable shape = (1, 3, 1, 1, 1)
Model: mc3_18 	Min viable shape = (1, 3, 1, 1, 1)
Model: r2plus1d_18 	Min viable shape = (1, 3, 1, 1, 1)

@datumbox

cc @datumbox @bjuncek

@facebook-github-bot
Copy link

facebook-github-bot commented Jan 19, 2022

💊 CI failures summary and remediations

As of commit a38ef88 (more details on the Dr. CI page):


None of the CI failures appear to be your fault 💚



🚧 1 ongoing upstream failure:

These were probably caused by upstream breakages that are not fixed yet.


This comment was automatically generated by Dr. CI (expand for details).

Please report bugs/suggestions to the (internal) Dr. CI Users group.

Click here to manually regenerate this comment.

Copy link
Contributor

@datumbox datumbox left a comment

Choose a reason for hiding this comment

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

@f-parfenov The changes look good. I only left 2 minor comments, let me know what you think.

Copy link
Contributor

@datumbox datumbox left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @f-parfenov! The failing test on prototype is unrelated. I'll merge once all other tests pass.

@datumbox datumbox merged commit c27bed4 into pytorch:main Jan 20, 2022
facebook-github-bot pushed a commit that referenced this pull request Jan 26, 2022
Summary:
* Adding min_size as a required field.

* Adding min_size to classification models (quantized and not)

* Adding min_size to video models meta.

* Moving min_size to _COMMON_META

* Fixing extra line

Reviewed By: jdsgomes, prabhat00155

Differential Revision: D33739383

fbshipit-source-id: 4984d7aebd0e46d8ef9c769b553e8f0faea91654

Co-authored-by: Vasilis Vryniotis <[email protected]>
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.

Add minimum input image size to the model meta-data
3 participants