Forums - ONNX DepthToSpace

10 posts / 0 new
Last post
ONNX DepthToSpace
rnatarajan
Join Date: 27 Oct 19
Posts: 4
Posted: Tue, 2021-11-23 14:28

Hi,

I'm trying to convert an ONNX model with DepthToSpace (which is equivalent to torch.nn.PixelShuffle). The snpe-onnx-to-dlc complains that DepthToSpace is not supported. However, the page https://developer.qualcomm.com/sites/default/files/docs/snpe//network_la... says that PixelShuffle is supported which is the exact equivalent of ONNX DepthToSpace.

Can you please fix the converter to recognize DepthToSpace to be the same as PixelShuffle?

 

Thanks,

Ram

  • Up0
  • Down0
weihuan
Join Date: 12 Apr 20
Posts: 270
Posted: Tue, 2021-11-23 18:03

Dear developer,

Thanks for your efforts in our products.

Could you give us more messages for us to more deeply analysis?

1, Which SNPE version you used?

2, Regarding the D2S layer,  SNPE has supported now. We will check if SNPE ONNX converter supported in the latest release.

3. Where is the D2S layer issue from, model head or tail?

BR.

Wei

  • Up0
  • Down0
zhiguol
Join Date: 16 Dec 19
Posts: 25
Posted: Tue, 2021-11-23 18:13

More:

Could you please let me knwo which feature are you working on with current model?

Thanks.

  • Up0
  • Down0
rnatarajan
Join Date: 27 Oct 19
Posts: 4
Posted: Wed, 2021-11-24 03:12

1, Which SNPE version you used?

I am using version snpe-1.55.0.2958.

3. Where is the D2S layer issue from, model head or tail?

The model tail.

 

 

  • Up0
  • Down0
rnatarajan
Join Date: 27 Oct 19
Posts: 4
Posted: Wed, 2021-11-24 03:13

This is part of a segmentation network.

  • Up0
  • Down0
zhiguol
Join Date: 16 Dec 19
Posts: 25
Posted: Wed, 2021-11-24 17:45

Thanks. 

Would you mind provide your model, we can have a try locally?

This shall be supported, but need to check if there are other issues.

Thanks.

  • Up0
  • Down0
rnatarajan
Join Date: 27 Oct 19
Posts: 4
Posted: Thu, 2021-11-25 17:38

I couldn't find a way to upload the onnx file. However, I have outlined here the steps to reproduce the problem:

1. Use the following code to generate the onnx file called super_resolution.onnx. 

<code>

import torch
import torch.nn as nn
import torch.nn.init as init
 
class SuperResolutionNet(nn.Module):
    def __init__(self, upscale_factor, inplace=False):
        super(SuperResolutionNet, self).__init__()
        self.relu = nn.ReLU(inplace=inplace)
        self.conv1 = nn.Conv2d(1, 64, (5, 5), (1, 1), (2, 2))
        self.conv2 = nn.Conv2d(64, 64, (3, 3), (1, 1), (1, 1))
        self.conv3 = nn.Conv2d(64, 32, (3, 3), (1, 1), (1, 1))
        self.conv4 = nn.Conv2d(32, upscale_factor ** 2, (3, 3), (1, 1), (1, 1))
        self.pixel_shuffle = nn.PixelShuffle(upscale_factor)
 
        self._initialize_weights()
 
    def forward(self, x):
        x = self.relu(self.conv1(x))
        x = self.relu(self.conv2(x))
        x = self.relu(self.conv3(x))
        x = self.pixel_shuffle(self.conv4(x))
        return x
 
    def _initialize_weights(self):
        init.orthogonal_(self.conv1.weight, init.calculate_gain('relu'))
        init.orthogonal_(self.conv2.weight, init.calculate_gain('relu'))
        init.orthogonal_(self.conv3.weight, init.calculate_gain('relu'))
        init.orthogonal_(self.conv4.weight)
 
# Create the super-resolution model by using the above model definition.
torch_model = SuperResolutionNet(upscale_factor=3)
 
# set the model to inference mode
torch_model.eval()
 
# Input to the model
batch_size = 1
x = torch.randn(batch_size, 1, 224, 224, requires_grad=True)
torch_out = torch_model(x)
 
# Export the model
torch.onnx.export(torch_model,               # model being run
                  x,                         # model input (or a tuple for multiple inputs)
                  "super_resolution.onnx",   # where to save the model (can be a file or file-like object)
                  export_params=True,        # store the trained parameter weights inside the model file
                  opset_version=11,          # the ONNX version to export the model to
                  do_constant_folding=True,  # whether to execute constant folding for optimization
                  input_names = ['input'],   # the model's input names
                  output_names = ['output'], # the model's output names
                  )

</code>

 

2. Save the above code to a file, say hurr.py

3. Make sure you have pytorch installed.

4. Run <code>python hurr.py</code> to produce super_resolution.onnx

5. Run <code>snpe-onnx-to-dlc --input_network super_resolution.onnx --output_path super_resolution.dlc </code> to see the error

  • Up0
  • Down0
zhiguol
Join Date: 16 Dec 19
Posts: 25
Posted: Mon, 2021-11-29 00:41

Dear customer, 

Thanks for detailed update. 

We will try internally for this issue.

Thanks.

  • Up0
  • Down0
c_yanlin
Join Date: 20 May 21
Posts: 3
Posted: Mon, 2021-11-29 19:40

Dear.customer.

Sorry to tell you that the depthtospace operator is currently not supported in onnx.

Please refer to the following doc:

https://developer.qualcomm.com/sites/default/files/docs/snpe//network_la...

Thanks

  • Up0
  • Down0
c_yanlin
Join Date: 20 May 21
Posts: 3
Posted: Mon, 2021-11-29 19:41

Dear.customer.

Sorry to tell you that the depthtospace operator is currently not supported in onnx

Thanks

  • 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.