question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

KeyError                                  Traceback (most recent call last)
<ipython-input-22-6be9743dbc2b> in <module>
      1 from onnx2keras import onnx_to_keras
      2 model=onnx.load("optimized_mobile_pydnet.onnx")
----> 3 k_model = onnx_to_keras(onnx_model=model, input_names=['input'])

~/anaconda3/envs/e2r/lib/python3.7/site-packages/onnx2keras/converter.py in onnx_to_keras(onnx_model, input_names, input_shapes, name_policy, verbose, change_ordering)
    179             lambda_funcs,
    180             node_name,
--> 181             keras_names
    182         )
    183         if isinstance(keras_names, list):

~/anaconda3/envs/e2r/lib/python3.7/site-packages/onnx2keras/operation_layers.py in convert_clip(node, params, layers, lambda_func, node_name, keras_name)
     29     input_0 = ensure_tf_type(layers[node.input[0]], name="%s_const" % keras_name)
     30 
---> 31     if params['min'] == 0:
     32         logger.debug("Using ReLU({0}) instead of clip".format(params['max']))
     33         layer = keras.layers.ReLU(max_value=params['max'], name=keras_name)

KeyError: 'min'```

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:14

github_iconTop GitHub Comments

5reactions
dtlam26commented, Jan 15, 2021

I have come here to rescue you guys. This bug is because of conflict among version of onnx and the onnx torch use to export. By inspecting the file in onnx, you guys con fine the key here is not match with the newest onnx ops converter. The correct dict now is here:

AVAILABLE_CONVERTERS = {
    'Conv': convert_conv,
    'ConvTranspose': convert_convtranspose,
    'Relu': convert_relu,
    'Elu': convert_elu,
    'LeakyRelu': convert_lrelu,
    'Sigmoid': convert_sigmoid,
    'Tanh': convert_tanh,
    'Selu': convert_selu,
    'Clip': convert_clip,
    'Exp': convert_exp,
    'Log': convert_log,
    'Softmax': convert_softmax,
    'PRelu': convert_prelu,
    'ReduceMax': convert_reduce_max,
    'ReduceSum': convert_reduce_sum,
    'ReduceMean': convert_reduce_mean,
    'Pow': convert_pow,
    'Slice': convert_slice,
    'Squeeze': convert_squeeze,
    'Expand': convert_expand,
    'Sqrt': convert_sqrt,
    'Split': convert_split,
    'Cast': convert_cast,
    'Floor': convert_floor,
    'Identity': convert_identity,
    'ArgMax': convert_argmax,
    'ReduceL2': convert_reduce_l2,
    'Max': convert_max,
    'Min': convert_min,
    'Mean': convert_mean,
    'Div': convert_elementwise_div,
    'Add': convert_elementwise_add,
    'Sum': convert_elementwise_add,
    'Mul': convert_elementwise_mul,
    'Sub': convert_elementwise_sub,
    'Gemm': convert_gemm,
    'MatMul': convert_gemm,
    'Transpose': convert_transpose,
    'Constant': convert_constant,
    'BatchNormalization': convert_batchnorm,
    'InstanceNormalization': convert_instancenorm,
    'Dropout': convert_dropout,
    'LRN': convert_lrn,
    'MaxPool': convert_maxpool,
    'AveragePool': convert_avgpool,
    'GlobalAveragePool': convert_global_avg_pool,
    'Shape': convert_shape,
    'Gather': convert_gather,
    'Unsqueeze': convert_unsqueeze,
    'Concat': convert_concat,
    'Reshape': convert_reshape,
    'Pad': convert_padding,
    'Flatten': convert_flatten,
    'Upsample': convert_upsample,
}

Therefore, you can edit the line in here as the correct node_type in the dict (ie when it returns to min/Resize as Min/Upsample). This can easily be done by editing the source file of onnx2keras. It may also ask you to change the node_params as the Upsample ask for size param as scales. For detail, pls look in here

2reactions
e2r-htzcommented, Sep 10, 2020

Also KeyError: 'Resize'

Read more comments on GitHub >

github_iconTop Results From Across the Web

KeyError: 'min' · Issue #79 · gmalivenko/onnx2keras - GitHub
For the clip operator, it seems that it support for onnx operator set <=6, where min and max are at the attribute. However,...
Read more >
Python KeyError Exceptions and How to Handle Them
The Python KeyError is a type of LookupError exception and denotes that there was an issue retrieving the key you were looking for....
Read more >
KeyError : 411 when trying to find minimum value in a dictionary
I need to find the value of i for which value of A is minimum in the below code. But it is giving...
Read more >
What is KeyError in Python? Dictionary and Handling Them
Now let us see what a key error is. KeyError in Python is raised when you attempt to access a key that is...
Read more >
How to fix Python KeyError Exceptions in simple steps?
Know about Python KeyError Exception. And learn how to handle exceptions in Python. A detailed guide to Errors and Exceptions in Python.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found