Hi All,
Can you please let me know how to load the pretrained models using c++ frontend? I am trying to load the Resnet model using C++ front end as follows.
#include <torch/torch.h>
#include <torch/data/datasets/base.h>
#include <iostream>
#include <memory>
int main()
{
//https://s3.amazonaws.com/pytorch/models/resnet18-5c106cde.pth
//resnet18-5c106cde.pth
//auto sequential = std::make_shared<torch::nn::Sequential>();
torch::nn::Sequential sequential;
torch::load(sequential, "resnet18-5c106cde.pth");
std::cout << c10::str(sequential) << "\n";
}
But I am getting sigabrt.
[ Variable[CPUFloatType]{2,3} ]
terminate called after throwing an instance of 'c10::Error'
what(): [enforce fail at inline_container.cc:137] . PytorchStreamReader failed reading zip archive: failed finding central directory
frame #0: std::function<std::string ()>::operator()() const + 0x11 (0x7f0189f2ef81 in /opt/libtorch/lib/libc10.so)
frame #1: c10::ThrowEnforceNotMet(char const*, int, char const*, std::string const&, void const*) + 0x49 (0x7f0189f2ed99 in /opt/libtorch/lib/libc10.so)
frame #2: caffe2::serialize::PyTorchStreamReader::valid(char const*) + 0x6b (0x7f018bb3894b in /opt/libtorch/lib/libcaffe2.so)
frame #3: caffe2::serialize::PyTorchStreamReader::init() + 0x9d (0x7f018bb3a71d in /opt/libtorch/lib/libcaffe2.so)
frame #4: caffe2::serialize::PyTorchStreamReader::PyTorchStreamReader(std::unique_ptr<caffe2::serialize::ReadAdapterInterface, std::default_delete<caffe2::serialize::ReadAdapterInterface> >) + 0x3b (0x7f018bb3c17b in /opt/libtorch/lib/libcaffe2.so)
frame #5: <unknown function> + 0x9087ee (0x7f0194c137ee in /opt/libtorch/lib/libtorch.so.1)
frame #6: torch::jit::load(std::unique_ptr<caffe2::serialize::ReadAdapterInterface, std::default_delete<caffe2::serialize::ReadAdapterInterface> >, c10::optional<c10::Device>, std::unordered_map<std::string, std::string, std::hash<std::string>, std::equal_to<std::string>, std::allocator<std::pair<std::string const, std::string> > >&) + 0x9a (0x7f0194c16d2a in /opt/libtorch/lib/libtorch.so.1)
frame #7: torch::jit::load(std::string const&, c10::optional<c10::Device>, std::unordered_map<std::string, std::string, std::hash<std::string>, std::equal_to<std::string>, std::allocator<std::pair<std::string const, std::string> > >&) + 0x68 (0x7f0194c16ec8 in /opt/libtorch/lib/libtorch.so.1)
frame #8: torch::serialize::InputArchive::load_from(std::string const&, c10::optional<c10::Device>) + 0x38 (0x7f0194e09798 in /opt/libtorch/lib/libtorch.so.1)
frame #9: void torch::load<torch::nn::Sequential, char const (&) [22]>(torch::nn::Sequential&, char const (&) [22]) + 0x57 (0x409cd7 in ./CatsAndDogsCnn)
frame #10: main + 0x9e (0x4074ae in ./CatsAndDogsCnn)
frame #11: __libc_start_main + 0xf0 (0x7f01895c9830 in /lib/x86_64-linux-gnu/libc.so.6)
frame #12: _start + 0x29 (0x407599 in ./CatsAndDogsCnn)