Skip to content

Converting to Torchscript #7

@mochaminte

Description

@mochaminte

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions