How to initialize a Blob variable in Caffe as zero
In my project I want to init it as zero, I write the code using cudaMemset
cudaMemset(v, Dtype(0), v.count());
Which is not working, because I’m too stupid and forget to multiply the size of each element.
cudaMemset(v.mutable_gpu_data(), Dtype(0), sizeof(Dtype)&v.count());
Then it’s working.
But if we want to set it as other fixed value (say 1), we can use caffe_gpu_set instead:
Dtype Alpha = 1.0;
caffe_gpu_set(v.count(), Alpha, v.mutable_gpu_data());