Skip to content

Commit

Permalink
Merge branch 'master' into mobile (c6414ea)
Browse files Browse the repository at this point in the history
  • Loading branch information
sh1r0 committed Apr 24, 2015
2 parents b7a5b5d + c6414ea commit 8c31ef1
Show file tree
Hide file tree
Showing 39 changed files with 941 additions and 178 deletions.
15 changes: 9 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ WARNINGS := -Wall -Wno-sign-compare
# Set build directories
##############################

DISTRIBUTE_DIR ?= distribute
DISTRIBUTE_SUBDIRS := $(DISTRIBUTE_DIR)/bin $(DISTRIBUTE_DIR)/lib
DIST_ALIASES := dist
ifneq ($(strip $(DISTRIBUTE_DIR)),distribute)
Expand Down Expand Up @@ -232,13 +233,15 @@ endif
# libstdc++ for NVCC compatibility on OS X >= 10.9 with CUDA < 7.0
ifeq ($(OSX), 1)
CXX := /usr/bin/clang++
CUDA_VERSION := $(shell $(CUDA_DIR)/bin/nvcc -V | grep -o 'release \d' | grep -o '\d')
ifeq ($(shell echo $(CUDA_VERSION) \< 7.0 | bc), 1)
CXXFLAGS += -stdlib=libstdc++
LINKFLAGS += -stdlib=libstdc++
ifneq ($(CPU_ONLY), 1)
CUDA_VERSION := $(shell $(CUDA_DIR)/bin/nvcc -V | grep -o 'release \d' | grep -o '\d')
ifeq ($(shell echo $(CUDA_VERSION) \< 7.0 | bc), 1)
CXXFLAGS += -stdlib=libstdc++
LINKFLAGS += -stdlib=libstdc++
endif
# clang throws this warning for cuda headers
WARNINGS += -Wno-unneeded-internal-declaration
endif
# clang throws this warning for cuda headers
WARNINGS += -Wno-unneeded-internal-declaration
# gtest needs to use its own tuple to not conflict with clang
COMMON_FLAGS += -DGTEST_USE_OWN_TR1_TUPLE=1
# boost::thread is called boost_thread-mt to mark multithreading on OS X
Expand Down
2 changes: 1 addition & 1 deletion docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Similarly for IPython notebooks: simply include `"include_in_docs": true` in the

Other docs, such as installation guides, are written in the `docs` directory and manually linked to from the `index.md` page.

We strive to provide provide lots of usage examples, and to document all code in docstrings.
We strive to provide lots of usage examples, and to document all code in docstrings.
We absolutely appreciate any contribution to this effort!

### Versioning
Expand Down
21 changes: 13 additions & 8 deletions docs/install_apt.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,24 @@ title: Installation: Ubuntu

sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-dev

**CUDA**: Install via the NVIDIA package instead of `apt-get` to be certain of the library and driver versions.
Install the library and latest driver separately; the driver bundled with the library is usually out-of-date.
This can be skipped for CPU-only installation.

**BLAS**: install ATLAS by `sudo apt-get install libatlas-base-dev` or install OpenBLAS or MKL for better CPU performance.

**Python** (optional): if you use the default Python you will need to `sudo apt-get install` the `python-dev` package to have the Python headers for building the pycaffe interface.

**Remaining dependencies, 14.04**

Everything is packaged in 14.04.

sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler

**Remaining dependencies, 12.04**

These dependencies need manual installation in 12.04.

# glog
wget https://google-glog.googlecode.com/files/glog-0.3.3.tar.gz
tar zxvf glog-0.3.3.tar.gz
Expand All @@ -28,17 +40,10 @@ title: Installation: Ubuntu
export CXXFLAGS="-fPIC" && cmake .. && make VERBOSE=1
make && make install
# lmdb
git clone git://gitorious.org/mdb/mdb.git
git clone https://gitorious.org/mdb/mdb.git
cd mdb/libraries/liblmdb
make && make install

Note that glog does not compile with the most recent gflags version (2.1), so before that is resolved you will need to build with glog first.

**CUDA**: Install via the NVIDIA package instead of `apt-get` to be certain of the library and driver versions.
Install the library and latest driver separately; the driver bundled with the library is usually out-of-date.

**BLAS**: install ATLAS by `sudo apt-get install libatlas-base-dev` or install OpenBLAS or MKL for better CPU performance.

**Python** (optional): if you use the default Python you will need to `sudo apt-get install` the `python-dev` package to have the Python headers for building the pycaffe interface.

