pytorch2keras icon indicating copy to clipboard operation
pytorch2keras copied to clipboard

KeyError in convert_gather

Open lhfowl opened this issue 5 years ago • 1 comments

Hello,

I'm trying to convert a version of MobileNetv2 to keras, and the conversion almost finishes but fails in convert_gather. I'm trying to figure out how the code gets the 'name in state_dict' entry so I can try to debug... FYI, I am not using your mobilinet.py script in the tests directory.

Here's a snippet of the last few lines of the terminal output/the error:


('graph node:', u'MobileNetV2') ('node id:', u'1331') ('type:', u'onnx::Gather') ('inputs:', ['1329', '1328']) ('outputs:', [u'MobileNetV2']) ('name in state_dict:', '1329.1328') ('attrs:', {u'axis': 0}) ('is_terminal:', False) Converting embedding ... Traceback (most recent call last): File "mobilinet.py", line 96, in k_model = pytorch_to_keras(net, input_var, (3, 32, 32,), verbose=True) File "/home/Desktop/pytorch2keras/pytorch2keras/converter.py", line 317, in pytorch_to_keras names File "/home/Desktop/pytorch2keras/pytorch2keras/embedding_layers.py", line 33, in convert_gather W = weights[weights_name].numpy() KeyError: '1329.1328.weight'

lhfowl avatar Apr 24 '19 20:04 lhfowl

I have the same problem. The code uses the same function to convert both Gather and Embedding layer. It seems that the Gather layer doesn't have something called 'weight' while the Embedding layer does.

So far I know that Keras use K.gather() function to do the embedding thing. But I just can't figure out how to generate the wight for a Gather layer.

Ciyou avatar May 24 '19 15:05 Ciyou