walktree / libtorch-yolov3

A Libtorch implementation of the YOLO v3 object detection algorithm
450 stars 131 forks source link

支持最新的libtorch1.6版本 #52

Closed ouening closed 4 years ago

ouening commented 4 years ago

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

changanxiaofan commented 3 years ago

thanks