Skip to content

Commit 1ed11d5

Browse files
committed
back-merge
2 parents 1718903 + 51be352 commit 1ed11d5

File tree

7 files changed

+40
-37
lines changed

7 files changed

+40
-37
lines changed

docs/installation.md

+9-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Caffe depends on several software packages.
1818
* [CUDA](https://developer.nvidia.com/cuda-zone) library version 6.5 (recommended), 6.0, 5.5, or 5.0 and the latest driver version for CUDA 6 or 319.* for CUDA 5 (and NOT 331.*)
1919
* [BLAS](http://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms) (provided via ATLAS, MKL, or OpenBLAS).
2020
* [OpenCV](http://opencv.org/).
21-
* [Boost](http://www.boost.org/) (>= 1.55, although only 1.55 is tested)
21+
* [Boost](http://www.boost.org/) (>= 1.55, although only 1.55 and 1.56 are tested)
2222
* `glog`, `gflags`, `protobuf`, `leveldb`, `snappy`, `hdf5`, `lmdb`
2323
* For the Python wrapper
2424
* `Python 2.7`, `numpy (>= 1.7)`, boost-provided `boost.python`
@@ -59,7 +59,7 @@ The main requirements are `numpy` and `boost.python` (provided by boost). `panda
5959

6060
You can install the dependencies with
6161

62-
pip install -r /path/to/caffe/python/requirements.txt
62+
for req in $(cat requirements.txt); do sudo pip install $req; done
6363

6464
but we highly recommend first installing the [Anaconda](https://store.continuum.io/cshop/anaconda/) Python distribution, which provides most of the necessary packages, as well as the `hdf5` library dependency.
6565

@@ -141,11 +141,13 @@ Do `brew edit opencv` and change the lines that look like the two lines below to
141141
**NOTE**: We find that everything compiles successfully if `$LD_LIBRARY_PATH` is not set at all, and `$DYLD_FALLBACK_LIBRARY_PATH` is set to to provide CUDA, Python, and other relevant libraries (e.g. `/usr/local/cuda/lib:$HOME/anaconda/lib:/usr/local/lib:/usr/lib`).
142142
In other `ENV` settings, things may not work as expected.
143143

144+
**NOTE**: There is currently a conflict between boost 1.56 and CUDA in some configurations. Check the [conflict description](https://github.com/BVLC/caffe/issues/1193#issuecomment-57491906) and try downgrading to 1.55.
145+
144146
#### 10.8-specific Instructions
145147

146148
Simply run the following:
147149

148-
brew install --build-from-source --with-python boost
150+
brew install --build-from-source boost boost-python
149151
brew install --with-python protobuf
150152
for x in snappy leveldb gflags glog szip lmdb homebrew/science/opencv; do brew install $x; done
151153

@@ -180,22 +182,22 @@ For each of these formulas, `brew edit FORMULA`, and add the ENV definitions as
180182

181183
To edit the formulae in turn, run
182184

183-
for x in snappy leveldb protobuf gflags glog szip boost lmdb homebrew/science/opencv; do brew edit $x; done
185+
for x in snappy leveldb protobuf gflags glog szip boost boost-python lmdb homebrew/science/opencv; do brew edit $x; done
184186

185187
After this, run
186188

187189
for x in snappy leveldb gflags glog szip lmdb homebrew/science/opencv; do brew uninstall $x; brew install --build-from-source --fresh -vd $x; done
188190
brew uninstall protobuf; brew install --build-from-source --with-python --fresh -vd protobuf
189-
brew install --build-from-source --with-python --fresh -vd boost
191+
brew install --build-from-source --fresh -vd boost boost-python
190192

191193
**Note** that `brew install --build-from-source --fresh -vd boost` is fine if you do not need the Caffe Python wrapper.
192194

193195
**Note** that the HDF5 dependency is provided by Anaconda Python in this case.
194196
If you're not using Anaconda, include `hdf5` in the list above.
195197

196-
**Note** that in order to build the caffe python wrappers you must install boost using the --with-python option:
198+
**Note** that in order to build the Caffe Python wrappers you must install `boost` and `boost-python`:
197199

198-
brew install --build-from-source --with-python --fresh -vd boost
200+
brew install --build-from-source --fresh -vd boost boost-python
199201

200202
**Note** that Homebrew maintains itself as a separate git repository and making the above `brew edit FORMULA` changes will change files in your local copy of homebrew's master branch. By default, this will prevent you from updating Homebrew using `brew update`, as you will get an error message like the following:
201203

docs/tutorial/net_layer_blob.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Note that although we have designed blobs with its dimensions corresponding to i
2626

2727
Caffe operations are general with respect to the channel dimension / K. Grayscale and hyperspectral imagery are fine. Caffe can likewise model and process arbitrary vectors in blobs with singleton. That is, the shape of blob holding 1000 vectors of 16 feature dimensions is 1000 x 16 x 1 x 1.
2828

29-
Parameter blob dimensions vary according to the type and configuration of the layer. For a convolution layer with 96 filters of 11 x 11 spatial dimension and 3 inputs the blob is 96 x 3 x 11 x 11. For an inner product / fully-connected layer with 1000 output channels and 1024 input channels the parameter blob is 1 x 1 x 1000 x 4096.
29+
Parameter blob dimensions vary according to the type and configuration of the layer. For a convolution layer with 96 filters of 11 x 11 spatial dimension and 3 inputs the blob is 96 x 3 x 11 x 11. For an inner product / fully-connected layer with 1000 output channels and 1024 input channels the parameter blob is 1 x 1 x 1000 x 1024.
3030

3131
For custom data it may be necessary to hack your own input preparation tool or data layer. However once your data is in your job is done. The modularity of layers accomplishes the rest of the work for you.
3232

@@ -85,7 +85,7 @@ Developing custom layers requires minimal effort by the compositionality of the
8585

8686
The net jointly defines a function and its gradient by composition and auto-differentiation. The composition of every layer's output computes the function to do a given task, and the composition of every layer's backward computes the gradient from the loss to learn the task. Caffe models are end-to-end machine learning engines.
8787

88-
The net is a set of layers connected in a computation graph -- a DAG / directed acyclic graph to be exact. Caffe does all the bookkeeping for any DAG of layers to ensure correctness of the forward and backward passes. A typical net begins with a data layer that loads from disk and ends with a loss layer that computes the objective for a task such as classification or reconstruction.
88+
The net is a set of layers connected in a computation graph -- a directed acyclic graph (DAG) to be exact. Caffe does all the bookkeeping for any DAG of layers to ensure correctness of the forward and backward passes. A typical net begins with a data layer that loads from disk and ends with a loss layer that computes the objective for a task such as classification or reconstruction.
8989

9090
The net is defined as a set of layers and their connections in a plaintext modeling language.
9191
A simple logistic regression classifier

examples/finetune_flickr_style/readme.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ Let's fine-tune the BVLC-distributed CaffeNet model on a different dataset, [Fli
1313

1414
## Explanation
1515

16-
The Flickr-sourced images of the Style dataset are visually very similar to the ImageNet dataset, on which the `caffe_reference_imagenet_model` was trained.
16+
The Flickr-sourced images of the Style dataset are visually very similar to the ImageNet dataset, on which the `bvlc_reference_caffenet` was trained.
1717
Since that model works well for object category classification, we'd like to use it architecture for our style classifier.
1818
We also only have 80,000 images to train on, so we'd like to start with the parameters learned on the 1,000,000 ImageNet images, and fine-tune as needed.
1919
If we give provide the `weights` argument to the `caffe train` command, the pretrained weights will be loaded into our model, matching layers by name.
2020

2121
Because we are predicting 20 classes instead of a 1,000, we do need to change the last layer in the model.
2222
Therefore, we change the name of the last layer from `fc8` to `fc8_flickr` in our prototxt.
23-
Since there is no layer named that in the `caffe_reference_imagenet_model`, that layer will begin training with random weights.
23+
Since there is no layer named that in the `bvlc_reference_caffenet`, that layer will begin training with random weights.
2424

2525
We will also decrease the overall learning rate `base_lr` in the solver prototxt, but boost the `blobs_lr` on the newly introduced layer.
2626
The idea is to have the rest of the model change very slowly with new data, but let the new layer learn fast.
@@ -34,7 +34,7 @@ All steps are to be done from the caffe root directory.
3434
The dataset is distributed as a list of URLs with corresponding labels.
3535
Using a script, we will download a small subset of the data and split it into train and val sets.
3636

37-
caffe % ./models/finetune_flickr_style/assemble_data.py -h
37+
caffe % ./examples/finetune_flickr_style/assemble_data.py -h
3838
usage: assemble_data.py [-h] [-s SEED] [-i IMAGES] [-w WORKERS]
3939

4040
Download a subset of Flickr Style to a directory
@@ -48,12 +48,11 @@ Using a script, we will download a small subset of the data and split it into tr
4848
num workers used to download images. -x uses (all - x)
4949
cores.
5050

51-
caffe % python models/finetune_flickr_style/assemble_data.py --workers=-1 --images=2000 --seed 831486
51+
caffe % python examples/finetune_flickr_style/assemble_data.py --workers=-1 --images=2000 --seed 831486
5252
Downloading 2000 images with 7 workers...
5353
Writing train/val for 1939 successfully downloaded images.
5454

5555
This script downloads images and writes train/val file lists into `data/flickr_style`.
56-
With this random seed there are 1,557 train images and 382 test images.
5756
The prototxts in this example assume this, and also assume the presence of the ImageNet mean file (run `get_ilsvrc_aux.sh` from `data/ilsvrc12` to obtain this if you haven't yet).
5857

5958
We'll also need the ImageNet-trained model, which you can obtain by running `./scripts/download_model_binary.py models/bvlc_reference_caffenet`.
@@ -106,7 +105,8 @@ Now we can train! (You can fine-tune in CPU mode by leaving out the `-gpu` flag.
106105
I0828 22:23:17.438894 11510 solver.cpp:302] Test net output #0: accuracy = 0.2356
107106

108107
Note how rapidly the loss went down. Although the 23.5% accuracy is only modest, it was achieved in only 1000, and evidence that the model is starting to learn quickly and well.
109-
Once the model is fully fine-tuned on the whole training set over 100,000 iterations the final validation accuracy is 91.64%. This takes ~7 hours in Caffe on a K40 GPU.
108+
Once the model is fully fine-tuned on the whole training set over 100,000 iterations the final validation accuracy is 39.16%.
109+
This takes ~7 hours in Caffe on a K40 GPU.
110110

111111
For comparison, here is how the loss goes down when we do not start with a pre-trained model:
112112

@@ -155,7 +155,7 @@ Now try fine-tuning to your own tasks and data!
155155

156156
## Trained model
157157

158-
We provide a model trained on all 80K images, with final accuracy of 98%.
158+
We provide a model trained on all 80K images, with final accuracy of 39%.
159159
Simply do `./scripts/download_model_binary.py models/finetune_flickr_style` to obtain it.
160160

161161
## License

examples/mnist/readme.md

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
---
2-
title: MNIST Tutorial
3-
description: Train and test "LeNet" on MNIST data.
2+
title: LeNet MNIST Tutorial
3+
description: Train and test "LeNet" on the MNIST handwritten digit data.
44
category: example
55
include_in_docs: true
66
priority: 1
77
---
88

9-
# Training MNIST with Caffe
9+
# Training LeNet on MNIST with Caffe
1010

1111
We will assume that you have Caffe successfully compiled. If not, please refer to the [Installation page](/installation.html). In this tutorial, we will assume that your Caffe installation is located at `CAFFE_ROOT`.
1212

1313
## Prepare Datasets
1414

1515
You will first need to download and convert the data format from the MNIST website. To do this, simply run the following commands:
1616

17-
cd $CAFFE_ROOT/data/mnist
18-
./get_mnist.sh
19-
cd $CAFFE_ROOT/examples/mnist
20-
./create_mnist.sh
17+
cd $CAFFE_ROOT
18+
./data/mnist/get_mnist.sh
19+
./examples/mnist/create_mnist.sh
2120

2221
If it complains that `wget` or `gunzip` are not installed, you need to install them respectively. After running the script there should be two datasets, `mnist_train_lmdb`, and `mnist_test_lmdb`.
2322

@@ -228,8 +227,8 @@ Check out the comments explaining each line in the prototxt `$CAFFE_ROOT/example
228227

229228
Training the model is simple after you have written the network definition protobuf and solver protobuf files. Simply run `train_lenet.sh`, or the following command directly:
230229

231-
cd $CAFFE_ROOT/examples/mnist
232-
./train_lenet.sh
230+
cd $CAFFE_ROOT
231+
./examples/mnist/train_lenet.sh
233232

234233
`train_lenet.sh` is a simple script, but here is a quick explanation: the main tool for training is `caffe` with action `train` and the solver protobuf text file as its argument.
235234

models/finetune_flickr_style/readme.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@ name: Finetuning CaffeNet on Flickr Style
33
caffemodel: finetune_flickr_style.caffemodel
44
caffemodel_url: http://dl.caffe.berkeleyvision.org/finetune_flickr_style.caffemodel
55
license: non-commercial
6-
sha1: 443ad95a61fb0b5cd3cee55951bcc1f299186b5e
7-
caffe_commit: 41751046f18499b84dbaf529f64c0e664e2a09fe
6+
sha1: b61b5cef7d771b53b0c488e78d35ccadc073e9cf
7+
caffe_commit: 737ea5e936821b5c69f9c3952d72693ae5843370
88
gist_id: 034c6ac3865563b69e60
99
---
1010

1111
This model is trained exactly as described in `docs/finetune_flickr_style/readme.md`, using all 80000 images.
12-
The final performance on the test set:
12+
The final performance:
1313

14-
I0903 18:40:59.211707 11585 caffe.cpp:167] Loss: 0.407405
15-
I0903 18:40:59.211717 11585 caffe.cpp:179] accuracy = 0.9164
14+
I1017 07:36:17.370688 31333 solver.cpp:228] Iteration 100000, loss = 0.757952
15+
I1017 07:36:17.370730 31333 solver.cpp:247] Iteration 100000, Testing net (#0)
16+
I1017 07:36:34.248730 31333 solver.cpp:298] Test net output #0: accuracy = 0.3916
1617

1718
## License
1819

python/requirements.txt

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
Cython>=0.19.2
2-
h5py>=2.2.0
2+
numpy>=1.7.1
3+
scipy>=0.13.2
4+
scikit-image>=0.9.3
5+
scikit-learn>=0.14.1
6+
matplotlib>=1.3.1
37
ipython>=1.1.0
8+
h5py>=2.2.0
49
leveldb>=0.191
5-
matplotlib>=1.3.1
610
networkx>=1.8.1
711
nose>=1.3.0
8-
numpy>=1.7.1
912
pandas>=0.12.0
13+
python-dateutil>=1.4,<2
1014
protobuf>=2.5.0
1115
python-gflags>=2.0
12-
scikit-image>=0.9.3
13-
scikit-learn>=0.14.1
14-
scipy>=0.13.2

src/caffe/solver.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ template <typename Dtype>
2323
Solver<Dtype>::Solver(const string& param_file)
2424
: net_() {
2525
SolverParameter param;
26-
ReadProtoFromTextFile(param_file, &param);
26+
ReadProtoFromTextFileOrDie(param_file, &param);
2727
Init(param);
2828
}
2929

0 commit comments

Comments
 (0)