Giter VIP home page Giter VIP logo

libtorch-yolov3's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

libtorch-yolov3's Issues

你好,libtorch1.4好像用不了

  1. 142行 conv_options.with_bias(with_bias);只有这个 conv_options.bias(with_bias),没有with_bias;
  2. at::TensorOptions options = torch::TensorOptions()
    .dtype(torch::kFloat32)
    .is_variable(true),没有这个is_variable,我改成了at::TensorOptions options = torch::TensorOptions().dtype(torch::kFloat32);去掉了后面的.is_variable(true);我改了之后,编译通过,GPU运行失败,出现错误的在yolo层,cpu上正常运行

crash in Darknet::load_weights() when load tiny weights

module_list.size() is 24

void Darknet::load_weights(const char *weight_file)
{
...
for (int i = 0; i < module_list.size(); i++)
{

}
...
conv_weights = conv_weights.view_as(conv_imp->weight);//------crah when i == 22
}

build error ('isspace': is not a member of 'std')

after executing this command:
cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_PREFIX_PATH=C:/Program Files/libtorch ..
i open yolo-app.sln with visual studio in order to build the project and generate yolo-app.exe
but i can't build because there is some errors in Darknet.cpp file :

Untitled

Any Help :)

main.cpp:50 compile error.

In main.cpp:50, you should change "CV_BGR2RGB" to "cv::COLOR_BGR2RGB", or it will be error while compiling with opencv4.0

你好,請問一下 不用libtorch的話 可以用啥

I met the same error, did you solve it ?

Yes I have solved it
My cmakelist is error

What's wrong with your cmakelist?

首先 不能用opencv4和libtorch
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(yolo-app)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV _INCLUDE_DIRS})
find_package(Torch REQUIRED)
aux_source_directory(. DIR_sRCS)
add_executable(yolo-app main.cpp)#注 main.cpp可以换成路径xxx/xxx.cpp
target_link_libraries(yolo-app "${TORCH_LIBRARIES}" "${OpenCV_LIBS}")
set_property(TARGET yolo-app PROPERTY CXX_STANDARD 11)

谢啦,我按你的CMakeList.txt改了下,还是有问题,后来又把main.cpp 改成了
${DIR_SRCS} 才解决这个问题。

Originally posted by @Arctanxy in #10 (comment)

load_weights error

./yolo-app ../imgs/person.jpg
loading weight ...
terminate called after throwing an instance of 'c10::Error'
what(): Tensor: invalid storage offset -5 (setStrided at /pytorch/aten/src/ATen/native/Resize.h:87)
frame #0: std::function<std::string ()>::operator()() const + 0x11 (0x7f0957255441 in /home/chenxin/Desktop/libtorch-shared-with-deps-latest/libtorch/lib/libc10.so)
frame #1: c10::Error::Error(c10::SourceLocation, std::string const&) + 0x2a (0x7f0957254d7a in /home/chenxin/Desktop/libtorch-shared-with-deps-latest/libtorch/lib/libc10.so)
frame #2: + 0xa36497 (0x7f094d20b497 in /home/chenxin/Desktop/libtorch-shared-with-deps-latest/libtorch/lib/libcaffe2.so)
frame #3: at::native::as_strided_tensorimpl(at::Tensor const&, c10::ArrayRef, c10::ArrayRef, c10::optional) + 0xbb (0x7f094d2081eb in /home/chenxin/Desktop/libtorch-shared-with-deps-latest/libtorch/lib/libcaffe2.so)
frame #4: + 0xb25b1a (0x7f094d2fab1a in /home/chenxin/Desktop/libtorch-shared-with-deps-latest/libtorch/lib/libcaffe2.so)
frame #5: at::native::slice(at::Tensor const&, long, long, long, long) + 0x1b8 (0x7f094d2000f8 in /home/chenxin/Desktop/libtorch-shared-with-deps-latest/libtorch/lib/libcaffe2.so)
frame #6: at::TypeDefault::slice(at::Tensor const&, long, long, long, long) const + 0x1a (0x7f094d45f1fa in /home/chenxin/Desktop/libtorch-shared-with-deps-latest/libtorch/lib/libcaffe2.so)
frame #7: at::Tensor::slice(long, long, long, long) const + 0x6f (0x55b9b4eb4cf5 in ./yolo-app)
frame #8: Darknet::load_weights(char const*) + 0x596 (0x55b9b4eadfee in ./yolo-app)
frame #9: main + 0x1a1 (0x55b9b4eef14b in ./yolo-app)
frame #10: __libc_start_main + 0xe7 (0x7f08d0fe5b97 in /lib/x86_64-linux-gnu/libc.so.6)
frame #11: _start + 0x2a (0x55b9b4ea848a in ./yolo-app)

Aborted (core dumped)

Solved.

Solved.
Replace every

torch::TensorFromBlob

to

at::from_blob

like

at::from_blob(weights_src, {length/4}).to(torch::kFloat32)

There will be 3 totally.

Originally posted by @zhengli233 in #12 (comment)

OpenCV linking error

After executing make i get the following error. I'm using OpenCV4 on arch linux

