gmalivenko / pytorch2keras

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

Key error" 'Slice' #89

Open Jagadish-Kumaran opened 5 years ago

Jagadish-Kumaran commented 5 years ago

Describe the bug When i try to convert the pytorch model to keras model, I get an error saying "Key error: 'Slice'

To Reproduce

with_gpu = False net = vgg.VGG('VGG19') if with_gpu: checkpoint = torch.load('test_model.t7', map_location="cuda:0") else: checkpoint = torch.load('test_model.t7', map_location=torch.device('cpu')) net.load_state_dict(checkpoint['net']) if with_gpu: device = torch.device("cuda:0") net = net.to(device) net.eval()

Convert Pytorch Model

In[ ]:

pip install pytorch2keras

In[ ]:

Convert Pytorch Model

from pytorch2keras.converter import pytorch_to_keras from torch.autograd import Variable

input_np = np.random.uniform(0, 1, (1, 3, 256, 256)) input_var = Variable(torch.FloatTensor(input_np)) k_model = pytorch_to_keras(net, input_var, [(3,256,256,)], verbose=True)

Expected behavior A clear and concise description of what you expected to happen.

Logs DEBUG:onnx2keras:shape:Actual result: DEBUG:onnx2keras:shape:[None 512 1 1] DEBUG:onnx2keras:###### DEBUG:onnx2keras:... DEBUG:onnx2keras:Converting ONNX operation DEBUG:onnx2keras:type: Slice DEBUG:onnx2keras:node_name: 171 DEBUG:onnx2keras:node_params: {'axes': [0], 'ends': [1], 'starts': [0]} DEBUG:onnx2keras:... DEBUG:onnx2keras:Check if all inputs are available: DEBUG:onnx2keras:Check input 0 (name 170). DEBUG:onnx2keras:... found all, continue Traceback (most recent call last): File "Video_classifier_FER-Copy6.py", line 112, in k_model = pytorch_to_keras(net, input_var, [(3,256,256,)], verbose=True) File "/mnt/sde/jagadish/Anaconda3/envs/test_env/lib/python3.6/site-packages/pytorch2keras/converter.py", line 73, in pytorch_to_keras verbose=verbose, change_ordering=change_ordering) File "/mnt/sde/jagadish/Anaconda3/envs/test_env/lib/python3.6/site-packages/onnx2keras/converter.py", line 142, in onnx_to_keras AVAILABLE_CONVERTERS[node_type]( KeyError: 'Slice'

Environment (please complete the following information):