Giter VIP home page Giter VIP logo

Comments (3)

CaoWGG avatar CaoWGG commented on May 31, 2024

@haiyang-tju
maybe you need to fix input image size, then you can change here .
replace *.size() to [int,int] or use scale_factor

from centernet-condinst.

haiyang-tju avatar haiyang-tju commented on May 31, 2024

Thanks for your reply. @CaoWGG

I searched and tried many options, and there is no good solutions. One painful way is to edit the parameter align_corners=False, and with the default opset_version. And this will give two UserWarnings, I don't know if it will actually have an impact.

 UserWarning: Default upsampling behavior when mode=bilinear is changed to align_corners=False since 0.4.0. Please specify align_corners=True if the old behavior is desired. See the documentation of nn.Upsample for details.
:undefined
  "See the documentation of nn.Upsample for details.".format(mode))
torch.onnx.export(model, input, "./bb.onnx", export_params=True)
None
***/lib/python3.6/site-packages/torch/onnx/symbolic_helper.py:198: UserWarning: You are trying to export the model with onnx:Upsample for ONNX opset version 9. This operator might cause results to not match the expected results by PyTorch.
:undefined
ONNX's Upsample/Resize operator did not match Pytorch's Interpolation until opset 11. Attributes to determine how to transform the input were added in onnx:Resize in opset 11 to support Pytorch's behavior (like coordinate_transformation_mode and nearest_mode).
We recommend using opset 11 and above for models using this operator. 
  "" + str(_export_onnx_opset_version) + ". "

And maybe this can solve the error.
pytorch/pytorch#22906 (comment)

from centernet-condinst.

haiyang-tju avatar haiyang-tju commented on May 31, 2024

Reference here, I made a custom layer with double upsampling. And it can be successfully exported to onnx.

class resize_bilinear(nn.Module):
    def __init__(self, in_shape):
        super(resize_bilinear, self).__init__()
        self.in_shape = in_shape
        self.rhw = 2
        self.out_shape = self.in_shape*self.rhw
        self.cal_parameters()
    
    def cal_parameters(self):
        y = torch.arange(self.out_shape, dtype=torch.float32)
        ty = (y + 1) / self.rhw + 0.5 * (1 - 1.0 / self.rhw) - 1
        zero = torch.zeros([1])
        ty = torch.max(ty, zero)

        ty_floor = ty.floor()
        ty_ceil = ty.ceil()
        dy = ty - ty_floor
        dydy = dy.view(-1,1) * dy.view(-1)
        
        iy0 = ty_floor.long()
        iy1 = torch.clamp(ty_ceil,0,self.in_shape-1).long()

        self.iy0 = nn.Parameter(iy0, requires_grad=False)
        self.iy1 = nn.Parameter(iy1, requires_grad=False)
        self.dy = nn.Parameter(dy, requires_grad=False)
        self.dydy = nn.Parameter(dydy, requires_grad=False)

    def forward(self, x):
        if x is None:
            return x
        im_iy0 = x.index_select(2, self.iy0) 
        im_iy1 = x.index_select(2, self.iy1)
        d = im_iy0.index_select(3, self.iy0) * (1 - 2*self.dy + self.dydy) + \
            im_iy1.index_select(3, self.iy0) * (self.dy - self.dydy) + \
            im_iy0.index_select(3, self.iy1) * (self.dy - self.dydy) + \
            im_iy1.index_select(3, self.iy1) * self.dydy
        
        return d

WX20200107-095152@2x

from centernet-condinst.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.