Caffe
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: 설치방법에 대한 설명
- Caffe:ImageNetTutorial: Train and test "CaffeNet" on ImageNet data.
- Caffe:ImageNetClassifying
- Caffe:ExtractingFeatures: 특징 추출.
- Caffe:C++: Caffe를 사용한 C++프로그래밍에 대한 내용.
- Caffe:Windows: Windows에서 Caffe를 사용하기 위한 방법.
- 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
웹 데모를 위해 Python 패키지에서 Werkzeug, Flask, tornado, numpy, pandas, Pillow, itsdangerous 등이 필요하다. 설치는 아래와 같이 진행 할 수 있다.
또한 Python PATH
를 아래와 같이 지정해야 한다.
이후 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
cmake도중 아래와 같은 에러 메시지가 출력될 수 있다.
Atlas관련 라이브러리를 찾을 수 없다는 에러이다. 이 경우 OpenBLAS를 사용하도록 우회한다. cmake/Dependencies.cmake
파일을 참조하면 알 수 있지만, BLAD
값을 Open
으로 변경 해주면 된다.
Python can't import _caffe module
Problem with dynamic loading and caffe.proto
EXE 실행시 아래와 같은 에러 메시지가 출력할 수 있다.
[libprotobuf ERROR google/protobuf/descriptor_database.cc:57] File already exists in database: caffe.proto
케이스가 다양하겠지만 필자의 경우 OpenCV의 Contrib확장 모듈을 추가 설치하여 발생된 문제이다. 확장모듈을 제거하고 OpenCV를 설치하면 된다.
ImportError: No module named gpu_nms
Faster-RCNN에서 발생되는 현상 중 하나. 해결 방법은 관련 항목 참조.
Segmentation Fault
세그먼테이션 결함은 발생되는 상황이 매우 많다. 따라서 아래의 내용 중 하나를 확인해야 한다.
- Boost 버전. (참고로 필자의 경우
1.60.0
에서 Boost.Python패키지를 사용했을 때 OpenCV.Python용 Mat에 접근하면 프로그램이 죽는 현상이 발생되었다.1.59.0
버전으로 다운그레이드 후 실행하니 정상적으로 작동하였다.)- 위와 비슷한 현상이 발생되었을 경우, Python 관련 패키지를 다시 설치하였다. NumPy -> Boost.Python -> OpenCV -> Caffe 순서로 설치하였다.
R6034
Pycaffe사용시 이러한 메시지가 출력되었을 경우 아래와 같이 수정해 보면 정상작동할 가능성이 있다.
- Protobuf가 설치된 Python Package의
google/__init__.py
에서__import__('pkg_resources').declare_namespace(__name__)
를 제거한다. - Pycaffe의
caffe/io.py
의import skimage.io
와from skimage.transform import resize
를 제거하면 된다. 이 부분은 Python의__import__
관련 항목을 사용할 경우 발생되는 문제로 보인다. (정확한 원인을 확인해야 한다)
registry.count(type) (0 vs. 1)
실행할 경우 아래와 같은 에러가 발생될 수 있다.
Check failed: registry.count(type) == 1 (0 vs. 1) Unknown layer type: Input (known types: MemoryData)
이 경우 만약 정적 컴파일하였다면, 동적 컴파일로 옵션을 바꾸면 된다. (LayerFactory에 등록하는 코드가 Global에 포함되어있다.)
No module named skimage.io
Python에서 skimage.io가 없을 경우 해당 패키지를 아래와 같이 설치하면 된다.
cudaSuccess (2 vs. 0) out of memory
트레이닝 등의 상황에서 아래와 같은 에러메시지를 발견할 수 있다.
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)
nvidia-smi
등의 유틸리티로 확인하면 GPU메모리가 부족하단걸 알 수 있다. 만약 트레이닝중이라면 solver.prototxt
에서 batch size
를 낮게 조정하면 된다. 이걸로도 부족하다면 레이어 구조를 바꾸는 수밖에...
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
- Github: Study materials and example codes for caffe library (caffe 오픈소스 분석을 통해 deep learning 이해)
- [추천] 딥러닝 공부 가이드 (HW / SW 준비편) 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
- [추천] Caffe 실습 3
- 졸업논문3_Training Dataset with Caffe
Tutorials
- [추천] Deep Learning Study: Introduction to Caffe
- [추천] TA_lecture - Deep learning using Caffe - Practical guide 4