Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tensor is a deleted function - Print method #75

Open
CarlosYeverino opened this issue Jul 10, 2018 · 5 comments
Open

Tensor is a deleted function - Print method #75

CarlosYeverino opened this issue Jul 10, 2018 · 5 comments

Comments

@CarlosYeverino
Copy link

Hi all,

I am getting 2 errors during building solution. I checked the header file tensor.h and I saw the following: /**

  • @brief Delete the copy constructor and use Clone explicitly
    */
    Tensor(const Tensor& src) = delete;

The mentioned 2 errors:
Severity Code Description Project File Line Suppression State
Error (active) function "caffe2::Tensor::Tensor(const caffe2::Tensor &src) [with Context=caffe2::CPUContext]" (declared at line 706 of "d:\Yeverino\git_projects\pytorch\caffe2\core\tensor.h") cannot be referenced -- it is a deleted function ConsoleApplication1 d:\Yeverino\visual studio projects\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.cpp 11

Severity Code Description Project File Line Suppression State
Error C2280 'caffe2::Tensorcaffe2::CPUContext::Tensor(const caffe2::Tensorcaffe2::CPUContext &)': attempting to reference a deleted function ConsoleApplication1 d:\yeverino\visual studio projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 11

How should I modify the print method included in the tutorials in order to fix the errors?
void print(const Blob* blob, const std::string& name) {
auto tensor = blob->Get();
const auto& data = tensor.data();
std::cout << name << "(" << tensor.dims()
<< "): " << std::vector(data, data + tensor.size())
<< std::endl;
}

@rednoah91
Copy link

As the comment mentioned: "Delete the copy constructor and use Clone explicitly"
const auto& data = tensor.Clone().data();

@CarlosYeverino
Copy link
Author

Hi @rednoah91 ,

thanks for your reply.

I tried what you mentioned, however, errors are still there. Errors are caused by line 11 in the print method (auto tensor = blob->Get();). Do you know how to fix it?

capture

@ferasboulala
Copy link

auto tensor = blob->Get<TensorCPU>().Clone()

Just add the .Clone() whenever you refer to a TensorCPU object.

@zacario-li
Copy link

zacario-li commented Jul 27, 2018

@CarlosYeverino
Copy link
Author

Hi @zacario-li @ferasboulala ,

for some cases your suggestion fixed the error, however, I also get the following error:

carlos@carlos-ubuntu:~/Documents/git/caffe2_cpp_tutorial$ c++ src/caffe2/binaries/pretrained.cc -o bin/pretrained -std=gnu++11 -Iinclude -I/usr/include/eigen3 -I/usr/include/opencv -lgflags -lglog -lprotobuf -lopencv_core -lopencv_imgproc -lopencv_highgui -lCaffe2_CPU
In file included from /usr/local/include/caffe2/core/net.h:12:0,
                 from src/caffe2/binaries/pretrained.cc:2:
/usr/local/include/caffe2/core/blob.h: In instantiation of ‘T* caffe2::Blob::GetMutable() [with T = caffe2::Tensor]’:
src/caffe2/binaries/pretrained.cc:107:68:   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/net.h:12,
                 from src/caffe2/binaries/pretrained.cc:2:
/usr/local/include/caffe2/core/tensor.h:94:3: note: declared here
   Tensor() = delete;
   ^

The relevant code for the error:

  Workspace workspace("tmp");
  CAFFE_ENFORCE(workspace.RunNetOnce(init_net));
  auto input = workspace.CreateBlob("data")->GetMutable<TensorCPU>();

I added .Clone after GetMutable<TensorCPU>() but then I got the following error:

carlos@carlos-ubuntu:~/Documents/git/caffe2_cpp_tutorial$ c++ src/caffe2/binaries/pretrained.cc -o bin/pretrained -std=gnu++11 -Iinclude -I/usr/include/eigen3 -I/usr/include/opencv -lgflags -lglog -lprotobuf -lopencv_core -lopencv_imgproc -lopencv_highgui -lCaffe2_CPU
src/caffe2/binaries/pretrained.cc: In function ‘void caffe2::run()’:
src/caffe2/binaries/pretrained.cc:107:70: error: request for member ‘Clone’ in ‘workspace.caffe2::Workspace::CreateBlob(std::__cxx11::basic_string<char>(((const char*)"data"), std::allocator<char>()))->caffe2::Blob::GetMutable<caffe2::Tensor>()’, which is of pointer type ‘caffe2::Tensor*’ (maybe you meant to use ‘->’ ?)
   auto input = workspace.CreateBlob("data")->GetMutable<TensorCPU>().Clone();
                                                                      ^
In file included from /usr/local/include/caffe2/core/net.h:12:0,
                 from src/caffe2/binaries/pretrained.cc:2:
/usr/local/include/caffe2/core/blob.h: In instantiation of ‘T* caffe2::Blob::GetMutable() [with T = caffe2::Tensor]’:
src/caffe2/binaries/pretrained.cc:107:68:   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/net.h:12,
                 from src/caffe2/binaries/pretrained.cc:2:
/usr/local/include/caffe2/core/tensor.h:94:3: note: declared here
   Tensor() = delete;
   ^

Any ideas to fix this error?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants