3

I need to run in c++ a pre-trained pytorch nn model (trained in python) to make predictions.

To do so, I'm following the instructions on how to load a pytorch model in c++ given here: https://pytorch.org/tutorials/advanced/cpp_export.html

But when I try to get the torch.jit.ScriptModule via tracing as stated in the first step of the tutorial:

    traced_script_module =
        torch.jit.trace(model, (input_tensor_1, input_tensor_2))

Instead of returning a torch.jit.ScriptModule, it returns a function:

    print(type(traced_script_module))
    <type 'function'>

Which, when I run:

    traced_script_module.save("model.pt")

then leads into the following error:

Traceback (most recent call last):
  File "serialize_model.py", line 60, in <module>
    traced_script_module.save("model.pt")
AttributeError: 'function' object has no attribute 'save'

Any ideas on what I'm doing wrong?

1
  • 1
    What is your PyTorch version? Commented Feb 12, 2019 at 14:25

1 Answer 1

2

Thanks for asking Jatentaki. I was using PyTorch 0.4 in Python and when I updated to 1.0 it worked.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.