gmalivenko / pytorch2keras

PyTorch to Keras model convertor
https://pytorch2keras.readthedocs.io/en/latest/
MIT License
857 stars 143 forks source link

pytorch2keras convert prelu layer fail #121

Open luan1412167 opened 4 years ago

luan1412167 commented 4 years ago

Describe the bug A clear and concise description of what the bug is. Hi there, I'm using your pytorch2keras and facing the following error. Thanks for your support DEBUG:onnx2keras:###### DEBUG:onnx2keras:... DEBUG:onnx2keras:Converting ONNX operation DEBUG:onnx2keras:type: PRelu DEBUG:onnx2keras:node_name: 338 DEBUG:onnx2keras:node_params: {'change_ordering': True, 'name_policy': 'short'} DEBUG:onnx2keras:... DEBUG:onnx2keras:Check if all inputs are available: DEBUG:onnx2keras:Check input 0 (name 336). DEBUG:onnx2keras:Check input 1 (name 337). DEBUG:onnx2keras:... found all, continue Traceback (most recent call last): File "/home/dmp/Silent-Face-Anti-Spoofing/src/utils/cvtpytorch2keras.py", line 134, in <module> k_model = pytorch_to_keras(anti_model.model, input_var, input_shapes=[(3, 112, 112,)], change_ordering=True, verbose=True, name_policy='short') File "/home/dmp/Downloads/pytorch2keras/pytorch2keras/converter.py", line 83, in pytorch_to_keras verbose=verbose, change_ordering=change_ordering) File "/home/dmp/Silent-Face-Anti-Spoofing/luandd/lib/python3.6/site-packages/onnx2keras-0.0.22-py3.6.egg/onnx2keras/converter.py", line 181, in onnx_to_keras keras_names File "/home/dmp/Silent-Face-Anti-Spoofing/luandd/lib/python3.6/site-packages/onnx2keras-0.0.22-py3.6.egg/onnx2keras/activation_layers.py", line 173, in convert_prelu layers[node_name] = prelu(input_0) File "/home/dmp/Silent-Face-Anti-Spoofing/luandd/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/base_layer.py", line 824, in __call__ self._maybe_build(inputs) File "/home/dmp/Silent-Face-Anti-Spoofing/luandd/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/base_layer.py", line 2153, in _maybe_build self.set_weights(self._initial_weights) File "/home/dmp/Silent-Face-Anti-Spoofing/luandd/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/base_layer.py", line 1341, in set_weights 'provided weight shape ' + str(w.shape)) ValueError: Layer weight shape (1, 1, 56) not compatible with provided weight shape (32, 1, 1)

To Reproduce Snippet of your code ` input_np = np.random.uniform(0, 1, (1, 3, 112, 112)) input_var = Variable(torch.FloatTensor(input_np))

k_model = pytorch_to_keras(anti_model.model, input_var, input_shapes=[(3, 112, 112,)], change_ordering=True, verbose=True, name_policy='short') 

` This is my pytorch model https://drive.google.com/file/d/18NMAcPh2ZJwaWZZ-JxvZZOWOllskygSq/view?usp=sharing Expected behavior A clear and concise description of what you expected to happen.

Logs If applicable, add error message to help explain your problem.

Environment (please complete the following information):

Additional context Add any other context about the problem here.