open_model_zoo icon indicating copy to clipboard operation
open_model_zoo copied to clipboard

Unable to convert ResNet-50-Pytorch model

Open js333031 opened this issue 7 months ago • 6 comments

Unable to convert the downloaded model. Error:

(openvino_env) (base) testuser@clftower:~/workspace$ omz_downloader --name resnet-50-pytorch
################|| Downloading resnet-50-pytorch ||################

========== Downloading /home/testuser/workspace/public/resnet-50-pytorch/resnet50-19c8e357.pth
... 100%, 100100 KB, 32465 KB/s, 3 seconds passed

(openvino_env) (base) testuser@clftower:~/workspace$ omz_converter --name resnet-50-pytorch
========== Converting resnet-50-pytorch to ONNX
Conversion to ONNX command: /home/testuser/openvino_env/bin/python -- /home/testuser/openvino_env/lib/python3.12/site-packages/omz_tools/internal_scripts/pytorch_to_onnx.py --model-name=resnet50 --weights=/home/testuser/workspace/public/resnet-50-pytorch/resnet50-19c8e357.pth --import-module=torchvision.models --input-shape=1,3,224,224 --output-file=/home/testuser/workspace/public/resnet-50-pytorch/resnet-v1-50.onnx --input-names=data --output-names=prob

ERROR: Weights from /home/testuser/workspace/public/resnet-50-pytorch/resnet50-19c8e357.pth cannot be loaded for model resnet50! Check matching between model and weights
Cannot use ``weights_only=True`` with files saved in the legacy .tar format. In PyTorch 2.6, we changed the default value of the `weights_only` argument in `torch.load` from `False` to `True`. Re-running `torch.load` with `weights_only` set to `False` will likely succeed, but it can result in arbitrary code execution. Do it only if you got the file from a trusted source.

FAILED:
resnet-50-pytorch
(openvino_env) (base) testuser@clftower:~/workspace$ 

Steps used on Ubuntu 24.04:

sudo apt install python3.12-venv
python3 -m venv openvino_env
source openvino_env/bin/activate
python -m pip install --upgrade pip
python -m pip install openvino
python -c "from openvino import Core; print(Core().available_devices)"      #  ---- Please verify that both CPU and GPU are listed -----
pip install openvino-dev
pip install onnx
pip install torch torchvision

mkdir workspace
cd workspace

omz_downloader --name resnet-50-pytorch
omz_converter --name resnet-50-pytorch

js333031 avatar Apr 14 '25 13:04 js333031

Fixed in https://github.com/openvinotoolkit/open_model_zoo/pull/3997. Try master branch version

Wovchena avatar Apr 14 '25 13:04 Wovchena

Is there a specific pip install package available for the master branch?

js333031 avatar Apr 14 '25 14:04 js333031

# Navigate to the open_model_zoo/tools/model_tools directory
pip install --upgrade pip
pip install .

https://github.com/openvinotoolkit/open_model_zoo/tree/master/tools/model_tools#installation

Wovchena avatar Apr 14 '25 15:04 Wovchena

This would require a somewhat larger developer effort by cloning the repo, perhaps some other tools. I was hoping for something simpler like pip install <pkg name>-<pkg ver/branch>.

On Mon, Apr 14, 2025 at 11:44 AM Vladimir Zlobin @.***> wrote:

Navigate to the open_model_zoo/tools/model_tools directory

pip install --upgrade pip pip install .

https://github.com/openvinotoolkit/open_model_zoo/tree/master/tools/model_tools#installation

— Reply to this email directly, view it on GitHub https://github.com/openvinotoolkit/open_model_zoo/issues/4009#issuecomment-2802142932, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABT2PN4ZHKQ7TSQMNVQEQNT2ZPJXBAVCNFSM6AAAAAB3C6CZL6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDQMBSGE2DEOJTGI . You are receiving this because you authored the thread.Message ID: @.***> Wovchena left a comment (openvinotoolkit/open_model_zoo#4009) https://github.com/openvinotoolkit/open_model_zoo/issues/4009#issuecomment-2802142932

Navigate to the open_model_zoo/tools/model_tools directory

pip install --upgrade pip pip install .

https://github.com/openvinotoolkit/open_model_zoo/tree/master/tools/model_tools#installation

— Reply to this email directly, view it on GitHub https://github.com/openvinotoolkit/open_model_zoo/issues/4009#issuecomment-2802142932, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABT2PN4ZHKQ7TSQMNVQEQNT2ZPJXBAVCNFSM6AAAAAB3C6CZL6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDQMBSGE2DEOJTGI . You are receiving this because you authored the thread.Message ID: @.***>

js333031 avatar Apr 14 '25 17:04 js333031

@js333031 a quick workaround (as in PR listed by wovchena https://github.com/openvinotoolkit/open_model_zoo/pull/3997/files) for the latest omz version available via pip (v2024.6), would be to edit the following file on your env and add weights_only=False as shown below. Then proceed to run the omz_converter step. This worked for me using versions listed below in [1].

# path to virtual environment omz package files
/home/pse/user/venv/venv/lib/python3.12/site-packages/omz_tools/internal_scripts/pytorch_to_onnx.py

// Add: Image

Based on the following statement, I am not sure this fix would make it to the pip package (openvino-dev) as I don't think there will be any other releases for it. Maybe @Wovchena can comment if there are plans for another pip release. Hope this helps, let me know if you have any questions.

https://docs.openvino.ai/2025/documentation/legacy-features.html > Open Model ZOO "Open Model ZOO provided a collection of models prepared for use with OpenVINO, and a small set of tools enabling a level of automation for the process. Since the tools have been mostly replaced by other solutions and several other model repositories have recently grown in size and popularity, Open Model ZOO will no longer be maintained. You may still use its resources until they are fully removed."

[1]
python                 3.12.9
torch                     2.6.0
torchvision               0.21.0
onnx                      1.17.0
openvino                  2024.6.0
openvino-dev              2024.6.0

avitial avatar May 08 '25 16:05 avitial

if there are plans for another pip release

No plans

Wovchena avatar May 09 '25 07:05 Wovchena