pytorch / pytorch

Tensors and Dynamic neural networks in Python with strong GPU acceleration
https://pytorch.org
Other
83.99k stars 22.64k forks source link

Warning when link libtorch and opencv4.2.0 together #33049

Open stereomatchingkiss opened 4 years ago

stereomatchingkiss commented 4 years ago

To Reproduce

Steps to reproduce the behavior:

  1. Download official opencv4.2.0
  2. Download libtorch1.4.0 of windows 64 bits, cpu version
  3. Create CMakeLists.txt
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)

project(person_reid)    

set(LIBTORCH_PATH ${CMAKE_CURRENT_LIST_DIR}/../../3rdLibs/libtorch/libtorch_cpu_1_4_0/)
set(OPENCV_CV_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../3rdLibs/opencv/opencv_4_2_0/opencv/build/)

set(CMAKE_PREFIX_PATH "${OPENCV_CV_PATH};${LIBTORCH_PATH};${CMAKE_PREFIX_PATH};")

find_package(OpenCV REQUIRED)
find_package(Torch REQUIRED)

file(GLOB UTILS_SRC
    "*.hpp"
    "*.cpp"
)

add_executable(person_reid ${UTILS_SRC})
target_link_libraries(person_reid "${TORCH_LIBRARIES};${OpenCV_LIBS}")
set_property(TARGET person_reid PROPERTY CXX_STANDARD 11)
  1. Codes
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>

#include <iostream>
#include <memory>

//#undef slots
#include <torch/script.h>
//#def slots Q_SLOTS

int main()try
{
    cv::Mat img = cv::imread("some.jpg");
    // Deserialize the ScriptModule from a file using torch::jit::load().
    torch::jit::script::Module module = torch::jit::load("traced_osnet_ain_x1_0.pt");   
}catch(std::exception const &ex){
    std::cerr << ex.what() << "\n";
    return -1;
}
  1. Build with release version

Expected behavior

Compile without any warnings

Environment

Please copy and paste the output from our environment collection script (or fill out the checklist below manually).

Warnings

cl : Command line warning D9025 : overriding '/EHs' with '/EHa'
C:\Users\yyyy\programs\Qt\3rdLibs\libtorch\libtorch_cpu_1_4_0\include\torch/csrc/jit/tracer.h(289): warning C4273: 'torch::jit::tracer::addInputs': inconsistent dll linkage
C:\Users\yyyy\programs\Qt\3rdLibs\libtorch\libtorch_cpu_1_4_0\include\torch/csrc/jit/tracer.h(277): note: see previous definition of 'addInputs'
C:\Users\yyyy\programs\Qt\3rdLibs\libtorch\libtorch_cpu_1_4_0\include\torch/csrc/jit/tracer.h(296): warning C4273: 'torch::jit::tracer::addInputs': inconsistent dll linkage
C:\Users\yyyy\programs\Qt\3rdLibs\libtorch\libtorch_cpu_1_4_0\include\torch/csrc/jit/tracer.h(283): note: see previous definition of 'addInputs'
stereomatchingkiss commented 4 years ago

Maybe I should build the libtorch by myself, any tutorials of building libtorch(with cuda) on windows?Thanks

peterjc123 commented 4 years ago

Please read this post. https://discuss.pytorch.org/t/numerous-compiler-warnings/67727

fmassa commented 4 years ago

There are currently a number of warnings in libtorch. Removing them all will be a large task, but it can be tackled independently