pytorch2keras icon indicating copy to clipboard operation
pytorch2keras copied to clipboard

keyError:'31_np'

Open Dreamgang opened this issue 5 years ago • 3 comments

Describe the bug KeyError: '31_np'.

To Reproduce `class PCN2(nn.Module):

def __init__(self):
    super().__init__()
    self.conv1 = nn.Conv2d(3, 20, kernel_size=3, stride=1)
    self.conv2 = nn.Conv2d(20, 40, kernel_size=3, stride=1)
    self.conv3 = nn.Conv2d(40, 70, kernel_size=2, stride=1)
    self.fc = nn.Linear(70*3*3, 140)
    self.rotate = nn.Linear(140, 3)
    self.cls_prob = nn.Linear(140, 2)
    self.bbox = nn.Linear(140, 3)
    self.mp = nn.MaxPool2d(kernel_size=3, stride=2)

def forward(self, x):
    batch_size = x.size(0)
    x = self.conv1(x)
    x = F.pad(x, (0, 1, 0, 1))
    x = F.relu(self.mp(x), inplace=True)
    x = self.conv2(x)
    x = F.pad(x, (0, 1, 0, 1))
    x = F.relu(self.mp(x), inplace=True)
    x = F.relu(self.conv3(x), inplace=True)
    x = x.view(batch_size, -1)
    x = F.relu(self.fc(x), inplace=True)
    cls_prob = F.softmax(self.cls_prob(x), dim=1)
    rotate = F.softmax(self.rotate(x), dim=1)
    bbox = self.bbox(x)
    return cls_prob, rotate, bbox`

Expected behavior graph node: PCN2 node id: 32 type: onnx::Reshape inputs: ['27', '31'] outputs: ['PCN2'] name in state_dict: 27.31 attrs: {} is_terminal: False Converting reshape ... Traceback (most recent call last): File "D:/Projects/pcn/convert_pb.py", line 57, in k_model = pytorch_to_keras(model, input_var, [(3, None, None,)], verbose=True) File "D:\ProgramData\Anaconda3\envs\pytorch\lib\site-packages\pytorch2keras\converter.py", line 317, in pytorch_to_keras names File "D:\ProgramData\Anaconda3\envs\pytorch\lib\site-packages\pytorch2keras\reshape_layers.py", line 89, in convert_reshape reshape = keras.layers.Reshape(layers[inputs[1] + '_np'], name=tf_name) KeyError: '31_np'.

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

Environment (please complete the following information):

  • win10: [e.g. iOS]
  • Python3 [e.g. Python 2, Python 3]
  • Version [e.g. v0.1.11]

Additional context Add any other context about the problem here.

Dreamgang avatar May 13 '19 08:05 Dreamgang

Hey @Dreamgang. Please, update your pytorch2keras package to the latest and try again.

pip install --upgrade pytorch2keras

gmalivenko avatar May 13 '19 09:05 gmalivenko

Hey @ @nerox8664 I've updated the pytorch2keras package to the latest, and the errors still exists.

Dreamgang avatar May 20 '19 08:05 Dreamgang

Hello @Dreamgang. I updated tracing module, so, you can check if the problem still exist.

gmalivenko avatar Jun 27 '19 19:06 gmalivenko