Load .npy array saved in Pyton to a Torch C++ program

velenos14: <p>How can I load a .npy saved inside a Pyton program using np.save() to a C++ app which uses torch?<br>
At the moment, I am failing with:</p>
<pre><code class="lang-auto">import torch
from torch import nn
import numpy as np

class TensorContainer(nn.Module):
    def __init__(self, tensor_dict):
        super().__init__()
        for key,value in tensor_dict.items():
            setattr(self, key, value)

ris_with_ends = np.load("ris_withends.npy")

prior = torch.from_numpy(ris_with_ends)

tensor_dict = {'prior': prior}
tensors = TensorContainer(tensor_dict)
tensors = torch.jit.script(tensors)
tensors.save('prior.pth')
</code></pre>
<pre><code class="lang-auto">#include &lt;torch/torch.h&gt;
#include &lt;torch/script.h&gt;

int main() {
    torch::jit::script::Module tensors = torch::jit::load("prior.pth");
    torch::Tensor prior = tensors.attr("prior").toTensor();
}
</code></pre>
<p>The error is:</p>
<pre><code class="lang-auto">terminate called after throwing an instance of 'c10::Error'
  what():  open file failed because of errno 2 on fopen: , file path: prior.pth
Exception raised from RAIIFile at ../caffe2/serialize/file_adapter.cc:27 (most recent call first):
frame #0: c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;) + 0x6b (0x7f2a7d26205b in /home/velenos14/PhD/TDSE_3D_GPS_codes_PyTorch_CPP/libtorch/lib/libc10.so)
frame #1: c10::detail::torchCheckFail(char const*, char const*, unsigned int, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;) + 0xbf (0x7f2a7d25cf6f in /home/velenos14/PhD/TDSE_3D_GPS_codes_PyTorch_CPP/libtorch/lib/libc10.so)
frame #2: caffe2::serialize::FileAdapter::RAIIFile::RAIIFile(std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;) + 0x134 (0x7f2a6932a8c4 in /home/velenos14/PhD/TDSE_3D_GPS_codes_PyTorch_CPP/libtorch/lib/libtorch_cpu.so)
frame #3: caffe2::serialize::FileAdapter::FileAdapter(std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;) + 0x41 (0x7f2a6932af31 in /home/velenos14/PhD/TDSE_3D_GPS_codes_PyTorch_CPP/libtorch/lib/libtorch_cpu.so)
frame #4: caffe2::serialize::PyTorchStreamReader::PyTorchStreamReader(std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;) + 0x7f (0x7f2a693283af in /home/velenos14/PhD/TDSE_3D_GPS_codes_PyTorch_CPP/libtorch/lib/libtorch_cpu.so)
frame #5: torch::jit::import_ir_module(std::shared_ptr&lt;torch::jit::CompilationUnit&gt;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;, c10::optional&lt;c10::Device&gt;, std::unordered_map&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, std::hash&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::equal_to&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::allocator&lt;std::pair&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; &gt;&amp;, bool, bool) + 0x28d (0x7f2a6a4e762d in /home/velenos14/PhD/TDSE_3D_GPS_codes_PyTorch_CPP/libtorch/lib/libtorch_cpu.so)
frame #6: torch::jit::import_ir_module(std::shared_ptr&lt;torch::jit::CompilationUnit&gt;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;, c10::optional&lt;c10::Device&gt;, bool) + 0x92 (0x7f2a6a4e7ac2 in /home/velenos14/PhD/TDSE_3D_GPS_codes_PyTorch_CPP/libtorch/lib/libtorch_cpu.so)
frame #7: torch::jit::load(std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;, c10::optional&lt;c10::Device&gt;, bool) + 0xd1 (0x7f2a6a4e7bf1 in /home/velenos14/PhD/TDSE_3D_GPS_codes_PyTorch_CPP/libtorch/lib/libtorch_cpu.so)
frame #8: main + 0x64 (0x55df200c5e8f in ./example-app)
frame #9: __libc_start_main + 0xf3 (0x7f2a6564c0b3 in /lib/x86_64-linux-gnu/libc.so.6)
frame #10: _start + 0x2e (0x55df200c586e in ./example-app)

Aborted
</code></pre>
<p>Any help on this would be much appreciated.<br>
Thank you!</p>