caffe , When does Caffe make copies of the data?

When does Caffe make copies of the data?


Tag: caffe
 // Assuming that data are on the CPU initially, and we have a blob.
 const Dtype* foo;
 Dtype* bar;
 foo = blob.gpu_data(); // data copied cpu->gpu.
 foo = blob.cpu_data(); // no data copied since both have up-to-date contents.
 bar = blob.mutable_gpu_data(); // no data copied.
 // ... some operations ...
 bar = blob.mutable_gpu_data(); // no data copied when we are still on GPU.
 foo = blob.cpu_data(); // data copied gpu->cpu, since the gpu side has modified the data
foo = blob.gpu_data(); // no data copied since both have up-to-date contents
bar = blob.mutable_cpu_data(); // still no data copied.
bar = blob.mutable_gpu_data(); // data copied cpu->gpu.
bar = blob.mutable_cpu_data(); // data copied gpu->cpu

Why do the last two lines copy data? Don't the GPU and CPU have both up-to-date contents?


.gpu_data and .cpu_data are used in cases were the data is used only as input and will not be modified by the algorithm. .mutable_* is used when the data itself gets updated while running the algorithm.

Whenever a the data is called, it checks whether the previous statement was a mutable_* function call and that too using the same processor (gpu or cpu). If it is using the same processor, data need not be copied. If it is using the other processor, there is a chance that the data might have been updated in the previous .mutable_* call and hence a data copy is required.

Edit 1 Whenever the previous instruction is 'mutable', data copy is to be done before the current instruction IF the current instruction is on a different processor.

In no other case the data copy takes place except for a special initial condition, ie; when no data was present at all in the GPU memory and hence a copy of the data will take place before *_gpu_data() call.


Cannot import caffe into python, not found

I cannot import caffe into (anaconda-) python. I'm following a notebook example on "logistic regression on non-image HDF5 data". When I execute the line import caffe I get the following error: --------------------------------------------------------------------------- ImportError Traceback (most recent call last) <ipython-input-17-3524921938b5> in <module>() 8 sys.path.insert(0, caffe_root + 'python') 9 ---> 10 import...

Caffe layer creation failure

I'm trying to load in TEST phase a network configuration which has a memory data layer first and then a convolution layer. The MemoryData layer creation succeeds, But the convolution layer's creation fails at the following location: LOG(INFO) << "Creating layer " <<; const string& type = param.type(); CreatorRegistry&...

Python interface of Caffe: Error in “import caffe”

I'm trying to run Caffe in it's Python interface. I've already run the command make pycaffe in the caffe directory and it worked fine. Now, when I run the command import caffe in the python environment in the terminal (Ubuntu 14.04), I'm getting the following error: >>> import caffe Traceback...

In CNN with caffe, Can I set up initial caffemodel?

I have operated CNN using caffe. however, system was forced termination. I have caffemodel so far. Can I restart learning from now on using current caffemodel? Thanks,...

How to use 1-dim vector as input for caffe?

I'd like to train a neural network (NN) on my own 1-dim data, which I stored in a hdf5 database for caffe. According to the documetation this should work. It also works for me as far as I only use "Fully Connected Layers", "Relu" and "Dropout". However I get an...

How to adapt Caffe Matlab wrapper for a network trained on Mnist?

I successfully trained my Caffe net on the mnist database following Now I want to test the network with my own images using the Matlab wrapper. Therefore in "matcaffe.m" im loading the file "lenet.prototxt" which is not used for training but which seems to be suited for testing. It...

Drawing network in Caffe causes pydot to throw End of Line errors

So I just pulled the latest revision of Caffe from the master branch, and went through all the initialization steps. As a quick test, I was trying to run the python/ script provided, in order to visualize the MNIST Autoencoder example network. On executing the following command: ./python/ examples/mnist/mnist_autoencoder.prototxt trial_viz.png...

Using GPU despite setting CPU_Only, yielding unexpected keyword argument

I'm installing Caffe on an Ubuntu 14.04 virtual server with CUDA installed (without driver) using as inspiration. During the installation process I edited the MakeFile to include "CPU_ONLY := 1" before building it. However, it seems that Caffe is still trying to make use of the GPU. When I...

How to get a layer from a caffe model using torch

In python when I want to get the data from a layer using caffe I have the following code input_image = input_oversampled =, prediction =[input_image]) caffe_input = np.asarray('data', prediction)) data =['fc7'].data[4] // I want to get this value in lua Hoever when I'm using...

