onnx / models

A collection of pre-trained, state-of-the-art models in the ONNX format
http://onnx.ai/models/
Apache License 2.0
7.84k stars 1.4k forks source link

ShuffleNet Folder Readme file information is correct? #558

Open IzanCatalan opened 2 years ago

IzanCatalan commented 2 years ago

Ask a Question

Hi, I would like to know how I can follow the instructions to download shufflenet models from pytorch, convert them to onnx format and quantize to int8?

Question

Explain your question here.

I would like to follow the instructions from https://github.com/onnx/models/tree/main/vision/classification/shufflenet readme file.

I want to download pytorch models because the shufflenet models already in /shufflenet/model folder do not have batch size support which from pytorch you can select by using "dynamic_axes" and save the model.

This flag it is used in https://github.com/onnx/models/blob/main/vision/classification/shufflenet/ShufflenetV2-export.py line 152, however the script fails.

In addition, later, you can read on Readme file how to quantize the model, by using :

_bash run_tuning.sh --input_model=path/to/model \ # model path as *.onnx --config=shufflenetv2.yaml \ --outputmodel=path/to/save

However, I can't find "run_tuning.sh" and shufflenetv2.yaml files.

Moreover, I would like to know why in shufflenet models like "shufflenet-v2-12.onnx" you cannot find the input size in all modules, only at the input (1x3x224x224) with no batch size (picture 1) while using "mobilnetv2-12.onnx" (picture 2) model from https://github.com/onnx/models/tree/main/vision/classification/mobilenet/model you can see how the input has (batch_sizex3x224x224). It is also different from "densenet-12.onnx" file (picture 3) from https://github.com/onnx/models/tree/main/vision/classification/densenet-121 where before each module, you can see the input size.

Is this normal?, i would like to follow the Readme from shufflenet repo in order to chech if the sufflenet models are right o not. Perhaps someone has done it before and can help me?

imagen imagen imagen

Further information

Relevant Area (e.g. model usage, backend, best practices, pre-/post- processing, converters): I'm just using "ShufflenetV2-export.py" but already fails because an HTTP Error 300, I dont know if there is some links wrong, but no model from line 15 of the script works:

Traceback (most recent call last): File "ShufflenetV2-export.py", line 178, in shufflenetv2_test() File "ShufflenetV2-export.py", line 129, in shufflenetv2_test model = torch.hub.load(github_repo, model, pretrained=True) File "/home/izcagal/.local/lib/python3.8/site-packages/torch/hub.py", line 397, in load repo_or_dir = _get_cache_or_reload(repo_or_dir, force_reload, verbose, skip_validation) File "/home/izcagal/.local/lib/python3.8/site-packages/torch/hub.py", line 192, in _get_cache_or_reload download_url_to_file(url, cached_file, progress=False) File "/home/izcagal/.local/lib/python3.8/site-packages/torch/hub.py", line 452, in download_url_to_file u = urlopen(req) File "/usr/lib/python3.8/urllib/request.py", line 222, in urlopen return opener.open(url, data, timeout) File "/usr/lib/python3.8/urllib/request.py", line 531, in open response = meth(req, response) File "/usr/lib/python3.8/urllib/request.py", line 640, in http_response response = self.parent.error( File "/usr/lib/python3.8/urllib/request.py", line 569, in error return self._call_chain(args) File "/usr/lib/python3.8/urllib/request.py", line 502, in _call_chain result = func(args) File "/usr/lib/python3.8/urllib/request.py", line 649, in http_error_default raise HTTPError(req.full_url, code, msg, hdrs, fp) urllib.error.HTTPError: HTTP Error 300: Multiple Choices

I update my python to python 3.8 and now I have another output to ShufflenetV2-export.py:

Downloading: "https://github.com/pytorch/vision/zipball/v0.5.0" to /mnt/beegfs/gap/izcagal/.cache/torch/hub/v0.5.0.zip /mnt/beegfs/gap/izcagal/.local/lib/python3.8/site-packages/torch/hub.py:218: UserWarning: The ref v0.5.0 is ambiguous. Perhaps it is both a tag and a branch in the repo? Torchhub will now assume that it's a branch. You can disambiguate tags and branches by explicitly passing refs/heads/branch_name or refs/tags/tag_name as the ref. That might require using skip_validation=True. warnings.warn( /mnt/beegfs/gap/izcagal/.local/lib/python3.8/site-packages/torchvision/models/_utils.py:208: UserWarning: The parameter 'pretrained' is deprecated since 0.13 and will be removed in 0.15, please use 'weights' instead. warnings.warn( /mnt/beegfs/gap/izcagal/.local/lib/python3.8/site-packages/torchvision/models/_utils.py:223: UserWarning: Arguments other than a weight enum or None for 'weights' are deprecated since 0.13 and will be removed in 0.15. The current behavior is equivalent to passing weights=ShuffleNet_V2_X0_5_Weights.IMAGENET1K_V1. You can also use weights=ShuffleNet_V2_X0_5_Weights.DEFAULT to get the most up-to-date weights. warnings.warn(msg) Downloading: "https://download.pytorch.org/models/shufflenetv2_x0.5-f707e7126e.pth" to /mnt/beegfs/gap/izcagal/.cache/torch/hub/checkpoints/shufflenetv2_x0.5-f707e7126e.pth 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 5.28M/5.28M [00:00<00:00, 7.76MB/s] Traceback (most recent call last): File "ShufflenetV2-export.py", line 178, in shufflenetv2_test() File "ShufflenetV2-export.py", line 142, in shufflenetv2_test model_dir, data_dir = save_model('shufflenetv2', model.cpu(), input_1, output_1, File "ShufflenetV2-export.py", line 86, in save_model torch.onnx.export(model, inputs, model_dir, verbose=True, input_names=input_names, TypeError: export() got an unexpected keyword argument 'example_outputs'

Thank!

jcwchen commented 2 years ago

Hi @IzanCatalan,

Moreover, I would like to know why in shufflenet models like "shufflenet-v2-12.onnx" you cannot find the input size in all modules, only at the input (1x3x224x224) with no batch size (picture 1) while using "mobilnetv2-12.onnx" (picture 2) model from https://github.com/onnx/models/tree/main/vision/classification/mobilenet/model you can see how the input has (batch_sizex3x224x224). It is also different from "densenet-12.onnx" file (picture 3) from https://github.com/onnx/models/tree/main/vision/classification/densenet-121 where before each module, you can see the input size. Is this normal?

Please note that not every models in ONNX model zoo has batch_size input, especially for old contributed models. There are effort to enable old models to support bacth_size: https://github.com/onnx/models/pull/542. Going forward I think at least we should required new added models to have batch_size.

torch.onnx.export(model, inputs, model_dir, verbose=True, input_names=input_names, TypeError: export() got an unexpected keyword argument 'example_outputs'

Seems like a question for the converter -- what's your PyTorch version?

crackedpotato007 commented 1 year ago

Unable to convert GPT2 on torch 1.13.0 with same error