Forums - snpe-pytorch-to-dlc ignores --input_layout argument

2 posts / 0 new
Last post
snpe-pytorch-to-dlc ignores --input_layout argument
gershon
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
 
  • Up0
  • Down0
weihuan
Join Date: 12 Apr 20
Posts: 270
Posted: Sun, 2022-09-04 06:26

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

  • Up0
  • Down0
or Register

Opinions expressed in the content posted here are the personal opinions of the original authors, and do not necessarily reflect those of Qualcomm Incorporated or its subsidiaries (“Qualcomm”). The content is provided for informational purposes only and is not meant to be an endorsement or representation by Qualcomm or any other party. This site may also provide links or references to non-Qualcomm sites and resources. Qualcomm makes no representations, warranties, or other commitments whatsoever about any non-Qualcomm sites or third-party resources that may be referenced, accessible from, or linked to this site.