Code Monkey home page Code Monkey logo

lite_hrnet_onnx's Introduction

use mmpose frame to export lite_hrnet onnx model

chanes 1: line86

def get_avgpool_s_k_sz(self,x):
    outputsz = np.array(x[-1].size()[-2:])
    stridesz_list = []
    kernelsz_lsit = []
    for index in range(len(x)):
        inputsz_i = np.array(x[index].size()[-2:])
        stridesz_i = np.floor(inputsz_i / outputsz).astype(np.int32)
        kernelsz_i = inputsz_i - (outputsz - 1) * stridesz_i
        stridesz_list.append(stridesz_i)
        kernelsz_lsit.append(kernelsz_i)
    return stridesz_list,kernelsz_lsit,outputsz

def forward(self, x):
    # mini_size = x[-1].size()[-2:]
    # out = [F.adaptive_avg_pool2d(s, mini_size) for s in x[:-1]] + [x[-1]]
    # out = torch.cat(out, dim=1)

    stridesz_list, kernelsz_list, outputsz = self.get_avgpool_s_k_sz(x)
    out = [torch.nn.AvgPool2d(kernel_size=kernelsz.tolist(),stride=stridesz.tolist())(s) for s,kernelsz,stridesz in
           zip(x[:-1],kernelsz_list,stridesz_list) ] + [x[-1]]
    out = torch.cat((out), dim=1)

    out = self.conv1(out)
    out = self.conv2(out)
    out = torch.split(out, self.channels, dim=1)
    out = [
        s * F.interpolate(a, size=s.size()[-2:], mode='nearest')
        for s, a in zip(x, out)
    ]


    return out

changes 2:line30

    # self.global_avgpool = nn.AvgPool2d(1)
    self.global_avgpool = nn.AdaptiveAvgPool2d(1)

when run pytorchonnx.py,warning will happen,just ignore

Use load_from_local loader
/home/cody/anaconda3/envs/LiteHRNET/lib/python3.7/site-packages/mmpose/models/backbones/utils/channel_shuffle.py:20: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
  assert (num_channels % groups == 0), ('num_channels should be '
/home/cody/anaconda3/envs/LiteHRNET/lib/python3.7/site-packages/mmpose/models/backbones/litehrnet.py:87: TracerWarning: Converting a tensor to a Python integer might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
  outputsz = np.array(x[-1].size()[-2:])
/home/cody/anaconda3/envs/LiteHRNET/lib/python3.7/site-packages/mmpose/models/backbones/litehrnet.py:91: TracerWarning: Converting a tensor to a Python integer might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
  inputsz_i = np.array(x[index].size()[-2:])
Successfully exported ONNX model: lite_hr.onnx

Process finished with exit code 0

lite_hrnet_onnx's People

Contributors

codylcs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

lite_hrnet_onnx's Issues

Questions about model output

Does this onnx model only have heatmap output? If there is no offset output, how to calculate the position of the keypoints on the original image?

Failed to export an ONNX attribute 'onnx::Gather'

Thank for your guide,
But when I try convert lite_hrnet with your code with model Lite-HRNet-18, it raise the error:
RuntimeError: Failed to export an ONNX attribute 'onnx::Gather', since it's not constant, please try to make things (e.g., kernel size) static if possible
RuntimeError: Failed to export an ONNX attribute 'onnx::Gather', since it's not constant, please try to make things (e.g., kernel size) static if possible
could you please fix it for me? Thank you very much!

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.