snpe-pytorch-to-dlc ignores --input_layout argument
Join Date: 24 Jul 22
Posts: 5
Posted: Mon, 2022-08-08 01:39
snpe-pytorch-to-dlc inserts (by default) a permute layer after each input to do NCHW->NHWC permutation. This happens because it assumes all inputs to be NCHW (the Pytorch default). Adding command line argument --input_layout <input-name> NHWC should create a .dlc file without such permutation layer; however this does not happen - the output .dlc is exactly the same as when called without --input_layout.
Steps to reproduce:
1. Create a simple PyTorch scheme with the next script:
import torch
import torch.jit
import torch.nn as nn
from collections import namedtuple
class Net(nn.Module):
def __init__(self):
super(Net, self).__init__()
self.conv1 = nn.Conv2d(4, 4, 7, padding=1)
def forward(self, x):
x = self.conv1(x)
return x
net = Net()
input_shape_x = [1, 4, 270, 480]
input_data_x = torch.randn(input_shape_x)
NT = namedtuple('a', ['x'])
input = NT(input_data_x)
script_model = torch.jit.trace(net, input)
script_model.save("conv.pt")
2. Convert the scheme to .dlc as following:
snpe-pytorch-to-dlc -i conv.pt --input_dim x 1,4,270,480 --input_layout x NHWC
3. Open conv.dlc in a viewer - you will see the unneeded permutation layer immedeately after the input:
snpe-dlc-viewer -i conv.dlc
Dear customer,
How about the conversion commands as below without specific with --input_layout?
snpe-pytorch-to-dlc -i conv.pt --input_dim x 1,4,270,480
BR.
Wei