[100%] Linking CXX executable yolo_app
/usr/bin/ld: CMakeFiles/yolo_app.dir/yolo_app.cpp.o: in function `main':
yolo_app.cpp:(.text+0x9f0): undefined reference to `cv::imread(std::string const&, int)'
/usr/bin/ld: yolo_app.cpp:(.text+0x137e): undefined reference to `cv::imwrite(std::string const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/yolo_app.dir/build.make:125: yolo_app] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/yolo_app.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

in make step I meet a error with main.cpp

my CmakeList :
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(yolo-app)

find_package( OpenCV 3.4.9 REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
message(${OpenCV_INCLUDE_DIRS})

find_package(Torch REQUIRED)

aux_source_directory(. DIR_SRCS)

add_executable(yolo-app ${DIR_SRCS})
target_link_libraries(yolo-app "${TORCH_LIBRARIES}" "${OpenCV_LIBS}")
set_property(TARGET yolo-app PROPERTY CXX_STANDARD 11)

my terminal show that:

ubuntu@ubuntu-System-Product-Name:/Desktop/coco/libtorch-yolov3-master/build$ cmake -DCMAKE_PREFIX_PATH='/home/ubuntu/Desktop/libtorch'
-- Caffe2: CUDA detected: 10.2
-- Caffe2: CUDA nvcc is: /usr/local/cuda-10.2/bin/nvcc
-- Caffe2: CUDA toolkit directory: /usr/local/cuda-10.2
-- Caffe2: Header version is: 10.2
-- Found cuDNN: v7.6.4 (include: /usr/local/cuda-10.2/include, library: /usr/local/cuda-10.2/lib64/libcudnn.so)
-- Autodetected CUDA architecture(s): 7.5
-- Added CUDA NVCC flags for: -gencode;arch=compute_75,code=sm_75
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ubuntu/Desktop/coco/libtorch-yolov3-master/build
ubuntu@ubuntu-System-Product-Name:
/Desktop/coco/libtorch-yolov3-master/build$ make -j4
Scanning dependencies of target yolo-app
[ 66%] Building CXX object CMakeFiles/yolo-app.dir/detect_cuda_compute_capabilities.cpp.o
[ 66%] Building CXX object CMakeFiles/yolo-app.dir/detect_cuda_version.cc.o
[100%] Linking CXX executable yolo-app
CMakeFiles/yolo-app.dir/detect_cuda_version.cc.o: In function main': detect_cuda_version.cc:(.text+0x0): multiple definition of main'
CMakeFiles/yolo-app.dir/detect_cuda_compute_capabilities.cpp.o:detect_cuda_compute_capabilities.cpp:(.text+0x0): first defined here
collect2: error: ld returned 1 exit status
CMakeFiles/yolo-app.dir/build.make:183: recipe for target 'yolo-app' failed
make[2]: *** [yolo-app] Error 1
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

i use libtorch 1.3.0 cuda 10.1 in linux, Error when compile, Can you tell me how to solve it

CMakeFiles/yolo-app.dir/main.cpp.o: In function main': main.cpp:(.text+0x1012): multiple definition of main'
CMakeFiles/yolo-app.dir/detect_cuda_version.cc.o:detect_cuda_version.cc:(.text+0x0): first defined here
CMakeFiles/yolo-app.dir/detect_cuda_compute_capabilities.cpp.o: In function main': detect_cuda_compute_capabilities.cpp:(.text+0x0): multiple definition of main'
CMakeFiles/yolo-app.dir/detect_cuda_version.cc.o:detect_cuda_version.cc:(.text+0x0): first defined here
collect2: error: ld returned 1 exit status
CMakeFiles/yolo-app.dir/build.make:233: recipe for target 'yolo-app' failed
make[3]: *** [yolo-app] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/yolo-app.dir/all' failed
make[2]: *** [CMakeFiles/yolo-app.dir/all] Error 2
CMakeFiles/Makefile2:79: recipe for target 'CMakeFiles/yolo-app.dir/rule' failed
make[1]: *** [CMakeFiles/yolo-app.dir/rule] Error 2
Makefile:118: recipe for target 'yolo-app' failed
make: *** [yolo-app] Error 2

Error during make

Hi,
I use pytorch 1.2
I could successfully cmake it
but when building with make I get these errors
I don't know why, do you have the same mistakes ?

best regards

(base) n01pham@n01pham-MS-7B48:~/Desktop/libtorch-yolov3$ cmake -DCMAKE_PREFIX_PATH=/home/n01pham/libtorch
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Found torch: /home/n01pham/libtorch/lib/libtorch.so  
-- Configuring done
-- Generating done
-- Build files have been written to: /home/n01pham/Desktop/libtorch-yolov3
(base) n01pham@n01pham-MS-7B48:~/Desktop/libtorch-yolov3$ make
Scanning dependencies of target yolo-app
[ 33%] Building CXX object CMakeFiles/yolo-app.dir/Darknet.cpp.o
In file included from /home/n01pham/libtorch/include/torch/csrc/api/include/torch/nn/modules/conv.h:5:0,
                 from /home/n01pham/libtorch/include/torch/csrc/api/include/torch/nn/modules.h:12,
                 from /home/n01pham/libtorch/include/torch/csrc/api/include/torch/nn.h:7,
                 from /home/n01pham/libtorch/include/torch/csrc/api/include/torch/all.h:6,
                 from /home/n01pham/libtorch/include/torch/csrc/api/include/torch/torch.h:3,
                 from /home/n01pham/Desktop/libtorch-yolov3/Darknet.h:11,
                 from /home/n01pham/Desktop/libtorch-yolov3/Darknet.cpp:10:
/home/n01pham/libtorch/include/torch/csrc/api/include/torch/nn/options/conv.h: In function ‘torch::nn::Conv2dOptions conv_options(int64_t, int64_t, int64_t, int64_t, int64_t, int64_t, bool)’:
/home/n01pham/libtorch/include/torch/csrc/api/include/torch/nn/options/conv.h:40:42: error: ‘torch::ExpandingArray<2ul, long int> torch::nn::ConvOptions<2ul>::stride_’ is private
   TORCH_ARG(ExpandingArray<D>, stride) = 1;
                                          ^
/home/n01pham/Desktop/libtorch-yolov3/Darknet.cpp:136:18: error: within this context
     conv_options.stride_ = stride;
                  ^
In file included from /home/n01pham/libtorch/include/torch/csrc/api/include/torch/nn/modules/conv.h:5:0,
                 from /home/n01pham/libtorch/include/torch/csrc/api/include/torch/nn/modules.h:12,
                 from /home/n01pham/libtorch/include/torch/csrc/api/include/torch/nn.h:7,
                 from /home/n01pham/libtorch/include/torch/csrc/api/include/torch/all.h:6,
                 from /home/n01pham/libtorch/include/torch/csrc/api/include/torch/torch.h:3,
                 from /home/n01pham/Desktop/libtorch-yolov3/Darknet.h:11,
                 from /home/n01pham/Desktop/libtorch-yolov3/Darknet.cpp:10:
/home/n01pham/libtorch/include/torch/csrc/api/include/torch/nn/options/conv.h:46:43: error: ‘torch::ExpandingArray<2ul, long int> torch::nn::ConvOptions<2ul>::padding_’ is private
   TORCH_ARG(ExpandingArray<D>, padding) = 0;
                                           ^
/home/n01pham/Desktop/libtorch-yolov3/Darknet.cpp:137:18: error: within this context
     conv_options.padding_ = padding;
                  ^
In file included from /home/n01pham/libtorch/include/torch/csrc/api/include/torch/nn/modules/conv.h:5:0,
                 from /home/n01pham/libtorch/include/torch/csrc/api/include/torch/nn/modules.h:12,
                 from /home/n01pham/libtorch/include/torch/csrc/api/include/torch/nn.h:7,
                 from /home/n01pham/libtorch/include/torch/csrc/api/include/torch/all.h:6,
                 from /home/n01pham/libtorch/include/torch/csrc/api/include/torch/torch.h:3,
                 from /home/n01pham/Desktop/libtorch-yolov3/Darknet.h:11,
                 from /home/n01pham/Desktop/libtorch-yolov3/Darknet.cpp:10:
/home/n01pham/libtorch/include/torch/csrc/api/include/torch/nn/options/conv.h:71:32: error: ‘int64_t torch::nn::ConvOptions<2ul>::groups_’ is private
   TORCH_ARG(int64_t, groups) = 1;
                                ^
/home/n01pham/Desktop/libtorch-yolov3/Darknet.cpp:138:18: error: within this context
     conv_options.groups_ = groups;
                  ^
In file included from /home/n01pham/libtorch/include/torch/csrc/api/include/torch/nn/modules/conv.h:5:0,
                 from /home/n01pham/libtorch/include/torch/csrc/api/include/torch/nn/modules.h:12,
                 from /home/n01pham/libtorch/include/torch/csrc/api/include/torch/nn.h:7,
                 from /home/n01pham/libtorch/include/torch/csrc/api/include/torch/all.h:6,
                 from /home/n01pham/libtorch/include/torch/csrc/api/include/torch/torch.h:3,
                 from /home/n01pham/Desktop/libtorch-yolov3/Darknet.h:11,
                 from /home/n01pham/Desktop/libtorch-yolov3/Darknet.cpp:10:
/home/n01pham/libtorch/include/torch/csrc/api/include/torch/nn/options/conv.h:67:32: error: ‘bool torch::nn::ConvOptions<2ul>::with_bias_’ is private
   TORCH_ARG(bool, with_bias) = true;
                                ^
/home/n01pham/Desktop/libtorch-yolov3/Darknet.cpp:139:18: error: within this context
     conv_options.with_bias_ = with_bias;
                  ^
In file included from /home/n01pham/libtorch/include/torch/csrc/api/include/torch/nn/modules/batchnorm.h:4:0,
                 from /home/n01pham/libtorch/include/torch/csrc/api/include/torch/nn/modules.h:11,
                 from /home/n01pham/libtorch/include/torch/csrc/api/include/torch/nn.h:7,
                 from /home/n01pham/libtorch/include/torch/csrc/api/include/torch/all.h:6,
                 from /home/n01pham/libtorch/include/torch/csrc/api/include/torch/torch.h:3,
                 from /home/n01pham/Desktop/libtorch-yolov3/Darknet.h:11,
                 from /home/n01pham/Desktop/libtorch-yolov3/Darknet.cpp:10:
/home/n01pham/libtorch/include/torch/csrc/api/include/torch/nn/options/batchnorm.h: In function ‘torch::nn::BatchNormOptions bn_options(int64_t)’:
/home/n01pham/libtorch/include/torch/csrc/api/include/torch/nn/options/batchnorm.h:19:29: error: ‘bool torch::nn::BatchNormOptions::affine_’ is private
   TORCH_ARG(bool, affine) = true;
                             ^
/home/n01pham/Desktop/libtorch-yolov3/Darknet.cpp:145:16: error: within this context
     bn_options.affine_ = true;
                ^
In file included from /home/n01pham/libtorch/include/torch/csrc/api/include/torch/nn/modules/batchnorm.h:4:0,
                 from /home/n01pham/libtorch/include/torch/csrc/api/include/torch/nn/modules.h:11,
                 from /home/n01pham/libtorch/include/torch/csrc/api/include/torch/nn.h:7,
                 from /home/n01pham/libtorch/include/torch/csrc/api/include/torch/all.h:6,
                 from /home/n01pham/libtorch/include/torch/csrc/api/include/torch/torch.h:3,
                 from /home/n01pham/Desktop/libtorch-yolov3/Darknet.h:11,
                 from /home/n01pham/Desktop/libtorch-yolov3/Darknet.cpp:10:
/home/n01pham/libtorch/include/torch/csrc/api/include/torch/nn/options/batchnorm.h:24:31: error: ‘bool torch::nn::BatchNormOptions::stateful_’ is private
   TORCH_ARG(bool, stateful) = true;
                               ^
/home/n01pham/Desktop/libtorch-yolov3/Darknet.cpp:146:16: error: within this context
     bn_options.stateful_ = true;
                ^
/home/n01pham/Desktop/libtorch-yolov3/Darknet.cpp: In member function ‘at::Tensor UpsampleLayer::forward(at::Tensor)’:
/home/n01pham/Desktop/libtorch-yolov3/Darknet.cpp:170:21: warning: ‘using IntList = class c10::ArrayRef<long int>’ is deprecated [-Wdeprecated-declarations]
      torch::IntList sizes = x.sizes();
                     ^
In file included from /home/n01pham/libtorch/include/c10/util/Exception.h:6:0,
                 from /home/n01pham/libtorch/include/c10/core/Device.h:5,
                 from /home/n01pham/libtorch/include/c10/core/Allocator.h:6,
                 from /home/n01pham/libtorch/include/ATen/ATen.h:3,
                 from /home/n01pham/libtorch/include/torch/csrc/api/include/torch/types.h:3,
                 from /home/n01pham/libtorch/include/torch/csrc/api/include/torch/data/dataloader_options.h:4,
                 from /home/n01pham/libtorch/include/torch/csrc/api/include/torch/data/dataloader/base.h:3,
                 from /home/n01pham/libtorch/include/torch/csrc/api/include/torch/data/dataloader/stateful.h:3,
                 from /home/n01pham/libtorch/include/torch/csrc/api/include/torch/data/dataloader.h:3,
                 from /home/n01pham/libtorch/include/torch/csrc/api/include/torch/data.h:3,
                 from /home/n01pham/libtorch/include/torch/csrc/api/include/torch/all.h:4,
                 from /home/n01pham/libtorch/include/torch/csrc/api/include/torch/torch.h:3,
                 from /home/n01pham/Desktop/libtorch-yolov3/Darknet.h:11,
                 from /home/n01pham/Desktop/libtorch-yolov3/Darknet.cpp:10:
/home/n01pham/libtorch/include/c10/util/ArrayRef.h:278:1: note: declared here
 C10_DEFINE_DEPRECATED_USING(IntList, ArrayRef<int64_t>)
 ^
/home/n01pham/Desktop/libtorch-yolov3/Darknet.cpp: In member function ‘void Darknet::load_weights(const char*)’:
/home/n01pham/Desktop/libtorch-yolov3/Darknet.cpp:527:54: error: ‘class at::DeprecatedTypeProperties’ has no member named ‘tensorFromBlob’
     at::Tensor weights = torch::CPU(torch::kFloat32).tensorFromBlob(weights_src
                                                      ^
/home/n01pham/Desktop/libtorch-yolov3/Darknet.cpp:569:52: error: ‘class torch::nn::BatchNormImpl’ has no member named ‘running_variance’
    bn_running_var = bn_running_var.view_as(bn_imp->running_variance);
                                                    ^
/home/n01pham/Desktop/libtorch-yolov3/Darknet.cpp:574:12: error: ‘class torch::nn::BatchNormImpl’ has no member named ‘running_variance’
    bn_imp->running_variance.set_data(bn_running_var);
            ^
CMakeFiles/yolo-app.dir/build.make:62: recipe for target 'CMakeFiles/yolo-app.dir/Darknet.cpp.o' failed
make[2]: *** [CMakeFiles/yolo-app.dir/Darknet.cpp.o] Error 1
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

cpu可以用,gpu出错,请问是什么原因

libtorch 1.0,cuda9.0,

torch::Tensor Darknet::forward(torch::Tensor x)
{
int module_count = module_list.size();

std::vector<torch::Tensor> outputs(module_count);

torch::Tensor result;
int write = 0;

for (int i = 0; i < module_count; i++)
{
	map<string, string> block = blocks[i+1];

	string layer_type = block["type"];

	cout << layer_type << endl;

	if (layer_type == "net")
		continue;

	if (layer_type == "convolutional" || layer_type == "upsample" || layer_type == "maxpool")
	{
		torch::nn::SequentialImpl *seq_imp = dynamic_cast<torch::nn::SequentialImpl *>(module_list[i].ptr().get());
		
		x = seq_imp->forward(x);//这一句出错
		
		outputs[i] = x;
	}
	else if (layer_type == "route")
	{
		int start = std::stoi(block["start"]);
		int end = std::stoi(block["end"]);

		if (start > 0) start = start - i;

		if (end == 0)
		{
			x = outputs[i + start];
		}
		else
		{
			if (end > 0) end = end - i;

			torch::Tensor map_1 = outputs[i + start];
			torch::Tensor map_2 = outputs[i + end];

			x = torch::cat({map_1, map_2}, 1);
		}

		outputs[i] = x;
	}
	else if (layer_type == "shortcut")
	{
		int from = std::stoi(block["from"]);
		x = outputs[i-1] + outputs[i+from];
        outputs[i] = x;
	}
	else if (layer_type == "yolo")
	{
		torch::nn::SequentialImpl *seq_imp = dynamic_cast<torch::nn::SequentialImpl *>(module_list[i].ptr().get());

		map<string, string> net_info = blocks[0];
		int inp_dim = get_int_from_cfg(net_info, "height", 0);
		int num_classes = get_int_from_cfg(block, "classes", 0);

		x = seq_imp->forward(x, inp_dim, num_classes, *_device);

		if (write == 0)
		{
			result = x;
			write = 1;
		}
		else
		{
			result = torch::cat({result,x}, 1);
		}

		outputs[i] = outputs[i-1];
	}
}
return result;

}

支持最新的libtorch1.6版本

OS: Win 10 64
Libtorch: 1.6
Visual Studio 2017 (VC15)
OpenCV: 4.4 (win pre-build)
使用该库调用最新的libtorch的话会出现接口不兼容的问题,出现下面这些错误:

  1. Darknet.cpp(18): error C2039: “isspace”: 不是“std”的成员

  2. Darknet.cpp(139): error C2039: “with_bias”: 不是“torch::nn::ConvOptions<2>”的成员

  3. Darknet.cpp(146): error C2039: “stateful”: 不是“torch::nn::BatchNormOptions

  4. Darknet.cpp(380): error C2039: “BatchNorm”: 不是“torch::nn”的成员

  5. Darknet.cpp(526): error C2039: “is_variable”: 不是“c10::TensorOptions”的成员

  6. Darknet.cpp(550): error C2039: “BatchNormImpl”: 不是“torch::nn”的成员

相应的解决办法:

  1. 添加头文件#include
  2. 将with_bias改为bias
    image
  3. 修改为track_running_stats:
    image
  4. 修改为BathNorm2d
    image
  5. 没找到对应的属性,直接注释了
    image
  6. 修改为BatchNorm2dImpl:
    image

其实就是libtorch的接口还不稳定导致不同版本之间不兼容。
另外注意事项:

  1. cmakelists.txt需要手动添加opencv地址
  2. 64位框架编译:cmake -G "Visual Studio 15 2017 Win64" -T host=x64 -DCMAKE_PREFIX_PATH="E:\MachineLearn ing\libtorch" ..
  3. 运行程序的时候要复制libtorch的dll文件到执行路径

最后将修改后的程序托管在地址:https://github.com/ouening/libtorch1.6-yolov3

runtime error, variadic.h error template

template <typename ReturnType, typename... Ts, typename Function, typename Accessor>
ReturnType unpack(Function function, Accessor accessor) {
return ReturnType(unpack<ReturnType, Ts...>(
std::move(function),
std::move(accessor),
typename MakeIndices<sizeof...(Ts)>::indices()));
}

template <typename ReturnType, typename... Ts, typename Function, typename Accessor, size_t... Is>
ReturnType unpack(Function function, Accessor accessor, Indices<Is...>) {
return ReturnType(function(accessor.template operator()(Is)...));
}

错误 C2059 语法错误:“template” yolo-app E:\correct\libtorch\include\torch\csrc\utils\variadic.h 195
严重性 代码 说明 项目 文件 行 禁止显示状态
错误 C2951 模板 声明只能在全局、命名空间或类范围内使用 yolo-app E:\correct\libtorch\include\torch\csrc\utils\variadic.h 195

build error in visual studio 2017

i already built the project using cmake , then i am trying to generate the .exe file by build .sln file using visual studio 2017 ,
but i got those errors in the code :

attribute does not apply to any entity
'split': must return a value

Untitled

1

Any Help :)

detects pedestrians

hi,thank your code.
I trained a model that only detects pedestrians,nums=1(not 80)
Does the code need to be changed?

could run with cpu but not with CUDA

thanks for your great work. I could run it with cpu and gpu in my PC, but when i planted the code from PC to NVIDIA TX2, errors came. I could run with cpu but not with cuda. details was that:
terminate called after throwing an instance of 'std::runtime_error'
what():
Tensor for argument #4 'running_mean' is on CPU, but expected it to be on GPU (while checking arguments for cudnn_batch_norm) (checkSameGPU at /home/nvidia/workspace/wangh/libraries/pytorch/aten/src/ATen/TensorUtils.cpp:122)
frame #0: c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&) + 0x7c (0x7f7dc40374 in /home/nvidia/workspace/wangh/libraries/pytorch/torch/lib/libc10.so)
frame #1: at::checkSameGPU(char const*, at::TensorArg const&, at::TensorArg const&) + 0xbec (0x7f904c771c in /home/nvidia/workspace/wangh/libraries/pytorch/torch/lib/libcaffe2.so)
frame #2: at::checkAllSameGPU(char const*, c10::ArrayRefat::TensorArg) + 0x44 (0x7f904c8374 in /home/nvidia/workspace/wangh/libraries/pytorch/torch/lib/libcaffe2.so)
frame #3: at::native::cudnn_batch_norm(at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor const&, bool, double, double) + 0x3b8 (0x7f7e9ef918 in /home/nvidia/workspace/wangh/libraries/pytorch/torch/lib/libcaffe2_gpu.so)
frame #4: at::CUDAFloatType::cudnn_batch_norm(at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor const&, bool, double, double) const + 0xd8 (0x7f7eadd968 in /home/nvidia/workspace/wangh/libraries/pytorch/torch/lib/libcaffe2_gpu.so)
frame #5: torch::autograd::VariableType::cudnn_batch_norm(at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor const&, bool, double, double) const + 0x568 (0x7f93da2160 in /home/nvidia/workspace/wangh/libraries/pytorch/torch/lib/libtorch.so.1)
frame #6: at::native::_batch_norm_impl_index(at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor const&, bool, double, double, bool) + 0x3a0 (0x7f905463e0 in /home/nvidia/workspace/wangh/libraries/pytorch/torch/lib/libcaffe2.so)
frame #7: at::TypeDefault::_batch_norm_impl_index(at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor const&, bool, double, double, bool) const + 0xe4 (0x7f90976f74 in /home/nvidia/workspace/wangh/libraries/pytorch/torch/lib/libcaffe2.so)
frame #8: torch::autograd::VariableType::_batch_norm_impl_index(at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor const&, bool, double, double, bool) const + 0x2a4 (0x7f93d1d1ac in /home/nvidia/workspace/wangh/libraries/pytorch/torch/lib/libtorch.so.1)
frame #9: at::native::batch_norm(at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor const&, bool, double, double, bool) + 0x8c (0x7f90544dac in /home/nvidia/workspace/wangh/libraries/pytorch/torch/lib/libcaffe2.so)
frame #10: at::TypeDefault::batch_norm(at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor const&, bool, double, double, bool) const + 0xe4 (0x7f90976e04 in /home/nvidia/workspace/wangh/libraries/pytorch/torch/lib/libcaffe2.so)
frame #11: torch::autograd::VariableType::batch_norm(at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor const&, bool, double, double, bool) const + 0x21c (0x7f93d1ecdc in /home/nvidia/workspace/wangh/libraries/pytorch/torch/lib/libtorch.so.1)
frame #12: + 0x7cc8ac (0x7f93e6d8ac in /home/nvidia/workspace/wangh/libraries/pytorch/torch/lib/libtorch.so.1)
frame #13: + 0x88a660 (0x7f93f2b660 in /home/nvidia/workspace/wangh/libraries/pytorch/torch/lib/libtorch.so.1)
frame #14: torch::jit::InterpreterState::run(std::vector<c10::IValue, std::allocatorc10::IValue >&) + 0x38 (0x7f93f26838 in /home/nvidia/workspace/wangh/libraries/pytorch/torch/lib/libtorch.so.1)
frame #15: torch::jit::GraphExecutor::run(std::vector<c10::IValue, std::allocatorc10::IValue >&) + 0x188 (0x7f93f06cd0 in /home/nvidia/workspace/wangh/libraries/pytorch/torch/lib/libtorch.so.1)
frame #16: torch::jit::script::Method::run(std::vector<c10::IValue, std::allocatorc10::IValue >&) + 0x98 (0x4dfe64 in ./yolo-app)
frame #17: torch::jit::script::Method::operator()(std::vector<c10::IValue, std::allocatorc10::IValue >) + 0x30 (0x4dfec0 in ./yolo-app)
frame #18: torch::jit::script::Module::forward(std::vector<c10::IValue, std::allocatorc10::IValue >) + 0x84 (0x4e0fa4 in ./yolo-app)
frame #19: classifier(std::shared_ptrtorch::jit::script::Module, at::Tensor) + 0xfc (0x4d6760 in ./yolo-app)
frame #20: main + 0xc88 (0x4d8954 in ./yolo-app)
frame #21: __libc_start_main + 0xe0 (0x7f7cf718a0 in /lib/aarch64-linux-gnu/libc.so.6)
:
operation failed in interpreter:
op_version_set = 0
def forward(self,
input_1: Tensor) -> Tensor:
input_2 = torch.convolution(input_1, getattr(self.layer1, "0").weight, None, [1, 3], [0, 0], [1, 1], False, [0, 0], 1, False, False, True)
0 = torch.add(getattr(self.layer1, "1").num_batches_tracked, CONSTANTS.c0, alpha=1)
input_3 = torch.batch_norm(input_2, getattr(self.layer1, "1").weight, getattr(self.layer1, "1").bias, getattr(self.layer1, "1").running_mean, getattr(self.layer1, "1").running_var, True, 0.10000000000000001, 1.0000000000000001e-05, True)
~~~~~~~~~~~~~~~~ <--- HERE
input_4 = torch.threshold
(input_3, 0., 0.)
input_5, _1 = torch.max_pool2d_with_indices(input_4, [2, 2], [2, 2], [0, 0], [1, 1], False)
input_6 = torch.convolution(input_5, getattr(self.layer2, "0").weight, None, [1, 1], [2, 0], [1, 1], False, [0, 0], 2, False, False, True)
2 = torch.add(getattr(self.layer2, "1").num_batches_tracked, CONSTANTS.c0, alpha=1)
input_7 = torch.batch_norm(input_6, getattr(self.layer2, "1").weight, getattr(self.layer2, "1").bias, getattr(self.layer2, "1").running_mean, getattr(self.layer2, "1").running_var, True, 0.10000000000000001, 1.0000000000000001e-05, True)
input_8 = torch.threshold
(input_7, 0., 0.)
input_9, _3 = torch.max_pool2d_with_indices(input_8, [3, 3], [2, 2], [1, 0], [1, 1], False)
input_10 = torch._convolution(input_9, getattr(self.layer3, "0").weight, None, [1, 1], [1, 1], [1, 1], False, [0, 0], 1, False, False, True)
4 = torch.add(getattr(self.layer3, "1").num_batches_tracked, CONSTANTS.c0, alpha=1)
Aborted (core dumped)
why?

Performance problem

Hi,

thanks for the nice work, it seems however, that there is still a performance problem when running on GPU, i.e. the code cannot fully utilize the GPU and has high CPU usage when running on GPU. Steps to reproduce:

  • modify the code so that you create an endless loop around these two calls - net.forward and net.write_results,

  • on my GPU the GPU load goes up to 60 - 70 percent, not higher and CPU goes up to 20 percent.

Expected result: GPU load should go up to 100 percent and CPU usage should be small.

Any thoughts on the CPU consumption? It also might be a libtorch issue though...

Thanks.

crash while load_weights

loading weight ...
terminate called after throwing an instance of 'c10::Error'
what(): !is_variable() ASSERT FAILED at /pytorch/c10/core/TensorImpl.h:922, please report a bug to PyTorch. (shallow_copy_and_detach at /pytorch/c10/core/TensorImpl.h:922)
frame #0: std::function<std::string ()>::operator()() const + 0x11 (0x7efc2cd3f441 in /home/youyi/Documents/packages/libtorch/lib/libc10.so)
frame #1: c10::Error::Error(c10::SourceLocation, std::string const&) + 0x2a (0x7efc2cd3ed7a in /home/youyi/Documents/packages/libtorch/lib/libc10.so)
frame #2: + 0x95063d (0x7efc2d8a863d in /home/youyi/Documents/packages/libtorch/lib/libtorch.so.1)
frame #3: torch::autograd::Variable::Impl::set_data(at::Tensor const&) + 0x268 (0x7efc2d8a4b58 in /home/youyi/Documents/packages/libtorch/lib/libtorch.so.1)
frame #4: at::Tensor::set_data(at::Tensor) + 0x61 (0x564f2799e459 in ./yolo-app)
frame #5: Darknet::load_weights(char const*) + 0x816 (0x564f279980c0 in ./yolo-app)
frame #6: main + 0x1a1 (0x564f279d670d in ./yolo-app)
frame #7: __libc_start_main + 0xe7 (0x7efc1de31b97 in /lib/x86_64-linux-gnu/libc.so.6)
frame #8: _start + 0x2a (0x564f2799262a in ./yolo-app)

based on pytorch 1.1.0

error in main.cpp

I downlown the code and run in Ubuntu16.06
my cmakelist is
`
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(yolo-app)

