GithubHelp home page GithubHelp logo

ONNX/TorchScript convertion about gpen HOT 4 OPEN

yangxy avatar yangxy commented on July 19, 2024 1
ONNX/TorchScript convertion

from gpen.

Comments (4)

jnulzl avatar jnulzl commented on July 19, 2024 3

Hello!

Wanted to know if anyone managed to convert model with custom layers from stylegan2 to onnx/torchscript serialization format?

Convert to torchscript demo:

In gpen_model.py, you should

1、add export_torchscript attribute in __init__ of class Generator:

class Generator(nn.Module):
    def __init__(
        ......
        )
        ......      
        self.n_latent = self.log_size * 2 - 2
        self.export_torchscript = False ## add export_torchscript attribute 

    def make_noise(self):
         .....

2、add return image in forward of class Generator:

      if return_latents:
          return image, latent
      elif self.export_torchscript: ##add by jnulzl 
          return image              ##add by jnulzl 
      else:
          return image, None

3、In the end of gpen_model.py

if __name__ == '__main__':
    cpu_model = FullGenerator(512, 512, 8, 2).to(torch.device('cpu'))
    cpu_model.generator.export_torchscript = True
    data = torch.rand(1,3,512,512)
    _ = cpu_model(data)
    traced_cpu= torch.jit.trace(cpu_model, data)
    torch.jit.save(traced_cpu, "FullGenerator_cpu.pt")

from gpen.

yangxy avatar yangxy commented on July 19, 2024 1

I will try it later.

from gpen.

cyinen avatar cyinen commented on July 19, 2024

I will try it later.

Hello,have you convert the stylegan2 to onnx/torchscript finally?

from gpen.

zimenglan-sysu-512 avatar zimenglan-sysu-512 commented on July 19, 2024

hi @jnulzl what the verson of onnx u install is?

from gpen.

Related Issues (20)

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.