caffe2_cpp_tutorial icon indicating copy to clipboard operation
caffe2_cpp_tutorial copied to clipboard

Make error : caffe2::Tensor is not a template

Open shahruk10 opened this issue 7 years ago • 10 comments

Hi, I am receiving this error while trying to run make :

make[1]: Entering directory '/home/shahruk/caffe2_cpp_tutorial/build'
make[2]: Entering directory '/home/shahruk/caffe2_cpp_tutorial/build'
make[3]: Entering directory '/home/shahruk/caffe2_cpp_tutorial/build'
make[3]: Leaving directory '/home/shahruk/caffe2_cpp_tutorial/build'
make[3]: Entering directory '/home/shahruk/caffe2_cpp_tutorial/build'

[  1%] Building CXX object CMakeFiles/caffe2_cpp.dir/src/caffe2/operator/affine_scale_op.cc.o
/home/shahruk/caffe2_cpp_tutorial/src/caffe2/operator/affine_scale_op.cc:6:36: error: ‘caffe2::Tensor’ is not a template
 void get_affine_scale_tensor(const Tensor<C>& tensor, const Tensor<C>& mean,
                                    ^
/home/shahruk/caffe2_cpp_tutorial/src/caffe2/operator/affine_scale_op.cc:6:61: error: ‘caffe2::Tensor’ is not a template
 void get_affine_scale_tensor(const Tensor<C>& tensor, const Tensor<C>& mean,
                                                             ^
/home/shahruk/caffe2_cpp_tutorial/src/caffe2/operator/affine_scale_op.cc:7:36: error: ‘caffe2::Tensor’ is not a template
                              const Tensor<C>& scale, Tensor<C>& transformed,
                                    ^
/home/shahruk/caffe2_cpp_tutorial/src/caffe2/operator/affine_scale_op.cc:7:54: error: ‘caffe2::Tensor’ is not a template
                              const Tensor<C>& scale, Tensor<C>& transformed,
                                                      ^
/home/shahruk/caffe2_cpp_tutorial/src/caffe2/operator/affine_scale_op.cc:26:30: error: ‘caffe2::Tensor’ is not a template
 void set_affine_scale_tensor(Tensor<C>& tensor, const Tensor<C>& scale,
                              ^
/home/shahruk/caffe2_cpp_tutorial/src/caffe2/operator/affine_scale_op.cc:26:55: error: ‘caffe2::Tensor’ is not a template
 void set_affine_scale_tensor(Tensor<C>& tensor, const Tensor<C>& scale,
                                                       ^
/home/shahruk/caffe2_cpp_tutorial/src/caffe2/operator/affine_scale_op.cc:27:36: error: ‘caffe2::Tensor’ is not a template
                              const Tensor<C>& transformed,
                                    ^
/home/shahruk/caffe2_cpp_tutorial/src/caffe2/operator/affine_scale_op.cc: In member function ‘bool caffe2::AffineScaleOp<T, Context>::RunOnDevice() [with T = float; Context = caffe2::CPUContext]’:
/home/shahruk/caffe2_cpp_tutorial/src/caffe2/operator/affine_scale_op.cc:51:48: error: no matching function for call to ‘get_affine_scale_tensor(const caffe2::Tensor&, const caffe2::Tensor&, const caffe2::Tensor&, caffe2::Tensor&, int&)’
   get_affine_scale_tensor(X, M, S, *Y, inverse_);
                                                ^
/home/shahruk/caffe2_cpp_tutorial/src/caffe2/operator/affine_scale_op.cc:6:6: note: candidate: template<class C> void caffe2::get_affine_scale_tensor(const caffe2::Tensor&, const caffe2::Tensor&, const caffe2::Tensor&, caffe2::Tensor&, bool)
 void get_affine_scale_tensor(const Tensor<C>& tensor, const Tensor<C>& mean,
      ^
/home/shahruk/caffe2_cpp_tutorial/src/caffe2/operator/affine_scale_op.cc:6:6: note:   template argument deduction/substitution failed:
/home/shahruk/caffe2_cpp_tutorial/src/caffe2/operator/affine_scale_op.cc:51:48: note:   couldn't deduce template parameter ‘C’
   get_affine_scale_tensor(X, M, S, *Y, inverse_);
                                                ^
/home/shahruk/caffe2_cpp_tutorial/src/caffe2/operator/affine_scale_op.cc: In member function ‘bool caffe2::AffineScaleGradientOp<T, Context>::RunOnDevice() [with T = float; Context = caffe2::CPUContext]’:
/home/shahruk/caffe2_cpp_tutorial/src/caffe2/operator/affine_scale_op.cc:62:47: error: no matching function for call to ‘set_affine_scale_tensor(caffe2::Tensor&, const caffe2::Tensor&, const caffe2::Tensor&, int&)’
   set_affine_scale_tensor(*dX, S, dY, inverse_);
                                               ^
/home/shahruk/caffe2_cpp_tutorial/src/caffe2/operator/affine_scale_op.cc:26:6: note: candidate: template<class C> void caffe2::set_affine_scale_tensor(caffe2::Tensor&, const caffe2::Tensor&, const caffe2::Tensor&, bool)
 void set_affine_scale_tensor(Tensor<C>& tensor, const Tensor<C>& scale,
      ^
/home/shahruk/caffe2_cpp_tutorial/src/caffe2/operator/affine_scale_op.cc:26:6: note:   template argument deduction/substitution failed:
/home/shahruk/caffe2_cpp_tutorial/src/caffe2/operator/affine_scale_op.cc:62:47: note:   couldn't deduce template parameter ‘C’
   set_affine_scale_tensor(*dX, S, dY, inverse_);
                                               ^
CMakeFiles/caffe2_cpp.dir/build.make:62: recipe for target 'CMakeFiles/caffe2_cpp.dir/src/caffe2/operator/affine_scale_op.cc.o' failed
make[3]: *** [CMakeFiles/caffe2_cpp.dir/src/caffe2/operator/affine_scale_op.cc.o] Error 1
make[3]: Leaving directory '/home/shahruk/caffe2_cpp_tutorial/build'
CMakeFiles/Makefile2:337: recipe for target 'CMakeFiles/caffe2_cpp.dir/all' failed
make[2]: *** [CMakeFiles/caffe2_cpp.dir/all] Error 2
make[2]: Leaving directory '/home/shahruk/caffe2_cpp_tutorial/build'
Makefile:83: recipe for target 'all' failed
make[1]: *** [all] Error 2
make[1]: Leaving directory '/home/shahruk/caffe2_cpp_tutorial/build'
Makefile:4: recipe for target 'all' failed
make: *** [all] Error 2

Any help would be appreciated.

My environment is

Ubuntu : 16.04
g++ : 5.4
Caffe2 : newest version from https://caffe2.ai/docs/getting-started.html?platform=ubuntu&configuration=compile

shahruk10 avatar Aug 08 '18 02:08 shahruk10

I also got an issue regarding Tensor when I tried to build the whole thing.

carlos@carlos-ubuntu:~/Documents/git/Caffe2_Demo/03_cpp_forward/build$ make
Scanning dependencies of target classifier
[ 50%] Building CXX object CMakeFiles/classifier.dir/main.cpp.o
/home/carlos/Documents/git/Caffe2_Demo/03_cpp_forward/main.cpp: In function ‘void caffe2::run()’:
/home/carlos/Documents/git/Caffe2_Demo/03_cpp_forward/main.cpp:115:15: error: use of deleted function ‘caffe2::Tensor::Tensor()’
     TensorCPU input;
               ^
In file included from /usr/local/include/caffe2/core/blob.h:13:0,
                 from /usr/local/include/caffe2/core/workspace.h:14,
                 from /home/carlos/Documents/git/Caffe2_Demo/03_cpp_forward/main.cpp:11:
/usr/local/include/caffe2/core/tensor.h:94:3: note: declared here
   Tensor() = delete;
   ^
/home/carlos/Documents/git/Caffe2_Demo/03_cpp_forward/main.cpp:137:77: error: use of deleted function ‘caffe2::Tensor::Tensor(const caffe2::Tensor&)’
     auto softmax = TensorCPU(workSpace.GetBlob("softmax")->Get<TensorCUDA>());
                                                                             ^
In file included from /usr/local/include/caffe2/core/blob.h:13:0,
                 from /usr/local/include/caffe2/core/workspace.h:14,
                 from /home/carlos/Documents/git/Caffe2_Demo/03_cpp_forward/main.cpp:11:
/usr/local/include/caffe2/core/tensor.h:739:3: note: declared here
   Tensor(const Tensor& src) = delete;
   ^
In file included from /usr/local/include/caffe2/core/workspace.h:14:0,
                 from /home/carlos/Documents/git/Caffe2_Demo/03_cpp_forward/main.cpp:11:
/usr/local/include/caffe2/core/blob.h: In instantiation of ‘T* caffe2::Blob::GetMutable() [with T = caffe2::Tensor]’:
/home/carlos/Documents/git/Caffe2_Demo/03_cpp_forward/main.cpp:121:67:   required from here
/usr/local/include/caffe2/core/blob.h:121:5: error: static assertion failed: GetMutable can't be called with non-default-constructible types. Try using specialized methods
     static_assert(
     ^
/usr/local/include/caffe2/core/blob.h:129:22: error: use of deleted function ‘caffe2::Tensor::Tensor()’
       return Reset<T>(new T());
                      ^
In file included from /usr/local/include/caffe2/core/blob.h:13:0,
                 from /usr/local/include/caffe2/core/workspace.h:14,
                 from /home/carlos/Documents/git/Caffe2_Demo/03_cpp_forward/main.cpp:11:
/usr/local/include/caffe2/core/tensor.h:94:3: note: declared here
   Tensor() = delete;
   ^
CMakeFiles/classifier.dir/build.make:62: recipe for target 'CMakeFiles/classifier.dir/main.cpp.o' failed
make[2]: *** [CMakeFiles/classifier.dir/main.cpp.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/classifier.dir/all' failed
make[1]: *** [CMakeFiles/classifier.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

Any ideas on how to solve this?

CarlosYeverino avatar Sep 05 '18 22:09 CarlosYeverino

I have got an error on caffe2:Tensor when building caffe2_cpp_tutorial build.

kimkk@odml ~/archive/caffe2_cpp_tutorial/build (master)$ make
[  1%] Building NVCC (Device) object CMakeFiles/caffe2_cpp_gpu.dir/src/caffe2/operator/caffe2_cpp_gpu_generated_diagonal_op.cu.o
/home/kimkk/archive/pytorch/torch/lib/include/google/protobuf/arena_impl.h(54): warning: integer conversion resulted in a change of sign

/home/kimkk/archive/pytorch/torch/lib/include/google/protobuf/arena_impl.h(232): warning: integer conversion resulted in a change of sign

/home/kimkk/archive/caffe2_cpp_tutorial/src/caffe2/operator/diagonal_op.cu(6): error: class "caffe2::Tensor" may not have a template argument list

/home/kimkk/archive/caffe2_cpp_tutorial/src/caffe2/operator/diagonal_op.cu(14): error: class "caffe2::Tensor" may not have a template argument list

/home/kimkk/archive/caffe2_cpp_tutorial/src/caffe2/operator/diagonal_op.cu(22): error: class "caffe2::Tensor" may not have a template argument list

3 errors detected in the compilation of "/tmp/tmpxft_00003c8c_00000000-6_diagonal_op.cpp1.ii".
CMake Error at caffe2_cpp_gpu_generated_diagonal_op.cu.o.cmake:266 (message):
  Error generating file
  /home/kimkk/archive/caffe2_cpp_tutorial/build/CMakeFiles/caffe2_cpp_gpu.dir/src/caffe2/operator/./caffe2_cpp_gpu_generated_diagonal_op.cu.o


CMakeFiles/caffe2_cpp_gpu.dir/build.make:1964: recipe for target 'CMakeFiles/caffe2_cpp_gpu.dir/src/caffe2/operator/caffe2_cpp_gpu_generated_diagonal_op.cu.o' failed
make[2]: *** [CMakeFiles/caffe2_cpp_gpu.dir/src/caffe2/operator/caffe2_cpp_gpu_generated_diagonal_op.cu.o] Error 1
CMakeFiles/Makefile2:522: recipe for target 'CMakeFiles/caffe2_cpp_gpu.dir/all' failed
make[1]: *** [CMakeFiles/caffe2_cpp_gpu.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

hongsoog avatar Sep 08 '18 05:09 hongsoog

I'm not sure what each individual problem is but: @hongsoog I am guessing you have a newer version of Caffe2 since I'm seeing you installed it with PyTorch. I'm also willing to bet there have been changes since this repository was released. If you check the older documentation (before Caffe2 was moved into PyTorch) the Tensor class was a template class

@CarlosYeverino similarly I am guessing you have a much newer version of Caffe2 which has now deleted some earlier class methods.

@shahruk10 I'm sorry but if you don't format your code I can't even begin to read it.

alexge233 avatar Sep 17 '18 16:09 alexge233

Hi @alexge233 ,

thanks for your answer. Which tag/branch did you checkout to make it work?

CarlosYeverino avatar Sep 18 '18 06:09 CarlosYeverino

I used the old caffe2 repository not the one that is now part of PyTorch. I think it was master branch, but I would suggest you try directly with a release tarball. Do a quick search on those classes and see if they have changed their methods, I am guessing they have.

alexge233 avatar Sep 18 '18 11:09 alexge233

Maybe tags before v0.4.0 can build this tutorial correctly. the repository can not build with the version after tag v0.4.0, e.g. v0.4.1 or latest commit of pytorch. as @alexge233 said,newer version of Caffe2 has now deleted some earlier class methods. and the official document is too old, and seems no one is maintaining it. what's more, after caffe2 became part of PyTorch, the issues(about caffe2) are also almost no one answered.

And I don't know why the installation and documentations of caffe2 is so terrible, hope V1.0 will Improve these.

BIGBALLON avatar Sep 25 '18 07:09 BIGBALLON

@BIGBALLON To be honest I wouldn't bother with Caffe2 anymore, it appears to have been abandoned in favour of ATen which is what PyTorch uses as a back-end. It has the CUDA support and since PyTorch seems tied to it, it would be a safe bet to assume it will keep being supported. Caffe2 c++ was always a pain to deal with and although Leo did a good job showing how to use it, at this stage it is safe to say it is obsolete/deprecated.

alexge233 avatar Sep 25 '18 14:09 alexge233

With all due respect caffe2 is backbone production at FB as it seems, and the framework the most widely running on mobiles through FB app. Detectron runs on caffe2 firsthand. Not the easiest and most documented framework to work with, but a very flexible, light and production ready one for sure.

beniz avatar Sep 25 '18 18:09 beniz

Tensor is de-templatized since we are merging caffe2 and pytorch backends. sorry for the inconvenience..

jerryzh168 avatar Oct 25 '18 18:10 jerryzh168

Hi, @jerryzh168,

Look forward to see you fix it. thanks a lot.

BIGBALLON avatar Oct 26 '18 00:10 BIGBALLON