set(CMAKE_CXX_STANDARD 14)
set(Torch_DIR /home/zyy/libtorch/share/cmake/Torch)
set(OpenCV_DIR /home/tusvision/Downloads/opencv-3.4/opencv/build)

find_package(Torch REQUIRED)
find_package(OpenCV REQUIRED)

add_executable(yolo-app main.cpp)
target_link_libraries(yolo-app "${TORCH_LIBRARIES}" "${OpenCV_LIBS}")
set_property(TARGET yolo-app PROPERTY CXX_STANDARD 11)
`
My folder is
yolo-app/main.cpp 、darknet.h darknet.cpp

cmake .
Usage

cmake [options]
cmake [options]

Specify a source directory to (re-)generate a build system for it in the
current working directory. Specify an existing build directory to
re-generate its build system.

Run 'cmake --help' for more information.

zyy@TusVision:~/yolo-app$ cmake .
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Found CUDA: /usr/local/cuda (found suitable version "9.0", minimum required is "7.0")
-- Caffe2: CUDA detected: 9.0
-- Caffe2: CUDA nvcc is: /usr/local/cuda/bin/nvcc
-- Caffe2: CUDA toolkit directory: /usr/local/cuda
-- Caffe2: Header version is: 9.0
-- Found CUDNN: /usr/local/cuda/include
-- Found cuDNN: v7.2.1 (include: /usr/local/cuda/include, library: /usr/local/cuda/lib64/libcudnn.so)
-- Autodetected CUDA architecture(s): 6.1;6.1
-- Added CUDA NVCC flags for: -gencode;arch=compute_61,code=sm_61
-- Found torch: /home/zyy/libtorch/lib/libtorch.so
-- Found OpenCV: /home/tusvision/Downloads/opencv-3.4/opencv/build (found version "3.4.1")
-- Configuring done
-- Generating done
-- Build files have been written to: /home/zyy/yolo-app

make
zyy@TusVision:~/yolo-app$ make
Scanning dependencies of target yolo-app
[ 50%] Building CXX object CMakeFiles/yolo-app.dir/main.cpp.o
[100%] Linking CXX executable yolo-app
CMakeFiles/yolo-app.dir/main.cpp.o: In function main': main.cpp:(.text+0xc1b): undefined reference to Darknet::Darknet(char const*, c10::Device*)'
main.cpp:(.text+0xc2a): undefined reference to Darknet::get_net_info()' main.cpp:(.text+0xd09): undefined reference to Darknet::load_weights(char const*)'
main.cpp:(.text+0x11ab): undefined reference to Darknet::forward(at::Tensor)' main.cpp:(.text+0x1205): undefined reference to Darknet::write_results(at::Tensor, int, float, float)'
collect2: error: ld returned 1 exit status
CMakeFiles/yolo-app.dir/build.make:168: recipe for target 'yolo-app' failed
make[2]: *** [yolo-app] Error 1
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

the main.cpp error

Running your code gives the following error

error: ‘class at::DeprecatedTypeProperties’ has no member named ‘tensorFromBlob’
at::Tensor weights = torch::CPU(torch::kFloat32).tensorFromBlob(weights_src, {length/4});

Can you please guide a little how to modify it according to the newer version

std::runtime errror with libotrch cpu 1.0.0

./yolo-app ../imgs/messi.jpg
loading weight ...
terminate called after throwing an instance of 'std::runtime_error'
  what():  shape '[64, 128, 1, 1]' is invalid for input of size 7758
Aborted (core dumped)

Libtorch batch input

I have a question.
In inference stage, I want to set batch to four, processing four channels of video at the same time.
How should I do? Thank you !

terminate called after throwing an instance of 'c10::Error'

This error showed when loading the weights file:

terminate called after throwing an instance of 'c10::Error'
what(): !is_variable() INTERNAL ASSERT FAILED at /pytorch/c10/core/TensorImpl.h:927, please report a bug to PyTorch. (shallow_copy_and_detach at /pytorch/c10/core/TensorImpl.h:927)
frame #0: std::function<std::string ()>::operator()() const + 0x11 (0x7f54a6c17961 in /home/zhengli/Pytorch/libtorch-shared-with-deps-latest/libtorch/lib/libc10.so)
frame #1: c10::Error::Error(c10::SourceLocation, std::string const&) + 0x2a (0x7f54a6c1729a in /home/zhengli/Pytorch/libtorch-shared-with-deps-latest/libtorch/lib/libc10.so)
frame #2: + 0x2f662b9 (0x7f549de102b9 in /home/zhengli/Pytorch/libtorch-shared-with-deps-latest/libtorch/lib/libcaffe2.so)
frame #3: torch::autograd::Variable::Impl::set_data(at::Tensor const&) + 0x278 (0x7f549de0d5b8 in /home/zhengli/Pytorch/libtorch-shared-with-deps-latest/libtorch/lib/libcaffe2.so)
frame #4: at::Tensor::set_data(at::Tensor) + 0x53 (0x558b6a423363 in ./yolo-app)
frame #5: Darknet::load_weights(char const*) + 0x625 (0x558b6a416335 in ./yolo-app)
frame #6: main + 0x206 (0x558b6a40ef06 in ./yolo-app)
frame #7: __libc_start_main + 0xe7 (0x7f5499755b97 in /lib/x86_64-linux-gnu/libc.so.6)
frame #8: _start + 0x2a (0x558b6a40ff7a in ./yolo-app)

Aborted (core dumped)

Does anyone have the same problem?

Specified type of detection

thanks your work, it's great.
I just want to detect a specific kind of object and what to do.(For example, only people are tested.)
hope your reply,thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.