Skip to content
Search

Caffe

lastmod 2018-08-17created 2015-10-1393 edits

Caffe is a deep learning framework made with expression, speed, and modularity in mind. It is developed by the Berkeley Vision and Learning Center (BVLC) and by community contributors. Yangqing Jia created the project during his PhD at UC Berkeley. Caffe is released under the BSD 2-Clause license.

Category

Caffe Tour

  • Nets, Layers, and Blobs: the anatomy of a Caffe model.
  • Forward / Backward: the essential computations of layered compositional models.
  • Loss: the task to be learned is defined by the loss.
  • Solver: the solver coordinates model optimization.
  • Layer Catalogue: the layer is the fundamental unit of modeling and computation – Caffe’s catalogue includes layers for state-of-the-art models.
  • Interfaces: command line, Python, and MATLAB Caffe.
  • Data: how to caffeinate data for model input.

Caffe source code

Caffe:Api

Layers

Programming

Libraries

Models

CaffeNet vs AlexNet

  • CaffeNet
  • AlexNet
  • GoogleNet

Databases

Web demo

The web demo requires the Python packages Werkzeug, Flask, tornado, numpy, pandas, Pillow, itsdangerous, and others. They can be installed as follows.

$ pip install -r examples/web_demo/requirements.txt

You also need to set the Python PATH as follows.

PYTHONPATH=/path/to/caffe/python:$PYTHONPATH

Then you can start the demo with examples/web_demo/app.py.

$ python examples/web_demo/app.py -h

Mean value

https://groups.google.com/forum/#!topic/caffe-users/9opH6AW3Irw (answer by Evan Shelhamer):
[Mean] values are BGR for historical reasons -- the original CaffeNet training lmdb was made with image processing by OpenCV which defaults to BGR order.

Troubleshooting

Multi-GPU Usage

Currently Multi-GPU is only supported via the C/C++ paths and only for training.

The GPUs to be used for training can be set with the "-gpu" flag on the command line to the 'caffe' tool. e.g. "build/tools/caffe train --solver=models/bvlc_alexnet/solver.prototxt --gpu=0,1" will train on GPUs 0 and 1.

NOTE: each GPU runs the batchsize specified in your train_val.prototxt. So if you go from 1 GPU to 2 GPU, your effective batchsize will double. e.g. if your train_val.prototxt specified a batchsize of 256, if you run 2 GPUs your effective batch size is now 512. So you need to adjust the batchsize when running multiple GPUs and/or adjust your solver params, specifically learning rate.

Could NOT find Atlas

The following error message may be printed while running cmake.

Could NOT find Atlas (missing: Atlas_LAPACK_LIBRARY)

This error means the Atlas-related library cannot be found. In this case, work around it by using OpenBLAS instead. As you can see in the cmake/Dependencies.cmake file, just change the BLAD value to Open.

$ cmake -DBLAS=Open -DUSE_CUDNN=1 -G "Unix Makefiles"

Python can't import _caffe module

Problem with dynamic loading and caffe.proto

The following error message may be printed when running the EXE.

[libprotobuf ERROR google/protobuf/descriptor_database.cc:57] File already exists in database: caffe.proto

Causes vary, but in my case the problem came from additionally installing OpenCV's Contrib extension modules. Remove the extension modules and install OpenCV.

ImportError: No module named gpu_nms

One of the issues that occurs in Faster-RCNN. For the solution, see the related page.

Segmentation Fault

Segmentation faults can occur in a great many situations, so check one of the following.

R6034

If this message is printed when using Pycaffe, the following changes may make it work.

  1. Remove __import__('pkg_resources').declare_namespace(__name__) from google/__init__.py in the Python package where Protobuf is installed.
  2. Remove import skimage.io and from skimage.transform import resize from caffe/io.py in Pycaffe. This appears to be a problem that occurs when using Python's __import__-related features. (The exact cause still needs to be confirmed)

registry.count(type) (0 vs. 1)

The following error may occur at run time.

Check failed: registry.count(type) == 1 (0 vs. 1) Unknown layer type: Input (known types: MemoryData)

In this case, if you compiled statically, switch the option to dynamic compilation. (The code that registers with the LayerFactory is in the global scope.)

No module named skimage.io

If skimage.io is missing in Python, install the package as follows.

$ pip install scikit-image

cudaSuccess (2 vs. 0) out of memory

You may see an error message like the following during training and similar tasks.

I0329 21:13:11.459560  5026 net.cpp:217] Network initialization done.
I0329 21:13:11.459564  5026 net.cpp:218] Memory required for data: 343607608
I0329 21:13:11.459643  5026 solver.cpp:42] Solver scaffolding done.
I0329 21:13:11.459671  5026 solver.cpp:222] Solving CaffeNet
I0329 21:13:11.459676  5026 solver.cpp:223] Learning Rate Policy: step
I0329 21:13:11.459689  5026 solver.cpp:266] Iteration 0, Testing net (#0)
I0329 21:15:33.072834  5026 solver.cpp:315]     Test net output #0: accuracy = 0
I0329 21:15:33.072907  5026 solver.cpp:315]     Test net output #1: loss = 7.48307 (* 1 = 7.48307 loss)
F0329 21:15:33.540781  5026 syncedmem.cpp:51] Check failed: error == cudaSuccess (2 vs. 0)  out of memory
*** Check failure stack trace: ***
    @     0x7f6a22caddaa  (unknown)
    @     0x7f6a22cadce4  (unknown)
    @     0x7f6a22cad6e6  (unknown)
    @     0x7f6a22cb0687  (unknown)
    @     0x7f6a230a0fda  caffe::SyncedMemory::mutable_gpu_data()
    @     0x7f6a23094352  caffe::Blob<>::mutable_gpu_data()
    @     0x7f6a230c4f05  caffe::ConvolutionLayer<>::Forward_gpu()
    @     0x7f6a2304c41d  caffe::Net<>::ForwardFromTo()
    @     0x7f6a2304c887  caffe::Net<>::ForwardPrefilled()
    @     0x7f6a2306b454  caffe::Solver<>::Step()
    @     0x7f6a2306be7f  caffe::Solver<>::Solve()
    @           0x4085d8  train()
    @           0x406b71  main
    @     0x7f6a221bfec5  (unknown)
    @           0x40711d  (unknown)
    @              (nil)  (unknown)
Aborted (core dumped)

Checking with a utility such as nvidia-smi shows that GPU memory is insufficient. If you are training, lower the batch size in solver.prototxt. If that is still not enough, the only option is to change the layer structure...

Documentation

Welcome to the BrainCaffe wiki! Caffe Documentation - ver.Kor
https://github.com/ys7yoo/BrainCaffe/wiki
BrainCaffe.wiki_-master-_8616aa1.zip (2017-09-01)

See also

Favorite site

How to use

Tutorials

Q&A

Resource

References


  1. Deep_learning_study_guide_-_HW_and_SW.pdf ↩

  2. Caffe_tutorial.pdf ↩

  3. Caffe_Training_OSIA_update2.pdf ↩

  4. TA_lecture_-Deep_learning_using_Caffe-_Practical_guide.pptx.pdf ↩