leovandriel / caffe2_cpp_tutorial

C++ transcripts of the Caffe2 Python tutorials and other C++ example code
BSD 2-Clause "Simplified" License
431 stars 94 forks source link

Shared data from value may be deleted #76

Closed akuz closed 6 years ago

akuz commented 6 years ago

At the line below, a "value" TensorCPU is created, and then its data is shared with the blob. However, at the end of this block, the "value" TensorCPU is destroyed, and so its data is "lost". I think it's only by accident that its data is still intact when it is used further down the line.

https://github.com/leonardvandriel/caffe2_cpp_tutorial/blob/d5daf4e89b9b1a12979649e783d68f4c821a554f/src/caffe2/binaries/intro.cc#L37

Instead, it should be:

tensor->CopyFrom (value);

akuz commented 6 years ago

Actually, I realised that data_ is a shared_ptr<>, so it won't be deleted, and will in fact be shared. Since it's not gonna be modified through the original Tensor, it's ok! Closing the issue...