I use libtorch to build up model.
I want to write a load model function.
I met this problem
[ 50%] Building CXX object CMakeFiles/yolo-app.dir/yolov3.cpp.o
[ 50%] Building CXX object CMakeFiles/yolo-app.dir/main.cpp.o
[ 75%] Building CXX object CMakeFiles/yolo-app.dir/Darknet.cpp.o
/home/ubuntu/Desktop/libtorch-yolov3-master/build/Darknet.cpp: In function ‘int split(const string&, std::vector&, std::string)’:
/home/ubuntu/Desktop/libtorch-yolov3-master/build/Darknet.cpp:79:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
/home/ubuntu/Desktop/libtorch-yolov3-master/build/Darknet.cpp: In member function ‘at::Tensor UpsampleLayer::forward(at::Tensor)’:
/home/ubuntu/Desktop/libtorch-yolov3-master/build/Darknet.cpp:170:21: warning: ‘using IntList = class c10::ArrayRef’ is deprecated [-Wdeprecated-declarations]
torch::IntList sizes = x.sizes();
^~~~~
In file included from /home/ubuntu/Desktop/libtorch/include/c10/core/ScalarType.h:3,
from /home/ubuntu/Desktop/libtorch/include/c10/core/Scalar.h:9,
from /home/ubuntu/Desktop/libtorch/include/ATen/core/Type.h:8,
from /home/ubuntu/Desktop/libtorch/include/ATen/Type.h:2,
from /home/ubuntu/Desktop/libtorch/include/ATen/Context.h:4,
from /home/ubuntu/Desktop/libtorch/include/ATen/ATen.h:5,
from /home/ubuntu/Desktop/libtorch/include/torch/csrc/api/include/torch/types.h:3,
from /home/ubuntu/Desktop/libtorch/include/torch/csrc/api/include/torch/data/dataloader_options.h:4,
from /home/ubuntu/Desktop/libtorch/include/torch/csrc/api/include/torch/data/dataloader/base.h:3,
from /home/ubuntu/Desktop/libtorch/include/torch/csrc/api/include/torch/data/dataloader/stateful.h:3,
from /home/ubuntu/Desktop/libtorch/include/torch/csrc/api/include/torch/data/dataloader.h:3,
from /home/ubuntu/Desktop/libtorch/include/torch/csrc/api/include/torch/data.h:3,
from /home/ubuntu/Desktop/libtorch/include/torch/csrc/api/include/torch/all.h:4,
from /home/ubuntu/Desktop/libtorch/include/torch/csrc/api/include/torch/torch.h:3,
from /home/ubuntu/Desktop/libtorch-yolov3-master/build/Darknet.h:11,
from /home/ubuntu/Desktop/libtorch-yolov3-master/build/Darknet.cpp:10:
/home/ubuntu/Desktop/libtorch/include/c10/util/ArrayRef.h:277:55: note: declared here
using IntList C10_DEPRECATED_USING = ArrayRef<int64_t>;
^
In file included from /home/ubuntu/Desktop/libtorch-yolov3-master/build/yolov3.h:13,
from /home/ubuntu/Desktop/libtorch-yolov3-master/build/yolov3.cpp:9:
/home/ubuntu/Desktop/libtorch-yolov3-master/build/Darknet.h:18:8: error: redefinition of ‘struct Darknet’
struct Darknet : torch::nn::Module {
^~~~~~~
In file included from /home/ubuntu/Desktop/libtorch-yolov3-master/build/yolov3.cpp:7:
/home/ubuntu/Desktop/libtorch-yolov3-master/build/Darknet.h:18:8: note: previous definition of ‘struct Darknet’
struct Darknet : torch::nn::Module {
^~~~~~~
/home/ubuntu/Desktop/libtorch-yolov3-master/build/yolov3.cpp: In constructor ‘YOLOV3::YOLOV3(std::string, std::string, int)’:
/home/ubuntu/Desktop/libtorch-yolov3-master/build/yolov3.cpp:12:70: error: no matching function for call to ‘c10::Device::Device()’
YOLOV3::YOLOV3(string cfgPath ,string weightPath,int input_image_size){
^
In file included from /home/ubuntu/Desktop/libtorch/include/c10/core/Allocator.h:6,
from /home/ubuntu/Desktop/libtorch/include/ATen/ATen.h:3,
from /home/ubuntu/Desktop/libtorch/include/torch/csrc/api/include/torch/types.h:3,
from /home/ubuntu/Desktop/libtorch/include/torch/csrc/api/include/torch/data/dataloader_options.h:4,
from /home/ubuntu/Desktop/libtorch/include/torch/csrc/api/include/torch/data/dataloader/base.h:3,
from /home/ubuntu/Desktop/libtorch/include/torch/csrc/api/include/torch/data/dataloader/stateful.h:3,
from /home/ubuntu/Desktop/libtorch/include/torch/csrc/api/include/torch/data/dataloader.h:3,
from /home/ubuntu/Desktop/libtorch/include/torch/csrc/api/include/torch/data.h:3,
from /home/ubuntu/Desktop/libtorch/include/torch/csrc/api/include/torch/all.h:4,
from /home/ubuntu/Desktop/libtorch/include/torch/csrc/api/include/torch/torch.h:3,
from /home/ubuntu/Desktop/libtorch-yolov3-master/build/yolov3.cpp:1:
/home/ubuntu/Desktop/libtorch/include/c10/core/Device.h:45:18: note: candidate: ‘c10::Device::Device(const string&)’
/* implicit / Device(const std::string& device_string);
^~~~~~
/home/ubuntu/Desktop/libtorch/include/c10/core/Device.h:45:18: note:   candidate expects 1 argument, 0 provided
/home/ubuntu/Desktop/libtorch/include/c10/core/Device.h:35:18: note: candidate: ‘c10::Device::Device(c10::DeviceType, c10::DeviceIndex)’
/ implicit */ Device(DeviceType type, DeviceIndex index = -1)
^~~~~~
/home/ubuntu/Desktop/libtorch/include/c10/core/Device.h:35:18: note:   candidate expects 2 arguments, 0 provided
/home/ubuntu/Desktop/libtorch/include/c10/core/Device.h:30:16: note: candidate: ‘constexpr c10::Device::Device(const c10::Device&)’
struct C10_API Device final {
^~~~~~
/home/ubuntu/Desktop/libtorch/include/c10/core/Device.h:30:16: note:   candidate expects 1 argument, 0 provided
/home/ubuntu/Desktop/libtorch/include/c10/core/Device.h:30:16: note: candidate: ‘constexpr c10::Device::Device(c10::Device&&)’
/home/ubuntu/Desktop/libtorch/include/c10/core/Device.h:30:16: note:   candidate expects 1 argument, 0 provided
/home/ubuntu/Desktop/libtorch-yolov3-master/build/yolov3.cpp: In member function ‘bool YOLOV3::initial()’:
/home/ubuntu/Desktop/libtorch-yolov3-master/build/yolov3.cpp:30:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
/home/ubuntu/Desktop/libtorch-yolov3-master/build/yolov3.cpp: At global scope:
/home/ubuntu/Desktop/libtorch-yolov3-master/build/yolov3.cpp:32:24: error: ‘bool YOLOV3::load_model’ is not a static data member of ‘class YOLOV3’
bool YOLOV3::load_model({
^
/home/ubuntu/Desktop/libtorch-yolov3-master/build/yolov3.cpp:36:5: error: invalid use of ‘this’ at top level
this->net = Darknet(cfgPath , &this->device);
^~~~
/home/ubuntu/Desktop/libtorch-yolov3-master/build/yolov3.cpp:36:25: error: invalid use of non-static data member ‘YOLOV3::cfgPath’
this->net = Darknet(cfgPath , &this->device);
^~~~~~~
In file included from /home/ubuntu/Desktop/libtorch-yolov3-master/build/yolov3.cpp:9:
/home/ubuntu/Desktop/libtorch-yolov3-master/build/yolov3.h:36:12: note: declared here
string cfgPath;
^~~~~~~
/home/ubuntu/Desktop/libtorch-yolov3-master/build/yolov3.cpp:36:36: error: invalid use of ‘this’ at top level
this->net = Darknet(cfgPath , &this->device);
^~~~
/home/ubuntu/Desktop/libtorch-yolov3-master/build/yolov3.cpp:36:49: error: expected ‘}’ before ‘;’ token
this->net = Darknet(cfgPath , &this->device);
^
/home/ubuntu/Desktop/libtorch-yolov3-master/build/yolov3.cpp:32:25: note: to match this ‘{’
bool YOLOV3::load_model({
^
/home/ubuntu/Desktop/libtorch-yolov3-master/build/yolov3.cpp:36:49: error: expected ‘)’ before ‘;’ token
this->net = Darknet(cfgPath , &this->device);
^
)
/home/ubuntu/Desktop/libtorch-yolov3-master/build/yolov3.cpp:32:24: note: to match this ‘(’
bool YOLOV3::load_model({
^
/home/ubuntu/Desktop/libtorch-yolov3-master/build/yolov3.cpp:38:33: error: invalid use of ‘this’ at top level
map<string, string> info = this->net.get_net_info();
^~~~
/home/ubuntu/Desktop/libtorch-yolov3-master/build/yolov3.cpp:40:5: error: ‘info’ does not name a type
info->operator = std::to_string(input_image_size);
^~~~
/home/ubuntu/Desktop/libtorch-yolov3-master/build/yolov3.cpp:42:10: error: ‘cout’ in namespace ‘std’ does not name a type
std::cout << “loading weight …” << endl;
^~~~
In file included from /home/ubuntu/Desktop/libtorch/include/c10/core/TensorTypeId.h:4,
from /home/ubuntu/Desktop/libtorch/include/c10/core/Backend.h:4,
from /home/ubuntu/Desktop/libtorch/include/c10/core/Layout.h:3,
from /home/ubuntu/Desktop/libtorch/include/ATen/core/Type.h:7,
from /home/ubuntu/Desktop/libtorch/include/ATen/Type.h:2,
from /home/ubuntu/Desktop/libtorch/include/ATen/Context.h:4,
from /home/ubuntu/Desktop/libtorch/include/ATen/ATen.h:5,
from /home/ubuntu/Desktop/libtorch/include/torch/csrc/api/include/torch/types.h:3,
from /home/ubuntu/Desktop/libtorch/include/torch/csrc/api/include/torch/data/dataloader_options.h:4,
from /home/ubuntu/Desktop/libtorch/include/torch/csrc/api/include/torch/data/dataloader/base.h:3,
from /home/ubuntu/Desktop/libtorch/include/torch/csrc/api/include/torch/data/dataloader/stateful.h:3,
from /home/ubuntu/Desktop/libtorch/include/torch/csrc/api/include/torch/data/dataloader.h:3,
from /home/ubuntu/Desktop/libtorch/include/torch/csrc/api/include/torch/data.h:3,
from /home/ubuntu/Desktop/libtorch/include/torch/csrc/api/include/torch/all.h:4,
from /home/ubuntu/Desktop/libtorch/include/torch/csrc/api/include/torch/torch.h:3,
from /home/ubuntu/Desktop/libtorch-yolov3-master/build/yolov3.cpp:1:
/usr/include/c++/8/iostream:61:18: note: ‘std::cout’ declared here
extern ostream cout;  /// Linked to standard output
^~~~
/home/ubuntu/Desktop/libtorch-yolov3-master/build/yolov3.cpp:43:5: error: expected unqualified-id before ‘this’
this->net.load_weights(weightPath);
^~~~
/home/ubuntu/Desktop/libtorch-yolov3-master/build/yolov3.cpp:44:10: error: ‘cout’ in namespace ‘std’ does not name a type
std::cout << “weight loaded …” << endl;
^~~~
In file included from /home/ubuntu/Desktop/libtorch/include/c10/core/TensorTypeId.h:4,
from /home/ubuntu/Desktop/libtorch/include/c10/core/Backend.h:4,
from /home/ubuntu/Desktop/libtorch/include/c10/core/Layout.h:3,
from /home/ubuntu/Desktop/libtorch/include/ATen/core/Type.h:7,
from /home/ubuntu/Desktop/libtorch/include/ATen/Type.h:2,
from /home/ubuntu/Desktop/libtorch/include/ATen/Context.h:4,
from /home/ubuntu/Desktop/libtorch/include/ATen/ATen.h:5,
from /home/ubuntu/Desktop/libtorch/include/torch/csrc/api/include/torch/types.h:3,
from /home/ubuntu/Desktop/libtorch/include/torch/csrc/api/include/torch/data/dataloader_options.h:4,
from /home/ubuntu/Desktop/libtorch/include/torch/csrc/api/include/torch/data/dataloader/base.h:3,
from /home/ubuntu/Desktop/libtorch/include/torch/csrc/api/include/torch/data/dataloader/stateful.h:3,
from /home/ubuntu/Desktop/libtorch/include/torch/csrc/api/include/torch/data/dataloader.h:3,
from /home/ubuntu/Desktop/libtorch/include/torch/csrc/api/include/torch/data.h:3,
from /home/ubuntu/Desktop/libtorch/include/torch/csrc/api/include/torch/all.h:4,
from /home/ubuntu/Desktop/libtorch/include/torch/csrc/api/include/torch/torch.h:3,
from /home/ubuntu/Desktop/libtorch-yolov3-master/build/yolov3.cpp:1:
/usr/include/c++/8/iostream:61:18: note: ‘std::cout’ declared here
extern ostream cout;  /// Linked to standard output
^~~~
/home/ubuntu/Desktop/libtorch-yolov3-master/build/yolov3.cpp:46:5: error: expected unqualified-id before ‘this’
this->net.to(this->device);
^~~~
/home/ubuntu/Desktop/libtorch-yolov3-master/build/yolov3.cpp:49:5: error: expected unqualified-id before ‘this’
this->net.eval();
^~~~
/home/ubuntu/Desktop/libtorch-yolov3-master/build/yolov3.cpp:50:5: error: expected unqualified-id before ‘return’
return true;
^~~~~~
/home/ubuntu/Desktop/libtorch-yolov3-master/build/yolov3.cpp:51:1: error: expected declaration before ‘}’ token
};
^
/home/ubuntu/Desktop/libtorch-yolov3-master/build/Darknet.cpp: In member function ‘std::map<std::basic_string, std::basic_string > Darknet::get_net_info()’:
/home/ubuntu/Desktop/libtorch-yolov3-master/build/Darknet.cpp:502:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
CMakeFiles/yolo-app.dir/build.make:86: recipe for target ‘CMakeFiles/yolo-app.dir/yolov3.cpp.o’ failed
make[2]: *** [CMakeFiles/yolo-app.dir/yolov3.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs…
CMakeFiles/Makefile2:67: recipe for target ‘CMakeFiles/yolo-app.dir/all’ failed
make[1]: *** [CMakeFiles/yolo-app.dir/all] Error 2
Makefile:83: recipe for target ‘all’ failed
make: *** [all] Error 2