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

run torchvision_test, got KeyError: 'Shape not implemented yet' #41

Closed
yangji307 opened this issue Apr 12, 2023 · 6 comments
Closed

Comments

@yangji307
Copy link

yangji307 commented Apr 12, 2023

env as below:
python 3.7
numpy 1.21.6
onnx 1.12.0
onnx-simplifier 0.4.19
onnxruntime 1.14.1
opencv-python 4.7.0.72
protobuf 3.19.0
pytest 7.2.2
tensorboard 2.11.2
tensorboard-data-server 0.6.1
tensorboard-plugin-wit 1.8.1
tensorflow 2.11.0
tensorflow-estimator 2.11.0
tensorflow-intel 2.11.0
tensorflow-io-gcs-filesystem 0.31.0
torch 1.9.0
torchvision 0.10.0+cu102

fail to run test_deeplabv3, and got the fllowing error msg:

`
torchvison_test.py::test_deeplabv3 FAILED [100%]
torchvison_test.py:31 (test_deeplabv3)
@pytest.mark.filterwarnings('ignore::UserWarning')
@pytest.mark.filterwarnings('ignore::DeprecationWarning')
def test_deeplabv3():
model = torchvision.models.segmentation.deeplabv3_resnet50(False)
onnx_model_path = os.path.join(MODEL_ROOT, "deeplabv3_resnet50.onnx")
torch.onnx.export(model, torch.randn(1, 3, 512, 1024), onnx_model_path, opset_version=13)

  error = onnx_converter(onnx_model_path, need_simplify = False, output_path = MODEL_ROOT, target_formats = ['tflite'])

torchvison_test.py:38:


converter.py:21: in onnx_converter
keras_model = keras_builder(model_proto, native_groupconv)


onnx_model = ir_version: 6
producer_name: "pytorch"
producer_version: "1.9"
graph {
node {
input: "input.1"
output: "363"...im {
dim_param: "Resize600_dim_3"
}
}
}
}
}
}
opset_import {
version: 13
}

native_groupconv = False

def keras_builder(onnx_model, native_groupconv:bool=False):

    conv_layers.USE_NATIVE_GROUP_CONV = native_groupconv

    model_graph = onnx_model.graph

    '''
        init onnx model's build-in tensors
    '''
    onnx_weights = dict()
    for initializer in model_graph.initializer:
        onnx_weights[initializer.name] = numpy_helper.to_array(initializer)

    '''
        build input nodes
    '''
    tf_tensor, input_shape = {}, []
    for inp in model_graph.input:
        input_shape = [x.dim_value for x in inp.type.tensor_type.shape.dim]
        if input_shape == []:
            continue
        batch_size = 1 if input_shape[0] <= 0 else input_shape[0]
        input_shape = input_shape[2:] + input_shape[1:2]
        tf_tensor[inp.name] = keras.Input(shape=input_shape, batch_size=batch_size)

    '''
        build model inline node by iterate onnx nodes.
    '''
    for node in model_graph.node:
        op_name, node_inputs, node_outputs = node.op_type, node.input, node.output
        op_attr = decode_node_attribute(node)

        tf_operator = OPERATOR.get(op_name)
        if tf_operator is None:
          raise KeyError(f"{op_name} not implemented yet")

E KeyError: 'Shape not implemented yet'

utils\builder.py:75: KeyError

`

@yangji307 yangji307 changed the title run torchvision_test got errorKeyError: 'Shape not implemented yet' run torchvision_test, got KeyError: 'Shape not implemented yet' Apr 12, 2023
@MPolaris
Copy link
Owner

please make need_simplify = True and try again.

@yangji307
Copy link
Author

yangji307 commented Apr 12, 2023

please make need_simplify = True and try again.

i have tried, but got the same error. T_T
image

@MPolaris
Copy link
Owner

make sure onnx-simplifier has installed correctly.
check it by:

python -c 'import onnxsim'

@yangji307
Copy link
Author

make sure onnx-simplifier has installed correctly. check it by:

python -c 'import onnxsim'

i debug the code, and find something wrong while simplifying the onnx model, is there any problem with my environment?
image

@MPolaris
Copy link
Owner

make sure onnx-simplifier has installed correctly. check it by:

python -c 'import onnxsim'

i debug the code, and find something wrong while simplifying the onnx model, is there any problem with my environment? image

I cannot reproduce the error.
It seems onnx model is invaild model, please use netron check it.
And, you can try that using onnx and 'onnxruntime' to load model by yourself.
onnxsim is rely on onnxruntime

@MPolaris
Copy link
Owner

fixed, please pull latest code and try again

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

No branches or pull requests

2 participants