Continue with [compilation](installation.html#compilation).
4 changes: 2 additions & 2 deletions docs/install_osx.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ In other `ENV` settings, things may not work as expected.
brew install --fresh -vd snappy leveldb gflags glog szip lmdb
# need the homebrew science source for OpenCV and hdf5
brew tap homebrew/science
hdf5 opencv
brew install hdf5 opencv

If using Anaconda Python, a modification to the OpenCV formula might be needed
Do `brew edit opencv` and change the lines that look like the two lines below to exactly the two lines below.
Expand Down Expand Up @@ -115,7 +115,7 @@ Then, whenever you want to update homebrew, switch back to the master branches,
# Update homebrew; hopefully this works without errors!
brew update

# Switch back to the caffe branches with the forumlae that you modified earlier
# Switch back to the caffe branches with the formulae that you modified earlier
cd /usr/local
git rebase master caffe
# Fix any merge conflicts and commit to caffe branch
Expand Down
43 changes: 27 additions & 16 deletions docs/model_zoo.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,30 @@ title: Model Zoo
---
# Caffe Model Zoo

Lots of people have used Caffe to train models of different architectures and applied to different problems, ranging from simple regression to AlexNet-alikes to Siamese networks for image similarity to speech applications.
To lower the friction of sharing these models, we introduce the model zoo framework:
Lots of researchers and engineers have made Caffe models for different tasks with all kinds of architectures and data.
These models are learned and applied for problems ranging from simple regression, to large-scale visual classification, to Siamese networks for image similarity, to speech and robotics applications.

To help share these models, we introduce the model zoo framework:

- A standard format for packaging Caffe model info.
- Tools to upload/download model info to/from Github Gists, and to download trained `.caffemodel` parameters.
- Tools to upload/download model info to/from Github Gists, and to download trained `.caffemodel` binaries.
- A central wiki page for sharing model info Gists.

## BVLC Reference Models
## Where to get trained models

First of all, we provide some trained models out of the box.
First of all, we bundle BVLC-trained models for unrestricted, out of the box use.
<br>
See the [BVLC model license](#bvlc-model-license) for details.
Each one of these can be downloaded by running `scripts/download_model_binary.py <dirname>` where `<dirname>` is specified below:

- **BVLC Reference CaffeNet** in `models/bvlc_reference_caffenet`: AlexNet trained on ILSVRC 2012, with a minor variation from the version as described in the NIPS 2012 paper. (Trained by Jeff Donahue @jeffdonahue)
- **BVLC AlexNet** in `models/bvlc_alexnet`: AlexNet trained on ILSVRC 2012, almost exactly as described in NIPS 2012. (Trained by Evan Shelhamer @shelhamer)
- **BVLC Reference R-CNN ILSVRC-2013** in `models/bvlc_reference_rcnn_ilsvrc13`: pure Caffe implementation of [R-CNN](https://github.com/rbgirshick/rcnn). (Trained by Ross Girshick @rbgirshick)
- **BVLC GoogleNet** in `models/bvlc_googlenet`: GoogleNet trained on ILSVRC 2012, almost exactly as described in [GoogleNet](http://arxiv.org/abs/1409.4842). (Trained by Sergio Guadarrama @sguada)

- **BVLC Reference CaffeNet** in `models/bvlc_reference_caffenet`: AlexNet trained on ILSVRC 2012, with a minor variation from the version as described in [ImageNet classification with deep convolutional neural networks](http://papers.nips.cc/paper/4824-imagenet-classification-with-deep-convolutional-neural-networks) by Krizhevsky et al. in NIPS 2012. (Trained by Jeff Donahue @jeffdonahue)
- **BVLC AlexNet** in `models/bvlc_alexnet`: AlexNet trained on ILSVRC 2012, almost exactly as described in [ImageNet classification with deep convolutional neural networks](http://papers.nips.cc/paper/4824-imagenet-classification-with-deep-convolutional-neural-networks) by Krizhevsky et al. in NIPS 2012. (Trained by Evan Shelhamer @shelhamer)
- **BVLC Reference R-CNN ILSVRC-2013** in `models/bvlc_reference_rcnn_ilsvrc13`: pure Caffe implementation of [R-CNN](https://github.com/rbgirshick/rcnn) as described by Girshick et al. in CVPR 2014. (Trained by Ross Girshick @rbgirshick)
- **BVLC GoogLeNet** in `models/bvlc_googlenet`: GoogLeNet trained on ILSVRC 2012, almost exactly as described in [Going Deeper with Convolutions](http://arxiv.org/abs/1409.4842) by Szegedy et al. in ILSVRC 2014. (Trained by Sergio Guadarrama @sguada)

## Community Models

The publicly-editable [Caffe Model Zoo wiki](https://github.com/BVLC/caffe/wiki/Model-Zoo) catalogues user-made models.
Refer to the model details for authorship and conditions -- please respect licenses and citations.
**Community models** made by Caffe users are posted to a publicly editable [wiki page](https://github.com/BVLC/caffe/wiki/Model-Zoo).
These models are subject to conditions of their respective authors such as citation and license.
Thank you for sharing your models!

## Model info format

Expand All @@ -44,7 +46,7 @@ A caffe model is distributed as a directory containing:

Github Gist is a good format for model info distribution because it can contain multiple files, is versionable, and has in-browser syntax highlighting and markdown rendering.

- `scripts/upload_model_to_gist.sh <dirname>`: uploads non-binary files in the model directory as a Github Gist and prints the Gist ID. If `gist_id` is already part of the `<dirname>/readme.md` frontmatter, then updates existing Gist.
`scripts/upload_model_to_gist.sh <dirname>` uploads non-binary files in the model directory as a Github Gist and prints the Gist ID. If `gist_id` is already part of the `<dirname>/readme.md` frontmatter, then updates existing Gist.

Try doing `scripts/upload_model_to_gist.sh models/bvlc_alexnet` to test the uploading (don't forget to delete the uploaded gist afterward).

Expand All @@ -56,4 +58,13 @@ It is up to the user where to host the `.caffemodel` file.
We host our BVLC-provided models on our own server.
Dropbox also works fine (tip: make sure that `?dl=1` is appended to the end of the URL).

- `scripts/download_model_binary.py <dirname>`: downloads the `.caffemodel` from the URL specified in the `<dirname>/readme.md` frontmatter and confirms SHA1.
`scripts/download_model_binary.py <dirname>` downloads the `.caffemodel` from the URL specified in the `<dirname>/readme.md` frontmatter and confirms SHA1.

## BVLC model license

The Caffe models bundled by the BVLC are released for unrestricted use.

These models are trained on data from the [ImageNet project](http://www.image-net.org/) and training data includes internet photos that may be subject to copyright.

Our present understanding as researchers is that there is no restriction placed on the open release of these learned model weights, since none of the original images are distributed in whole or in part.
To the extent that the interpretation arises that weights are derivative works of the original copyright holder and they assert such a copyright, UC Berkeley makes no representations as to what use is allowed other than to consider our present release in the spirit of fair use in the academic mission of the university to disseminate knowledge and tools as broadly as possible without restriction.
3 changes: 2 additions & 1 deletion examples/hdf5_classification.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"import shutil\n",
"import tempfile\n",
"\n",
"# You may need to 'pip install scikit-learn'\n",
"import sklearn\n",
"import sklearn.datasets\n",
"import sklearn.linear_model"
Expand Down Expand Up @@ -1070,4 +1071,4 @@
"metadata": {}
}
]
}
}
2 changes: 1 addition & 1 deletion examples/web_demo/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import tornado.httpserver
import numpy as np
import pandas as pd
import Image
from PIL import Image
import cStringIO as StringIO
import urllib
import exifutil
Expand Down
4 changes: 2 additions & 2 deletions include/caffe/common_layers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@ class CuDNNSoftmaxLayer : public SoftmaxLayer<Dtype> {

bool handles_setup_;
cudnnHandle_t handle_;
cudnnTensor4dDescriptor_t bottom_desc_;
cudnnTensor4dDescriptor_t top_desc_;
cudnnTensorDescriptor_t bottom_desc_;
cudnnTensorDescriptor_t top_desc_;
};
#endif

Expand Down
2 changes: 2 additions & 0 deletions include/caffe/data_layers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ class HDF5DataLayer : public Layer<Dtype> {
unsigned int current_file_;
hsize_t current_row_;
std::vector<shared_ptr<Blob<Dtype> > > hdf_blobs_;
std::vector<unsigned int> data_permutation_;
std::vector<unsigned int> file_permutation_;
};
*/
/**
Expand Down
96 changes: 90 additions & 6 deletions include/caffe/neuron_layers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,8 @@ class CuDNNReLULayer : public ReLULayer<Dtype> {

bool handles_setup_;
cudnnHandle_t handle_;
cudnnTensor4dDescriptor_t bottom_desc_;
cudnnTensor4dDescriptor_t top_desc_;
cudnnTensorDescriptor_t bottom_desc_;
cudnnTensorDescriptor_t top_desc_;
};
#endif

Expand Down Expand Up @@ -516,8 +516,8 @@ class CuDNNSigmoidLayer : public SigmoidLayer<Dtype> {

bool handles_setup_;
cudnnHandle_t handle_;
cudnnTensor4dDescriptor_t bottom_desc_;
cudnnTensor4dDescriptor_t top_desc_;
cudnnTensorDescriptor_t bottom_desc_;
cudnnTensorDescriptor_t top_desc_;
};
#endif

Expand Down Expand Up @@ -601,8 +601,8 @@ class CuDNNTanHLayer : public TanHLayer<Dtype> {

bool handles_setup_;
cudnnHandle_t handle_;
cudnnTensor4dDescriptor_t bottom_desc_;
cudnnTensor4dDescriptor_t top_desc_;
cudnnTensorDescriptor_t bottom_desc_;
cudnnTensorDescriptor_t top_desc_;
};
#endif

Expand Down Expand Up @@ -654,6 +654,90 @@ class ThresholdLayer : public NeuronLayer<Dtype> {
Dtype threshold_;
};

/**
* @brief Parameterized Rectified Linear Unit non-linearity @f$
* y_i = \max(0, x_i) + a_i \min(0, x_i)
* @f$. The differences from ReLULayer are 1) negative slopes are
* learnable though backprop and 2) negative slopes can vary across
* channels. The number of axes of input blob should be greater than or
* equal to 2. The 1st axis (0-based) is seen as channels.
*/
template <typename Dtype>
class PReLULayer : public NeuronLayer<Dtype> {
public:
/**
* @param param provides PReLUParameter prelu_param,
* with PReLULayer options:
* - filler (\b optional, FillerParameter,
* default {'type': constant 'value':0.25}).
* - channel_shared (\b optional, default false).
* negative slopes are shared across channels.
*/
explicit PReLULayer(const LayerParameter& param)
: NeuronLayer<Dtype>(param) {}

virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top);

virtual void Reshape(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top);

virtual inline const char* type() const { return "PReLU"; }

protected:
/**
* @param bottom input Blob vector (length 1)
* -# @f$ (N \times C \times ...) @f$
* the inputs @f$ x @f$
* @param top output Blob vector (length 1)
* -# @f$ (N \times C \times ...) @f$
* the computed outputs for each channel @f$i@f$ @f$
* y_i = \max(0, x_i) + a_i \min(0, x_i)
* @f$.
*/
virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top);
virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top);

/**
* @brief Computes the error gradient w.r.t. the PReLU inputs.
*
* @param top output Blob vector (length 1), providing the error gradient with
* respect to the outputs
* -# @f$ (N \times C \times ...) @f$
* containing error gradients @f$ \frac{\partial E}{\partial y} @f$
* with respect to computed outputs @f$ y @f$
* @param propagate_down see Layer::Backward.
* @param bottom input Blob vector (length 1)
* -# @f$ (N \times C \times ...) @f$
* the inputs @f$ x @f$; For each channel @f$i@f$, backward fills their
* diff with gradients @f$
* \frac{\partial E}{\partial x_i} = \left\{
* \begin{array}{lr}
* a_i \frac{\partial E}{\partial y_i} & \mathrm{if} \; x_i \le 0 \\
* \frac{\partial E}{\partial y_i} & \mathrm{if} \; x_i > 0
* \end{array} \right.
* @f$.
* If param_propagate_down_[0] is true, it fills the diff with gradients
* @f$
* \frac{\partial E}{\partial a_i} = \left\{
* \begin{array}{lr}
* \sum_{x_i} x_i \frac{\partial E}{\partial y_i} & \mathrm{if} \; x_i \le 0 \\
* 0 & \mathrm{if} \; x_i > 0
* \end{array} \right.
* @f$.
*/
virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,
const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);
virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,
const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);

bool channel_shared_;
Blob<Dtype> multiplier_; // dot multipler for backward computation of params
Blob<Dtype> bottom_memory_; // memory for in-place computation
};

} // namespace caffe

#endif // CAFFE_NEURON_LAYERS_HPP_
2 changes: 1 addition & 1 deletion include/caffe/syncedmem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace caffe {
// cudaMallocHost and cudaFree functions in order to create pinned memory.
// However, those codes rely on the existence of a cuda GPU (I don't know
// why that is a must since allocating memory should not be accessing the
// GPU resorce, but it just creates an error as of Cuda 5.0) and will cause
// GPU resource, but it just creates an error as of Cuda 5.0) and will cause
// problem when running on a machine without GPU. Thus, we simply define
// these two functions for safety and possible future change if the problem
// of calling cuda functions disappears in a future version.
Expand Down
Loading

0 comments on commit 8c31ef1

Please sign in to comment.