caffe: missing (error while loading shared libraries)

I've installed caffe on a server a while ago, and back then it worked properly. Now I'm following the LeNet MNIST tutorial again (, and running ./examples/mnist/ returns build/examples/mnist/convert_mnist_data.bin: error while loading shared libraries: cannot open shared object file: No such file or directory I've noticed that is...

Error when using classify in caffe

I am using caffe in python to classify. I get code from here. In here, I just use simple code such as plt.rcParams['figure.figsize'] = (10, 10) plt.rcParams['image.interpolation'] = 'nearest' plt.rcParams['image.cmap'] = 'gray' mean_filename='./mean.binaryproto' proto_data = open(mean_filename, "rb").read() a = mean =[0] age_net_pretrained='./age_net.caffemodel' age_net_model_file='./deploy_age.prototxt' age_net = caffe.Classifier(age_net_model_file,...

Error while installing deepdish

I'm trying to create an LMDB database file to be used with Caffe according to this tutorial on an Ubuntu 14.04 machine using Anaconda Python 2.7.9. However, when I do pip install deepdish, I'm getting the following error: Collecting deepdish Using cached deepdish-0.1.4.tar.gz Complete output from command python egg_info:...

Object categories of pretrained imagenet model in caffe

I'm using the pretrained imagenet model provided along the caffe (CNN) library ('bvlc_reference_caffenet.caffemodel'). I can output a 1000 dim vector of object scores for any images using this model. However I don't know what the actual object categories are. Did someone find a file, where the corresponding object categories are...

Armadillo in Caffe for pseudo-inverse and transpose

I need pseudo inverse and transpose function to implement a Layer in caffe. So I am using Armadillo library to do that. But How can I convert Caffe Blobs(2-D) to armadillo Mat and vice-versa ?

[Caffe]: Check failed: ShapeEquals(proto) shape mismatch (reshape not set)

I have this error and I have tried to take a look in Internet but I got nothing clear. I trained my net with Caffe successfully with around 82% of accuracy. Now I'm trying to try it with an image through this code: python python/ --model_def examples/imagenet/imagenet_deploy.prototxt --pretrained_model caffe_mycaffe_train_iter_10000.caffemodel --images_dim...

How does Caffe determine the number of neurons in each layer?

Recently, I've been trying to use Caffe for some of the deep learning work that I'm doing. Although writing the model in Caffe is very easy, I've not been able to know the answer to this question. How does Caffe determine the number of neurons in a hidden layer? I...

Two errors while running Caffe

I've installed Caffe on my Ubuntu 14.04 machine. the make runtest runs perfectly fine with 581 tests passed. I'm trying to work with the command line and python interface and getting the following two errors: Command Line Interface: When I try to run the command caffe, I'm getting the following...

When does Caffe make copies of the data?

// Assuming that data are on the CPU initially, and we have a blob. const Dtype* foo; Dtype* bar; foo = blob.gpu_data(); // data copied cpu->gpu. foo = blob.cpu_data(); // no data copied since both have up-to-date contents. bar = blob.mutable_gpu_data(); // no data copied. // ... some operations...

Import caffe error

i compiled caffe successfully in my ubuntu machine but cannot import in python. Caffe is installed /home/pbu/Desktop/caffe i tried adding the /home/pbu/caffe/python path to sys.path.append, still not working i am trying to import caffe [email protected]:/home/pbu/Desktop# python ./caffe/ Traceback (most recent call last): File "./caffe/", line 13, in <module> import caffe...

Installing Caffe (deep learning) issues

I have been able to install Caffe but I had a lot of issues and that's because I didn't follow the instructions very well. I have a Mac OSx and I'm reading the OSx guide for installation. In this point: when I type hdf5 opencv I get: "hdf5: command not...

Error in creating LMDB database file in Python for Caffe

I'm trying to create an LMDB data base file in Python to be used with Caffe according to this tutorial. The commands import numpy as np and import caffe run perfectly fine. However, when I try to run import lmdb and import deepdish as dd, I'm getting the following errors:...

caffe Debug build: stray '"' character in nvcc command

I am trying to build my C++ application that uses caffe, in Debug Mode, VS2013 community, x64. To be able to build version that do not need cuda to run, I added to wrapped each .cu file as indicated below: #ifndef CPU_ONLY // .cu file contents #endif The project was...