facebookarchive / caffe2

Caffe2 is a lightweight, modular, and scalable deep learning framework.
https://caffe2.ai
Apache License 2.0
8.42k stars 1.95k forks source link

Error compiling caffe2 using opencv 3.4 #1671

Open LaurentBerger opened 6 years ago

LaurentBerger commented 6 years ago

I have got these errors during compilation in image_input_op.h:

3>image_input_op.cc
3>G:\Lib\caffe2\caffe2/image/image_input_op.h(179): warning C4305: 'argument': truncation from 'double' to 'const float'
3>G:\Lib\caffe2\caffe2/image/image_input_op.h(164): note: while compiling class template member function 'caffe2::ImageInputOp<caffe2::CPUContext>::ImageInputOp(const caffe2::OperatorDef &,caffe2::Workspace *)'
3>G:\Lib\caffe2\caffe2/core/registry.h(142): note: see reference to function template instantiation 'caffe2::ImageInputOp<caffe2::CPUContext>::ImageInputOp(const caffe2::OperatorDef &,caffe2::Workspace *)' being compiled
3>G:\Lib\caffe2\caffe2/core/registry.h(142): note: see reference to class template instantiation 'caffe2::ImageInputOp<caffe2::CPUContext>' being compiled
3>G:\Lib\caffe2\caffe2\image\image_input_op.cc(21): note: see reference to function template instantiation 'ObjectPtrType caffe2::Registerer<std::string,ObjectPtrType,const caffe2::OperatorDef &,caffe2::Workspace *>::DefaultCreator<caffe2::ImageInputOp<caffe2::CPUContext>>(const caffe2::OperatorDef &,caffe2::Workspace *)' being compiled
3>        with
3>        [
3>            ObjectPtrType=std::unique_ptr<caffe2::OperatorBase,std::default_delete<caffe2::OperatorBase>>
3>        ]
3>G:\Lib\caffe2\caffe2\image\image_input_op.cc(21): note: see reference to function template instantiation 'ObjectPtrType caffe2::Registerer<std::string,ObjectPtrType,const caffe2::OperatorDef &,caffe2::Workspace *>::DefaultCreator<caffe2::ImageInputOp<caffe2::CPUContext>>(const caffe2::OperatorDef &,caffe2::Workspace *)' being compiled
3>        with
3>        [
3>            ObjectPtrType=std::unique_ptr<caffe2::OperatorBase,std::default_delete<caffe2::OperatorBase>>
3>        ]
3>G:\Lib\caffe2\caffe2/image/image_input_op.h(182): warning C4305: 'argument': truncation from 'double' to 'const float'
3>G:\Lib\caffe2\caffe2/image/image_input_op.h(184): warning C4305: 'argument': truncation from 'double' to 'const float'
3>G:\Lib\caffe2\caffe2/image/image_input_op.h(189): warning C4305: 'argument': truncation from 'double' to 'const float'
3>G:\Lib\caffe2\caffe2/image/image_input_op.h(259): error C2398: Element '1': conversion from 'double' to 'float' requires a narrowing conversion
3>G:\Lib\caffe2\caffe2/image/image_input_op.h(259): error C2398: Element '2': conversion from 'double' to 'float' requires a narrowing conversion
3>G:\Lib\caffe2\caffe2/image/image_input_op.h(259): error C2398: Element '3': conversion from 'double' to 'float' requires a narrowing conversion
3>G:\Lib\caffe2\caffe2/image/image_input_op.h(259): warning C4305: 'initializing': truncation from 'double' to 'float'
3>G:\Lib\caffe2\caffe2/image/image_input_op.h(261): error C2398: Element '1': conversion from 'double' to 'float' requires a narrowing conversion
3>G:\Lib\caffe2\caffe2/image/image_input_op.h(261): error C2398: Element '2': conversion from 'double' to 'float' requires a narrowing conversion
3>G:\Lib\caffe2\caffe2/image/image_input_op.h(261): error C2398: Element '3': conversion from 'double' to 'float' requires a narrowing conversion
3>G:\Lib\caffe2\caffe2/image/image_input_op.h(261): warning C4305: 'initializing': truncation from 'double' to 'float'
3>G:\Lib\caffe2\caffe2/image/image_input_op.h(263): error C2398: Element '1': conversion from 'double' to 'float' requires a narrowing conversion
3>G:\Lib\caffe2\caffe2/image/image_input_op.h(263): error C2398: Element '2': conversion from 'double' to 'float' requires a narrowing conversion
3>G:\Lib\caffe2\caffe2/image/image_input_op.h(263): error C2398: Element '3': conversion from 'double' to 'float' requires a narrowing conversion
3>G:\Lib\caffe2\caffe2/image/image_input_op.h(263): warning C4305: 'initializing': truncation from 'double' to 'float'
3>G:\Lib\caffe2\caffe2/image/image_input_op.h(265): error C2398: Element '1': conversion from 'double' to 'float' requires a narrowing conversion
3>G:\Lib\caffe2\caffe2/image/image_input_op.h(265): error C2398: Element '2': conversion from 'double' to 'float' requires a narrowing conversion
3>G:\Lib\caffe2\caffe2/image/image_input_op.h(265): error C2398: Element '3': conversion from 'double' to 'float' requires a narrowing conversion
3>G:\Lib\caffe2\caffe2/image/image_input_op.h(265): warning C4305: 'initializing': truncation from 'double' to 'float'
3>Done building project "caffe2.vcxproj" -- FAILED.

Add F after constants solve this issue.

pjh5 commented 6 years ago

This is a bug on our part. I will put out a PR to fix this.

If you don't want to wait for the PR, then I'm pretty sure the fix is to add a 'f' after all of the decimal numbers in image_input_op.h . For example, change '0.4' to '0.4f'

II-Matto commented 6 years ago

@pjh5 Hi, the problem still exists. The PR https://github.com/pytorch/pytorch/pull/7024 only fixed caffe2/operators/roi_align_op_gpu_test.cc.