Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert torch script(jit) #212

Open
HERIUN opened this issue Jul 22, 2024 · 0 comments
Open

convert torch script(jit) #212

HERIUN opened this issue Jul 22, 2024 · 0 comments

Comments

@HERIUN
Copy link

HERIUN commented Jul 22, 2024

edit vgg16_bn.py. forward() *because torch jit does not supply "named tuple"

    def forward(self, X):
        h = self.slice1(X)
        h_relu2_2 = h
        h = self.slice2(h)
        h_relu3_2 = h
        h = self.slice3(h)
        h_relu4_3 = h
        h = self.slice4(h)
        h_relu5_3 = h
        h = self.slice5(h)
        h_fc7 = h
        # vgg_outputs = namedtuple(
        #     "VggOutputs", ["fc7", "relu5_3", "relu4_3", "relu3_2", "relu2_2"]
        # )
        # out = vgg_outputs(h_fc7, h_relu5_3, h_relu4_3, h_relu3_2, h_relu2_2)
        return h_fc7, h_relu5_3, h_relu4_3, h_relu3_2, h_relu2_2

convert craft to jit

craft = CRAFT()
ckpt_path = "~~"
state_dict = _get_state_dict(
            ckpt_path=ckpt_path, include="module.", delete="module.", cuda=cuda
        )
craft.load_state_dict(state_dict=state_dict, strict=True)
craft.eval()
craft = torch.jit.script(craft)

In my gpu, speed +5%(1.34 sec -> 1.27sec), memory used are same(don't know why..)
image

order changed(it is almost same time)
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant