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.

Converter error: list assignment index out of range

See original GitHub issue

I was trying to convert a pytorch model into keras via onnx. The pytorch model was successfully converted to onnx format. I tried two versions of the model:

  1. Model with bilinear upsampling, with align_corners=False and opset 9,
  2. Model with bilinear upsampling, with align_corners=True and opset 11

In both cases i got same errors, if i set change_ordering=False Code:-

import onnx
from onnx2keras import onnx_to_keras

# Load ONNX model
onnx_model = onnx.load('SINet_320_opbnup.onnx')

# Call the converter (input - is the main model input name, can be different for your model)
k_model = onnx_to_keras(onnx_model, ['data'])
k_model.save('SINet.h5')

Error:-

WARNING:onnx2keras:avgpool:Unable to use `same` padding. Add ZeroPadding2D layer to fix shapes.
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-27-b90de0dc63bc> in <module>()
      6 
      7 # Call the converter (input - is the main model input name, can be different for your model)
----> 8 k_model = onnx_to_keras(onnx_model, ['data'])
      9 k_model.save('SINet.h5')

6 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/layers/advanced_activations.py in build(self, input_shape)
    141     if self.shared_axes is not None:
    142       for i in self.shared_axes:
--> 143         param_shape[i - 1] = 1
    144     self.alpha = self.add_weight(
    145         shape=param_shape,

IndexError: list assignment index out of range

If i set change_ordering=True, i get another error:-


ValueError Traceback (most recent call last) <ipython-input-29-bf041c502013> in <module>() 6 7 # Call the converter (input - is the main model input name, can be different for your model) ----> 8 k_model = onnx_to_keras(onnx_model, [‘data’], change_ordering=True) 9 k_model.save(‘SINet.h5’)

5 frames /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/base_layer.py in set_weights(self, weights) 1824 raise ValueError( 1825 'Layer weight shape %s not compatible with provided weight ’ -> 1826 ‘shape %s’ % (ref_shape, weight.shape)) 1827 weight_value_tuples.append((param, weight)) 1828 weight_index += 1

ValueError: Layer weight shape (1, 1, 160) not compatible with provided weight shape (12, 1, 1)

Models:-

SINet_320.zip

I ran the model checker successfully i.e onnx.checker.check_model(onnx_model) The original pytorch model contains PRelu activations. How can we fix this issue and convert the model into keras format??

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
Andredancecommented, Oct 24, 2020

I think this is primarily a lack of time. ReduceMax operation was added yesterday. I will look better to onnx “Resize” operation and maybe will add its support to the library. There is no similar functionality in keras. I’ll see what can be done about it.

0reactions
anilsathyan7commented, Oct 24, 2020

I think the ‘resize’ operator in onnx seems to handle bilinear resize functionality. It seems to give good results during testing/inference, with align corners=True. Earlier it used to be upsample layer(ie. nearest only). Similarly onnx seems to support reduce max operation. Keras also seems to have these layers anyway, so are they just integration issues?

Read more comments on GitHub >

github_iconTop Results From Across the Web

IndexError: list assignment index out of range - STechies
IndexError: list assignment index out of range, In python this type of error occurs when we try to assign a value to list...
Read more >
Fix IndexError: list assignment index out of range in Python
As we are trying to assign an element with a higher index we get the index out of range error. The solution is...
Read more >
Python Indexerror: list assignment index out of range Solution
In python, lists are mutable as the elements of a list can be modified. But if you try to modify a value whose...
Read more >
Python indexerror: list assignment index out of range Solution
The message “list assignment index out of range” tells us that we are trying to assign an item to an index that does...
Read more >
Python: IndexError: list assignment index out of range - date ...
My attempted code is below. I'm trying to import DAX price data from Yahoo and work with it but I can't get past...
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