gulvarol / bsldict

Watch, read and lookup: learning to spot signs from multiple supervisors, ACCV 2020 (Best Application Paper)
http://www.robots.ox.ac.uk/~vgg/research/bsldict/
28 stars 4 forks source link

Converting to Torchscript #7

Open mochaminte opened 9 months ago

mochaminte commented 9 months ago

Hi, I'm trying to convert the model you've provided into torchscript so that I can implement it into a mobile app, however I am having some issues trying to do so.

This is my code to convert the model:

import torch
from torch.utils.mobile_optimizer import optimize_for_mobile
from models.i3d_mlp import i3d_mlp

# Load the model from the file
model_path = 'models/i3d_mlp.pth.tar'
checkpoint = torch.load(model_path)

model = i3d_mlp()

model.load_state_dict(checkpoint)

model.eval()

# Script the loaded model
scripted_module = torch.jit.script(model)

# Optimize for mobile
optimized_scripted_module = optimize_for_mobile(scripted_module)

optimized_scripted_module._save_for_lite_interpreter("app\src\main\assets\bsldict.ptl")

And I am getting this error:

RuntimeError:
Module 'Unit3D' has no attribute 'bn' :
  File "...\models\i3d.py", line 123
        x = self.conv3d(x)
        if self._use_batch_norm:
            x = self.bn(x)
                ~~~~~~~ <--- HERE
        if self._activation_fn is not None:
            x = self._activation_fn(x)

Any help would be appreciated.