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:Install: How to install.
- Caffe:ImageNetTutorial: Train and test "CaffeNet" on ImageNet data.
- Caffe:ImageNetClassifying
- Caffe:ExtractingFeatures: Feature extraction.
- Caffe:C++: About C++ programming with Caffe.
- Caffe:Windows: How to use Caffe on Windows.
- Caffe:Python (Pycaffe)
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
- Caffe:Api:NeuronLayer
- Caffe:Api:ReLULayer
- Caffe:Api:PoolingLayer
- Caffe:Api:ConvolutionLayer
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.
You also need to set the Python PATH as follows.
Then you can start the demo with examples/web_demo/app.py.
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.
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.
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.
- Boost version. (For reference, in my case, with
1.60.0, using the Boost.Python package and accessing a Mat for OpenCV.Python crashed the program. After downgrading to version1.59.0, it worked normally.)- When a similar issue occurred, I reinstalled the Python-related packages, in the order NumPy -> Boost.Python -> OpenCV -> Caffe.
R6034
If this message is printed when using Pycaffe, the following changes may make it work.
- Remove
__import__('pkg_resources').declare_namespace(__name__)fromgoogle/__init__.pyin the Python package where Protobuf is installed. - Remove
import skimage.ioandfrom skimage.transform import resizefromcaffe/io.pyin 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.
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
- Caffe web site
- Caffe user groups
- Convolutional Neural Networks, CNN for working with images
- Github: Study materials and example codes for caffe library (understanding deep learning by analyzing the caffe open-source code)
- [Recommended] Deep learning study guide (HW / SW preparation) 1
How to use
- DIY Deep Learning for Vision: a Hands-On Tutorial with Caffe
- Stackoverflow: How to train a caffe model?
- Train and Test LeNet on your own dataset
- Caffe tutorial 2
- [Recommended] Caffe hands-on practice 3
- Graduation thesis 3_Training Dataset with Caffe
Tutorials
- [Recommended] Deep Learning Study: Introduction to Caffe
- [Recommended] TA_lecture - Deep learning using Caffe - Practical guide 4
Q&A
Resource
References
- Artificial intelligence
- Artificial neural network
- Caffe:Api:Blob
- Caffe:Api:ConvolutionLayer
- Caffe:Api:PoolingLayer
- Caffe:Api:ReLULayer
- Caffe:Develop
- Caffe:ImageNetClassifying
- Caffe:ImageNetTutorial
- Caffe:Install
- Caffe:Tour
- Caffe:Tour:LayerCatalogue
- Caffe:Tour:Solver
- Caffe:Windows
- Computer Sciences
- Convolutional neural network
- CUDA:Example
- CuDNN
- Cv::Mat:Python
- Deep learning
- Deep learning:Performance Tuning
- Faster R-CNN
- Faster-RCNN:Paper
- ImageNet
- Machine learning
- MNIST
- Model Zoo
- Pruning Neural Networks
- Python:Libraries
- R-FCN
- SPPnet
- Tbag
- TensorFlow
- Theano