Darknet load model problem

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