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

ValueError: 'onnx::Ma/' is not a valid root scope name. #147

Open
pranoyr opened this issue Nov 18, 2022 · 4 comments
Open

ValueError: 'onnx::Ma/' is not a valid root scope name. #147

pranoyr opened this issue Nov 18, 2022 · 4 comments
Labels

Comments

@pranoyr
Copy link

pranoyr commented Nov 18, 2022

Describe the bug
I am running the below code snippet and getting this error.

ValueError: 'onnx::Ma/' is not a valid root scope name. A root scope name has to match the following pattern: ^[A-Za-z0-9.][A-Za-z0-9_.\/>-]*$

To Reproduce

import os
os.environ['CUDA_VISIBLE_DEVICES'] = ''
import sys
sys.path.insert(0, '../expression_capture/')
from torchvision import models
from models.resnet18 import Fc

import torch
from pytorch2keras.converter import pytorch_to_keras



model = models.resnet18(pretrained=True).eval()



x = torch.randn(1, 3, 224, 224, requires_grad=False)
k_model = pytorch_to_keras(model, x, [(3, None, None,)], verbose=True, name_policy='short')
k_model.save('keras.h5') 

Environment (please complete the following information):

  • OS: Ubuntu 22.04
  • Python 3
  • Version v3.10
  • onnx==1.12.0
@pranoyr pranoyr added the bug label Nov 18, 2022
@balisujohn
Copy link

The first thing to try is an old version of onnx, since the pypi version of this package hasnt been updated in a very long time.

@balisujohn
Copy link

ok so I encountered this, the fix is to go into your tensorflow source in the file env/lib/python3.9/site-packages/tensorflow/python/framework/ops.py in your virtualenv and kill all the regex checks for node and scope name format. Seemed to work for me lol. As far as I can tell, tensorflow imposed new name restrictions, and you can just remove the restrictions lol(who knows if there could be unintended consequences).

@balisujohn
Copy link

Actually, even better, try setting the name_policy to "renumerate" when calling pytorch_to_keras. This fixed that error for me, without requiring such a cursed form of patch to tensorflow.

@yisong17tao
Copy link

Actually, even better, try setting the name_policy to "renumerate" when calling pytorch_to_keras. This fixed that error for me, without requiring such a cursed form of patch to tensorflow.

Thank you very much, solved my problem!

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

No branches or pull requests

3 participants