# libstdc++ instead of libc++ for CUDA compatibility on 10.9
ifeq ($(OSX), 1)
CXX := /usr/bin/clang++
+ CXXFLAGS += -stdlib=libstdc++
+ LINKFLAGS += -stdlib=libstdc++
# clang throws this warning for cuda headers
WARNINGS += -Wno-unneeded-internal-declaration
- ifneq ($(findstring 10.9, $(shell sw_vers -productVersion)),)
- CXXFLAGS += -stdlib=libstdc++
- LINKFLAGS += -stdlib=libstdc++
- endif
+ # gtest needs to use its own tuple to not conflict with clang
+ CXXFLAGS += -DGTEST_USE_OWN_TR1_TUPLE=1
# boost::thread is called boost_thread-mt to mark multithreading on OS X
LIBRARIES += boost_thread-mt
- NVCCFLAGS += -DOSX
endif
# Custom compiler
endif
else ifeq ($(OSX), 1)
# OS X packages atlas as the vecLib framework
- BLAS_INCLUDE ?= /System/Library/Frameworks/vecLib.framework/Versions/Current/Headers/
LIBRARIES += cblas
- LDFLAGS += -framework vecLib
+ # 10.10 has accelerate while 10.9 has veclib
+ XCODE_CLT_VER := $(shell pkgutil --pkg-info=com.apple.pkg.CLTools_Executables | grep -o 'version: 6')
+ ifneq (,$(findstring version: 6,$(XCODE_CLT_VER)))
+ BLAS_INCLUDE ?= /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/System/Library/Frameworks/Accelerate.framework/Versions/Current/Frameworks/vecLib.framework/Headers/
+ LDFLAGS += -framework Accelerate
+ else
+ BLAS_INCLUDE ?= /System/Library/Frameworks/vecLib.framework/Versions/Current/Headers/
+ LDFLAGS += -framework vecLib
+ endif
endif
endif
INCLUDE_DIRS += $(BLAS_INCLUDE)
LDFLAGS += $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) $(PKG_CONFIG) \
$(foreach library,$(LIBRARIES),-l$(library))
PYTHON_LDFLAGS := $(LDFLAGS) $(foreach library,$(PYTHON_LIBRARIES),-l$(library))
+DYNAMIC_LDFLAGS := -l$(PROJECT) -Wl,-rpath,\$$ORIGIN/../lib
# 'superclean' target recursively* deletes all files ending with an extension
# in $(SUPERCLEAN_EXTS) below. This may be useful if you've built older
@ mkdir -p $@
$(DYNAMIC_NAME): $(OBJS) | $(LIB_BUILD_DIR)
- @ echo LD $<
+ @ echo LD -o $@
$(Q)$(CXX) -shared -o $@ $(OBJS) $(LINKFLAGS) $(LDFLAGS)
$(STATIC_NAME): $(OBJS) | $(LIB_BUILD_DIR)
- @ echo AR $<
+ @ echo AR -o $@
$(Q)ar rcs $@ $(OBJS)
$(BUILD_DIR)/%.o: %.cpp | $(ALL_BUILD_DIRS)
| $(TEST_BIN_DIR)
@ echo CXX/LD -o $@ $<
$(Q)$(CXX) $(TEST_MAIN_SRC) $(TEST_OBJS) $(GTEST_OBJ) \
- -o $@ $(LINKFLAGS) $(LDFLAGS) -l$(PROJECT) -Wl,-rpath,$(LIB_BUILD_DIR)
+ -o $@ $(LINKFLAGS) $(LDFLAGS) $(DYNAMIC_LDFLAGS)
$(TEST_CU_BINS): $(TEST_BIN_DIR)/%.testbin: $(TEST_CU_BUILD_DIR)/%.o \
$(GTEST_OBJ) $(STATIC_NAME) | $(TEST_BIN_DIR)
# "sudo apt-get install nvidia-cuda-toolkit" then use this instead:
# CUDA_DIR := /usr
-# CUDA architecture setting: going with all of them (up to CUDA 5.5 compatible).
-# For the latest architecture, you need to install CUDA >= 6.0 and uncomment
-# the *_50 lines below.
+# CUDA architecture setting: going with all of them.
+# For CUDA < 6.0, comment the *_50 lines for compatibility.
CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \
-gencode arch=compute_20,code=sm_21 \
-gencode arch=compute_30,code=sm_30 \
-gencode arch=compute_35,code=sm_35 \
- #-gencode arch=compute_50,code=sm_50 \
- #-gencode arch=compute_50,code=compute_50
+ -gencode arch=compute_50,code=sm_50 \
+ -gencode arch=compute_50,code=compute_50
# BLAS choice:
# atlas for ATLAS (default)
Caffe is a deep learning framework developed with cleanliness, readability, and speed in mind.<br />
Consult the [project website](http://caffe.berkeleyvision.org) for all documentation.
+
+
+Please ask usage questions and how to model different tasks on the [caffe-users mailing list](https://groups.google.com/forum/#!forum/caffe-users).
+
Switching between CPU and GPU is as simple as setting a flag -- so models can be trained on a GPU machine, and then used on commodity clusters.
**Readable & modifiable implementation** fosters active development.
-In Caffe's first six months, it has been forked by over 300 developers on Github, and many have pushed significant changes.
+In Caffe's first year, it has been forked by over 600 developers on Github, and many have pushed significant changes.
**Speed** makes Caffe perfect for industry use.
Caffe can process over **40M images per day** with a single NVIDIA K40 or Titan GPU\*.
## Documentation
- [DIY Deep Learning for Vision with Caffe](https://docs.google.com/presentation/d/1UeKXVgRvvxg9OUdh_UiC5G71UMscNPlvArsWER41PsU/edit#slide=id.p)<br>
-Caffe tutorial slides.
-- [ACM MM paper](http://ucb-icsi-vision-group.github.io/caffe-paper/caffe.pdf)<br>
-A 4-page report for the ACM Multimedia Open Source competition.
-- [Caffe Tutorial](/tutorial)<br>
-DIY deep learning with this hands-on tutorial to Caffe.
+Tutorial presentation.
+- [Tutorial Documentation](/tutorial)<br>
+Practical guide and framework reference.
+- [arXiv / ACM MM '14 paper](http://arxiv.org/abs/1408.5093)<br>
+A 4-page report for the ACM Multimedia Open Source competition (arXiv:1408.5093v1).
- [Installation instructions](/installation.html)<br>
Tested on Ubuntu, Red Hat, OS X.
* [Model Zoo](/model_zoo.html)<br>
Please cite Caffe in your publications if it helps your research:
- @misc{Jia13caffe,
- Author = {Yangqing Jia},
- Title = { {Caffe}: An Open Source Convolutional Architecture for Fast Feature Embedding},
- Year = {2013},
- Howpublished = {\url{http://caffe.berkeleyvision.org/}}
+ @article{jia2014caffe,
+ Author = {Jia, Yangqing and Shelhamer, Evan and Donahue, Jeff and Karayev, Sergey and Long, Jonathan and Girshick, Ross and Guadarrama, Sergio and Darrell, Trevor},
+ Journal = {arXiv preprint arXiv:1408.5093},
+ Title = {Caffe: Convolutional Architecture for Fast Feature Embedding},
+ Year = {2014}
}
If you do publish a paper where Caffe helped your research, we encourage you to update the [publications wiki](https://github.com/BVLC/caffe/wiki/Publications).
## Acknowledgements
-Yangqing would like to thank the NVIDIA Academic program for providing GPUs, [Oriol Vinyals](http://www1.icsi.berkeley.edu/~vinyals/) for discussions along the journey, and BVLC PI [Trevor Darrell](http://www.eecs.berkeley.edu/~trevor/) for guidance.
+The BVLC Caffe developers would like to thank NVIDIA for GPU donation, A9 and Amazon Web Services for a research grant in support of Caffe development and reproducible research in deep learning, and BVLC PI [Trevor Darrell](http://www.eecs.berkeley.edu/~trevor/) for guidance.
-A core set of BVLC members have contributed much new functionality and many fixes since the original release (alphabetical by first name):
-[Eric Tzeng](https://github.com/erictzeng), [Evan Shelhamer](http://imaginarynumber.net/), [Jeff Donahue](http://jeffdonahue.com/), [Jon Long](https://github.com/longjon), [Ross Girshick](http://www.cs.berkeley.edu/~rbg/), [Sergey Karayev](http://sergeykarayev.com/), [Sergio Guadarrama](http://www.eecs.berkeley.edu/~sguada/).
+The BVLC members who have contributed to Caffe are (alphabetical by first name):
+[Eric Tzeng](https://github.com/erictzeng), [Evan Shelhamer](http://imaginarynumber.net/), [Jeff Donahue](http://jeffdonahue.com/), [Jon Long](https://github.com/longjon), [Ross Girshick](http://www.cs.berkeley.edu/~rbg/), [Sergey Karayev](http://sergeykarayev.com/), [Sergio Guadarrama](http://www.eecs.berkeley.edu/~sguada/), and [Yangqing Jia](http://daggerfs.com/).
-Additionally, the open-source community plays a large and growing role in Caffe's development.
+The open-source community plays an important and growing role in Caffe's development.
Check out the Github [project pulse](https://github.com/BVLC/caffe/pulse) for recent activity, and the [contributors](https://github.com/BVLC/caffe/graphs/contributors) for a sorted list.
We sincerely appreciate your interest and contributions!
If you'd like to contribute, please read the [developing & contributing](development.html) guide.
+Yangqing would like to give a personal thanks to the NVIDIA Academic program for providing GPUs, [Oriol Vinyals](http://www1.icsi.berkeley.edu/~vinyals/) for discussions along the journey, and BVLC PI [Trevor Darrell](http://www.eecs.berkeley.edu/~trevor/) for advice.
+
## Contacting us
All questions about usage, installation, code, and applications should be searched for and asked on the [caffe-users mailing list](https://groups.google.com/forum/#!forum/caffe-users).
# Installation
Prior to installing, it is best to read through this guide and take note of the details for your platform.
-We have installed Caffe on Ubuntu 14.04, Ubuntu 12.04, OS X 10.9, and OS X 10.8.
+We have installed Caffe on Ubuntu 14.04, Ubuntu 12.04, OS X 10.10, 10.9, and 10.8.
- [Prerequisites](#prerequisites)
- [Compilation](#compilation)
* [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.*)
* [BLAS](http://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms) (provided via ATLAS, MKL, or OpenBLAS).
-* [OpenCV](http://opencv.org/).
+* [OpenCV](http://opencv.org/) (>= 2.4)
* [Boost](http://www.boost.org/) (>= 1.55, although only 1.55 and 1.56 are tested)
* `glog`, `gflags`, `protobuf`, `leveldb`, `snappy`, `hdf5`, `lmdb`
* For the Python wrapper
**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`).
In other `ENV` settings, things may not work as expected.
-**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.
+**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 or upgrading to 1.57.
#### 10.8-specific Instructions
**Note** that the HDF5 dependency is provided by Anaconda Python in this case.
If you're not using Anaconda, include `hdf5` in the list above.
-#### 10.9-specific Instructions
+#### 10.10- and 10.9-specific Instructions
-In OS X 10.9, clang++ is the default C++ compiler and uses `libc++` as the standard library.
+In OS X 10.9+, clang++ is the default C++ compiler and uses `libc++` as the standard library.
However, NVIDIA CUDA (even version 6.0) currently links only with `libstdc++`.
This makes it necessary to change the compilation settings for each of the dependencies.
git checkout master
cd /usr/local/Library/Taps/homebrew/homebrew-science
git checkout master
-
+
# Update homebrew; hopefully this works without errors!
brew update
-
+
# Switch back to the caffe branches with the forumlae that you modified earlier
cd /usr/local
git rebase master caffe
cd /usr/local/Library/Taps/homebrew/homebrew-science
git rebase master caffe
# Fix any merge conflicts and commit to caffe branch
-
- # Done!
+
+ # Done!
At this point, you should be running the latest Homebrew packages and your Caffe-related modifications will remain in place.
<img src="fig/forward.jpg" alt="Forward pass" width="320">
-The data $x$ is passed through an inner product layer for $g(x)$ then through a softmax for $h(g(x))$ and softmax loss to give $f_W(x)$.
+The data $$x$$ is passed through an inner product layer for $$g(x)$$ then through a softmax for $$h(g(x))$$ and softmax loss to give $$f_W(x)$$.
The **backward** pass computes the gradient given the loss for learning.
In backward Caffe reverse-composes the gradient of each layer to compute the gradient of the whole model by automatic differentiation.
<img src="fig/backward.jpg" alt="Backward pass" width="320">
-The backward pass begins with the loss and computes the gradient with respect to the output $\frac{\partial f_W}{\partial h}$. The gradient with respect to the rest of the model is computed layer-by-layer through the chain rule. Layers with parameters, like the `INNER_PRODUCT` layer, compute the gradient with respect to their parameters $\frac{\partial f_W}{\partial W_{\text{ip}}}$ during the backward step.
+The backward pass begins with the loss and computes the gradient with respect to the output $$\frac{\partial f_W}{\partial h}$$. The gradient with respect to the rest of the model is computed layer-by-layer through the chain rule. Layers with parameters, like the `INNER_PRODUCT` layer, compute the gradient with respect to their parameters $$\frac{\partial f_W}{\partial W_{\text{ip}}}$$ during the backward step.
These computations follow immediately from defining the model: Caffe plans and carries out the forward and backward passes for you.
The command line interface -- cmdcaffe -- is the `caffe` tool for model training, scoring, and diagnostics. Run `caffe` without any arguments for help. This tool and others are found in caffe/build/tools. (The following example calls require completing the LeNet / MNIST example first.)
-**Training**: `caffe train` learns models from scratch, resumes learning from saved snapshots, and fine-tunes models to new data and tasks. All training requires a solver configuration through the `-solver solver.prototxt` argument. Resuming requires the `-snapshot model_iter_1000.solverstate` argument to load the solver snapshot. Fine-tuning requires the `-weights model.caffemodel` argument for the model initialization.
+**Training**: `caffe train` learns models from scratch, resumes learning from saved snapshots, and fine-tunes models to new data and tasks:
+
+* All training requires a solver configuration through the `-solver solver.prototxt` argument.
+* Resuming requires the `-snapshot model_iter_1000.solverstate` argument to load the solver snapshot.
+* Fine-tuning requires the `-weights model.caffemodel` argument for the model initialization.
+
+For example, you can run:
# train LeNet
caffe train -solver examples/mnist/lenet_solver.prototxt
**Testing**: `caffe test` scores models by running them in the test phase and reports the net output as its score. The net architecture must be properly defined to output an accuracy measure or loss as its output. The per-batch score is reported and then the grand average is reported last.
#
- # score the learned LeNet model on the validation set as defined in the model architeture lenet_train_test.prototxt
- caffe test -model examples/mnist/lenet_train_test.prototxt -weights examples/mnist/lenet_iter_10000 -gpu 0 -iterations 100
+ # score the learned LeNet model on the validation set as defined in the
+ # model architeture lenet_train_test.prototxt
+ caffe test -model examples/mnist/lenet_train_test.prototxt -weights examples/mnist/lenet_iter_10000.caffemodel -gpu 0 -iterations 100
**Benchmarking**: `caffe time` benchmarks model execution layer-by-layer through timing and synchronization. This is useful to check system performance and measure relative execution times for models.
# (These example calls require you complete the LeNet / MNIST example first.)
# time LeNet training on CPU for 10 iterations
caffe time -model examples/mnist/lenet_train_test.prototxt -iterations 10
- # time a model architecture with the given weights on the first GPU for 10 iterations
# time LeNet training on GPU for the default 50 iterations
caffe time -model examples/mnist/lenet_train_test.prototxt -gpu 0
+ # time a model architecture with the given weights on the first GPU for 10 iterations
+ caffe time -model examples/mnist/lenet_train_test.prototxt -weights examples/mnist/lenet_iter_10000.caffemodel -gpu 0 -iterations 10
**Diagnostics**: `caffe device_query` reports GPU details for reference and checking device ordinals for running on a given device in multi-GPU machines.
cd $CAFFE_ROOT/data/cifar10
./get_cifar10.sh
- cd $CAFFE_ROOT/examples/cifar10
- ./create_cifar10.sh
+ cd $CAFFE_ROOT
+ ./examples/cifar10/create_cifar10.sh
If it complains that `wget` or `gunzip` are not installed, you need to install them respectively. After running the script there should be the dataset, `./cifar10-leveldb`, and the data set image mean `./mean.binaryproto`.
Training the model is simple after you have written the network definition protobuf and solver protobuf files (refer to [MNIST Tutorial](../examples/mnist.html)). Simply run `train_quick.sh`, or the following command directly:
- cd $CAFFE_ROOT/examples/cifar10
- ./train_quick.sh
+ cd $CAFFE_ROOT
+ ./examples/cifar10/train_quick.sh
`train_quick.sh` is a simple script, so have a look inside. The main tool for training is `caffe` with the `train` action, and the solver protobuf text file as its argument.
"description": "Use the pre-trained ImageNet model to classify images with the Python interface.",
"example_name": "ImageNet classification",
"include_in_docs": true,
- "priority": 1
+ "priority": 1,
+ "signature": "sha256:2caae2c1fe3e282b8f836d380a45622351c91db18a1591e4f2fa67faba9ab72c"
},
"nbformat": 3,
"nbformat_minor": 0,
"\n",
"Caffe provides a general Python interface for models with `caffe.Net` in `python/caffe/pycaffe.py`, but to make off-the-shelf classification easy we provide a `caffe.Classifier` class and `classify.py` script. Both Python and MATLAB wrappers are provided. However, the Python wrapper has more features so we will describe it here. For MATLAB, refer to `matlab/caffe/matcaffe_demo.m`.\n",
"\n",
- "Before we begin, you must compile Caffe and install the python wrapper by setting your `PYTHONPATH`. If you haven't yet done so, please refer to the [installation instructions](installation.html). This example uses our pre-trained CaffeNet model, an ILSVRC12 image classifier. You can download it by running `./scripts/download_model_binary.py models/bvlc_reference_caffenet`. Note that this pre-trained model is licensed for academic research / non-commercial use only.\n",
+ "Before we begin, you must compile Caffe and install the python wrapper by setting your `PYTHONPATH`. If you haven't yet done so, please refer to the [installation instructions](installation.html). This example uses our pre-trained CaffeNet model, an ILSVRC12 image classifier. You can download it by running `./scripts/download_model_binary.py models/bvlc_reference_caffenet`.\n",
"\n",
"Ready? Let's start."
]
"cell_type": "markdown",
"metadata": {},
"source": [
- "Loading a network is easy. `caffe.Classifier` takes care of everything. Note the arguments for configuring input preprocessing: mean subtraction switched on by giving a mean array, input channel swapping takes care of mapping RGB into the reference ImageNet model's BGR order, and raw scaling multiplies the feature scale from the input [0,1] to the ImageNet model's [0,255]."
+ "Loading a network is easy. `caffe.Classifier` takes care of everything. Note the arguments for configuring input preprocessing: mean subtraction switched on by giving a mean array, input channel swapping takes care of mapping RGB into the reference ImageNet model's BGR order, and raw scaling multiplies the feature scale from the input [0,1] to the ImageNet model's [0,255].\n",
+ "\n",
+ "We will set the phase to test since we are doing testing, and will first use CPU for the computation."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
+ "caffe.set_phase_test()\n",
+ "caffe.set_mode_cpu()\n",
"net = caffe.Classifier(MODEL_FILE, PRETRAINED,\n",
" mean=np.load(caffe_root + 'python/caffe/imagenet/ilsvrc_2012_mean.npy'),\n",
" channel_swap=(2,1,0),\n",
"cell_type": "markdown",
"metadata": {},
"source": [
- "We will set the phase to test since we are doing testing, and will first use CPU for the computation."
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "net.set_phase_test()\n",
- "net.set_mode_cpu()"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [],
- "prompt_number": 3
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
"Let's take a look at our example image with Caffe's image loading helper."
]
},
{
"metadata": {},
"output_type": "pyout",
- "prompt_number": 4,
+ "prompt_number": 3,
"text": [
"<matplotlib.image.AxesImage at 0x7fda204c0e10>"
]
]
}
],
- "prompt_number": 4
+ "prompt_number": 3
},
{
"cell_type": "markdown",
]
}
],
- "prompt_number": 5
+ "prompt_number": 4
},
{
"cell_type": "markdown",
]
}
],
- "prompt_number": 6
+ "prompt_number": 5
},
{
"cell_type": "markdown",
]
}
],
- "prompt_number": 7
+ "prompt_number": 6
},
{
"cell_type": "markdown",
]
}
],
- "prompt_number": 8
+ "prompt_number": 7
},
{
"cell_type": "markdown",
"cell_type": "code",
"collapsed": false,
"input": [
- "net.set_mode_gpu()"
+ "caffe.set_mode_gpu()"
],
"language": "python",
"metadata": {},
"outputs": [],
- "prompt_number": 9
+ "prompt_number": 8
},
{
"cell_type": "markdown",
{
"metadata": {},
"output_type": "pyout",
- "prompt_number": 10,
+ "prompt_number": 9,
"text": [
"[<matplotlib.lines.Line2D at 0x7fda1ac309d0>]"
]
]
}
],
- "prompt_number": 10
+ "prompt_number": 9
},
{
"cell_type": "markdown",
]
}
],
- "prompt_number": 11
+ "prompt_number": 10
},
{
"cell_type": "code",
]
}
],
- "prompt_number": 12
+ "prompt_number": 11
},
{
"cell_type": "markdown",
"metadata": {}
}
]
-}
+}
\ No newline at end of file
"description": "Extracting features and visualizing trained filters with an example image, viewed layer-by-layer.",
"example_name": "Filter visualization",
"include_in_docs": true,
- "priority": 2
+ "priority": 2,
+ "signature": "sha256:526501b358e0f60c489eaf5799e8603a75019cc65401533baa307b5603fdefa1"
},
"nbformat": 3,
"nbformat_minor": 0,
"cell_type": "code",
"collapsed": false,
"input": [
+ "caffe.set_phase_test()\n",
+ "caffe.set_mode_cpu()\n",
"net = caffe.Classifier(caffe_root + 'models/bvlc_reference_caffenet/deploy.prototxt',\n",
" caffe_root + 'models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel')\n",
- "net.set_phase_test()\n",
- "net.set_mode_cpu()\n",
"# input preprocessing: 'data' is the name of the input blob == net.inputs[0]\n",
"net.set_mean('data', np.load(caffe_root + 'python/caffe/imagenet/ilsvrc_2012_mean.npy')) # ImageNet mean\n",
"net.set_raw_scale('data', 255) # the reference model operates on images in [0,255] range instead of [0,1]\n",
"metadata": {}
}
]
-}
+}
\ No newline at end of file
"example_name": "Editing model parameters",
"include_in_docs": true,
"priority": 5,
- "signature": "sha256:179fb20339497f5e64f6fbeb57987f27a962b7ae6d940c8fede2631aba9bffaf"
+ "signature": "sha256:bf84bcbd78fe007310f86d71c5969ba4205b6e06f408029860eec94821844bee"
},
"nbformat": 3,
"nbformat_minor": 0,
"import matplotlib.pyplot as plt\n",
"%matplotlib inline\n",
"\n",
+ "caffe.set_phase_test()\n",
+ "\n",
"# load input and configure preprocessing\n",
"im = caffe.io.load_image('images/cat.jpg')\n",
- "net_full_conv.set_phase_test()\n",
"net_full_conv.set_mean('data', np.load('../python/caffe/imagenet/ilsvrc_2012_mean.npy'))\n",
"net_full_conv.set_channel_swap('data', (2,1,0))\n",
"net_full_conv.set_raw_scale('data', 255.0)\n",
"metadata": {}
}
]
-}
+}
\ No newline at end of file
// is executed we will see a fatal log.
#define NOT_IMPLEMENTED LOG(FATAL) << "Not Implemented Yet"
+// See PR #1236
+namespace cv {class Mat;}
+
namespace caffe {
// We will use the boost shared_ptr instead of the new C++11 one mainly
#ifndef CAFFE_DATA_TRANSFORMER_HPP
#define CAFFE_DATA_TRANSFORMER_HPP
-#ifndef OSX
-#include <opencv2/core/core.hpp>
-#endif
-
#include <vector>
#include "caffe/blob.hpp"
* This is destination blob. It can be part of top blob's data if
* set_cpu_data() is used. See image_data_layer.cpp for an example.
*/
-#ifndef OSX
void Transform(const cv::Mat& cv_img, Blob<Dtype>* transformed_blob);
-#endif
/**
* @brief Applies the same transformation defined in the data layer's
CHECK_GE(sparse, -1);
if (sparse >= 0) {
// Sparse initialization is implemented for "weight" blobs; i.e. matrices.
- // These have num == channels == 1; height is number of inputs; width is
+ // These have num == channels == 1; width is number of inputs; height is
// number of outputs. The 'sparse' variable specifies the mean number
// of non-zero input weights for a given output.
CHECK_EQ(blob->num(), 1);
CHECK_EQ(blob->channels(), 1);
- int num_inputs = blob->height();
- Dtype non_zero_probability = Dtype(sparse) / Dtype(num_inputs);
+ int num_outputs = blob->height();
+ Dtype non_zero_probability = Dtype(sparse) / Dtype(num_outputs);
rand_vec_.reset(new SyncedMemory(blob->count() * sizeof(int)));
int* mask = reinterpret_cast<int*>(rand_vec_->mutable_cpu_data());
caffe_rng_bernoulli(blob->count(), non_zero_probability, mask);
#include "caffe/common.hpp"
-namespace caffe {
-
/**
- * A minimal wrapper for boost::thread to force host compilation for boost
- * Defined in caffe/util/thread.hpp
+ Forward declare boost::thread instead of including boost/thread.hpp
+ to avoid a boost/NVCC issues (#1009, #1010) on OSX.
*/
-class Thread {
- public:
- template<typename Callable, class A1>
- Thread(Callable func, A1 a1);
- void join();
- bool joinable();
- private:
- void* thread_;
-};
+namespace boost { class thread; }
+
+namespace caffe {
/**
* Virtual class encapsulate boost::thread for use in base class
*/
class InternalThread {
public:
- InternalThread() : thread_(NULL) {}
+ InternalThread() : thread_() {}
virtual ~InternalThread();
/** Returns true if the thread was successfully started. **/
/** Will not return until the internal thread has exited. */
bool WaitForInternalThreadToExit();
- bool is_started() const { return thread_ != NULL && thread_->joinable(); }
+ bool is_started() const;
protected:
/* Implement this method in your subclass
with the code you want your thread to run. */
virtual void InternalThreadEntry() {}
- caffe::Thread* thread_;
+ shared_ptr<boost::thread> thread_;
};
} // namespace caffe
-#endif
+#endif // CAFFE_INTERNAL_THREAD_HPP_
* @brief For an already initialized net, implicitly copies (i.e., using no
* additional memory) the pre-trained layers from another Net.
*/
- void ShareTrainedLayersWith(Net* other);
+ void ShareTrainedLayersWith(const Net* other);
// For an already initialized net, CopyTrainedLayersFrom() copies the already
// trained layers from another net parameter instance.
/**
void CopyTrainedLayersFrom(const NetParameter& param);
void CopyTrainedLayersFrom(const string trained_filename);
/// @brief Writes the net to a proto.
- void ToProto(NetParameter* param, bool write_diff = false);
+ void ToProto(NetParameter* param, bool write_diff = false) const;
/// @brief returns the network name.
- inline const string& name() { return name_; }
+ inline const string& name() const { return name_; }
/// @brief returns the layer names
- inline const vector<string>& layer_names() { return layer_names_; }
+ inline const vector<string>& layer_names() const { return layer_names_; }
/// @brief returns the blob names
- inline const vector<string>& blob_names() { return blob_names_; }
+ inline const vector<string>& blob_names() const { return blob_names_; }
/// @brief returns the blobs
- inline const vector<shared_ptr<Blob<Dtype> > >& blobs() { return blobs_; }
+ inline const vector<shared_ptr<Blob<Dtype> > >& blobs() const {
+ return blobs_;
+ }
/// @brief returns the layers
- inline const vector<shared_ptr<Layer<Dtype> > >& layers() { return layers_; }
+ inline const vector<shared_ptr<Layer<Dtype> > >& layers() const {
+ return layers_;
+ }
/**
* @brief returns the bottom vecs for each layer -- usually you won't
* need this unless you do per-layer checks such as gradients.
*/
- inline vector<vector<Blob<Dtype>*> >& bottom_vecs() { return bottom_vecs_; }
+ inline const vector<vector<Blob<Dtype>*> >& bottom_vecs() const {
+ return bottom_vecs_;
+ }
/**
* @brief returns the top vecs for each layer -- usually you won't
* need this unless you do per-layer checks such as gradients.
*/
- inline vector<vector<Blob<Dtype>*> >& top_vecs() { return top_vecs_; }
- inline vector<vector<bool> >& bottom_need_backward() {
+ inline const vector<vector<Blob<Dtype>*> >& top_vecs() const {
+ return top_vecs_;
+ }
+ inline const vector<vector<bool> >& bottom_need_backward() const {
return bottom_need_backward_;
}
- inline vector<Dtype>& blob_loss_weights() {
+ inline const vector<Dtype>& blob_loss_weights() const {
return blob_loss_weights_;
}
/// @brief returns the parameters
- inline vector<shared_ptr<Blob<Dtype> > >& params() { return params_; }
+ inline const vector<shared_ptr<Blob<Dtype> > >& params() const {
+ return params_;
+ }
/// @brief returns the parameter learning rate multipliers
- inline vector<float>& params_lr() { return params_lr_; }
- inline vector<float>& params_weight_decay() { return params_weight_decay_; }
- const map<string, int>& param_names_index() { return param_names_index_; }
+ inline const vector<float>& params_lr() const { return params_lr_; }
+ inline const vector<float>& params_weight_decay() const {
+ return params_weight_decay_;
+ }
+ const map<string, int>& param_names_index() const {
+ return param_names_index_;
+ }
/// @brief Input and output blob numbers
- inline int num_inputs() { return net_input_blobs_.size(); }
- inline int num_outputs() { return net_output_blobs_.size(); }
- inline vector<Blob<Dtype>*>& input_blobs() { return net_input_blobs_; }
- inline vector<Blob<Dtype>*>& output_blobs() { return net_output_blobs_; }
- inline vector<int>& input_blob_indices() { return net_input_blob_indices_; }
- inline vector<int>& output_blob_indices() { return net_output_blob_indices_; }
- bool has_blob(const string& blob_name);
- const shared_ptr<Blob<Dtype> > blob_by_name(const string& blob_name);
- bool has_layer(const string& layer_name);
- const shared_ptr<Layer<Dtype> > layer_by_name(const string& layer_name);
+ inline int num_inputs() const { return net_input_blobs_.size(); }
+ inline int num_outputs() const { return net_output_blobs_.size(); }
+ inline const vector<Blob<Dtype>*>& input_blobs() const {
+ return net_input_blobs_;
+ }
+ inline const vector<Blob<Dtype>*>& output_blobs() const {
+ return net_output_blobs_;
+ }
+ inline const vector<int>& input_blob_indices() const {
+ return net_input_blob_indices_;
+ }
+ inline const vector<int>& output_blob_indices() const {
+ return net_output_blob_indices_;
+ }
+ bool has_blob(const string& blob_name) const;
+ const shared_ptr<Blob<Dtype> > blob_by_name(const string& blob_name) const;
+ bool has_layer(const string& layer_name) const;
+ const shared_ptr<Layer<Dtype> > layer_by_name(const string& layer_name) const;
void set_debug_info(const bool value) { debug_info_ = value; }
#ifndef CAFFE_UTIL_IO_H_
#define CAFFE_UTIL_IO_H_
-#ifndef OSX
-#include <opencv2/core/core.hpp>
-#endif
-
#include <unistd.h>
#include <string>
#include "hdf5_hl.h"
#include "caffe/blob.hpp"
+#include "caffe/common.hpp"
#include "caffe/proto/caffe.pb.h"
#define HDF5_NUM_DIMS 4
return DecodeDatum(0, 0, true, datum);
}
-#ifndef OSX
cv::Mat ReadImageToCVMat(const string& filename,
const int height, const int width, const bool is_color);
-inline cv::Mat ReadImageToCVMat(const string& filename,
- const int height, const int width) {
- return ReadImageToCVMat(filename, height, width, true);
-}
+cv::Mat ReadImageToCVMat(const string& filename,
+ const int height, const int width);
-inline cv::Mat ReadImageToCVMat(const string& filename,
- const bool is_color) {
- return ReadImageToCVMat(filename, 0, 0, is_color);
-}
+cv::Mat ReadImageToCVMat(const string& filename,
+ const bool is_color);
-inline cv::Mat ReadImageToCVMat(const string& filename) {
- return ReadImageToCVMat(filename, 0, 0, true);
-}
+cv::Mat ReadImageToCVMat(const string& filename);
cv::Mat DecodeDatumToCVMat(const Datum& datum,
const int height, const int width, const bool is_color);
-inline cv::Mat DecodeDatumToCVMat(const Datum& datum,
- const int height, const int width) {
- return DecodeDatumToCVMat(datum, height, width, true);
-}
+cv::Mat DecodeDatumToCVMat(const Datum& datum,
+ const int height, const int width);
-inline cv::Mat DecodeDatumToCVMat(const Datum& datum,
- const bool is_color) {
- return DecodeDatumToCVMat(datum, 0, 0, is_color);
-}
+cv::Mat DecodeDatumToCVMat(const Datum& datum,
+ const bool is_color);
-inline cv::Mat DecodeDatumToCVMat(const Datum& datum) {
- return DecodeDatumToCVMat(datum, 0, 0, true);
-}
+cv::Mat DecodeDatumToCVMat(const Datum& datum);
void CVMatToDatum(const cv::Mat& cv_img, Datum* datum);
-#endif
template <typename Dtype>
void hdf5_load_nd_dataset_helper(
- hid_t file_id, const char* dataset_name_, int min_dim, int max_dim,
- Blob<Dtype>* blob);
+ hid_t file_id, const char* dataset_name_, int min_dim, int max_dim,
+ Blob<Dtype>* blob);
template <typename Dtype>
void hdf5_load_nd_dataset(
- hid_t file_id, const char* dataset_name_, int min_dim, int max_dim,
- Blob<Dtype>* blob);
+ hid_t file_id, const char* dataset_name_, int min_dim, int max_dim,
+ Blob<Dtype>* blob);
template <typename Dtype>
void hdf5_save_nd_dataset(
- const hid_t file_id, const string dataset_name, const Blob<Dtype>& blob);
+ const hid_t file_id, const string& dataset_name, const Blob<Dtype>& blob);
} // namespace caffe
+++ /dev/null
-#ifndef CAFFE_THREAD_CPP_HPP_
-#define CAFFE_THREAD_CPP_HPP_
-
-#include <boost/thread.hpp>
-#include "caffe/common.hpp"
-#include "caffe/internal_thread.hpp"
-
-namespace caffe {
-
-template<typename Callable, class A1>
-Thread::Thread(Callable func, A1 a1) {
- this->thread_ = new boost::thread(func, a1);
-}
-
-void Thread::join() {
- static_cast<boost::thread*>(this->thread_)->join();
-}
-
-bool Thread::joinable() {
- return static_cast<boost::thread*>(this->thread_)->joinable();
-}
-
-} // namespace caffe
-
-#endif
name: BVLC AlexNet Model
caffemodel: bvlc_alexnet.caffemodel
caffemodel_url: http://dl.caffe.berkeleyvision.org/bvlc_alexnet.caffemodel
-license: non-commercial
+license: unrestricted
sha1: 9116a64c0fbe4459d18f4bb6b56d647b63920377
caffe_commit: 709dc15af4a06bebda027c1eb2b3f3e3375d5077
---
## License
-The data used to train this model comes from the ImageNet project, which distributes its database to researchers who agree to a following term of access:
-"Researcher shall use the Database only for non-commercial research and educational purposes."
-Accordingly, this model is distributed under a non-commercial license.
+This model is released for unrestricted use.
name: BVLC CaffeNet Model
caffemodel: bvlc_reference_caffenet.caffemodel
caffemodel_url: http://dl.caffe.berkeleyvision.org/bvlc_reference_caffenet.caffemodel
-license: non-commercial
+license: unrestricted
sha1: 4c8d77deb20ea792f84eb5e6d0a11ca0a8660a46
caffe_commit: 709dc15af4a06bebda027c1eb2b3f3e3375d5077
---
## License
-The data used to train this model comes from the ImageNet project, which distributes its database to researchers who agree to a following term of access:
-"Researcher shall use the Database only for non-commercial research and educational purposes."
-Accordingly, this model is distributed under a non-commercial license.
+This model is released for unrestricted use.
name: BVLC Reference RCNN ILSVRC13 Model
caffemodel: bvlc_reference_rcnn_ilsvrc13.caffemodel
caffemodel_url: http://dl.caffe.berkeleyvision.org/bvlc_reference_rcnn_ilsvrc13.caffemodel
-license: non-commercial
+license: unrestricted
sha1: bdd8abb885819cba5e2fe1eb36235f2319477e64
caffe_commit: a7e397abbda52c0b90323c23ab95bdeabee90a98
---
## License
-The data used to train this model comes from the ImageNet project, which distributes its database to researchers who agree to a following term of access:
-"Researcher shall use the Database only for non-commercial research and educational purposes."
-Accordingly, this model is distributed under a non-commercial license.
+This model is released for unrestricted use.
from .pycaffe import Net, SGDSolver
+from .pycaffe import set_mode_cpu, set_mode_gpu, set_phase_train, set_phase_test
+from .pycaffe import set_device
from .classifier import Classifier
from .detector import Detector
import io
}
BOOST_PYTHON_MODULE(_caffe) {
+ // Caffe utility methods
+ bp::def("set_mode_cpu", &set_mode_cpu);
+ bp::def("set_mode_gpu", &set_mode_gpu);
+ bp::def("set_phase_train", &set_phase_train);
+ bp::def("set_phase_test", &set_phase_test);
+ bp::def("set_device", &Caffe::SetDevice);
+
// below, we prepend an underscore to methods that will be replaced
// in Python
bp::class_<PyNet, shared_ptr<PyNet> >(
.def("_forward", &PyNet::Forward)
.def("_backward", &PyNet::Backward)
.def("reshape", &PyNet::Reshape)
- .def("set_mode_cpu", &PyNet::set_mode_cpu)
- .def("set_mode_gpu", &PyNet::set_mode_gpu)
- .def("set_phase_train", &PyNet::set_phase_train)
- .def("set_phase_test", &PyNet::set_phase_test)
- .def("set_device", &PyNet::set_device)
.add_property("_blobs", &PyNet::blobs)
.add_property("layers", &PyNet::layers)
.add_property("_blob_names", &PyNet::blob_names)
namespace caffe {
+// Selecting mode and phase.
+void set_mode_cpu() { Caffe::set_mode(Caffe::CPU); }
+void set_mode_gpu() { Caffe::set_mode(Caffe::GPU); }
+void set_phase_train() { Caffe::set_phase(Caffe::TRAIN); }
+void set_phase_test() { Caffe::set_phase(Caffe::TEST); }
+
// wrap shared_ptr<Blob> in a class that we construct in C++ and pass
// to Python
template <typename Dtype>
WriteProtoToBinaryFile(net_param, filename.c_str());
}
- // The caffe::Caffe utility functions.
- void set_mode_cpu() { Caffe::set_mode(Caffe::CPU); }
- void set_mode_gpu() { Caffe::set_mode(Caffe::GPU); }
- void set_phase_train() { Caffe::set_phase(Caffe::TRAIN); }
- void set_phase_test() { Caffe::set_phase(Caffe::TEST); }
- void set_device(int device_id) { Caffe::SetDevice(device_id); }
-
vector<PyBlob<float> > blobs() {
return vector<PyBlob<float> >(net_->blobs().begin(), net_->blobs().end());
}
preprocessing options.
"""
caffe.Net.__init__(self, model_file, pretrained_file)
- self.set_phase_test()
+ caffe.set_phase_test()
if gpu:
- self.set_mode_gpu()
+ caffe.set_mode_gpu()
else:
- self.set_mode_cpu()
+ caffe.set_mode_cpu()
if mean is not None:
self.set_mean(self.inputs[0], mean)
R-CNN feature extraction.
"""
caffe.Net.__init__(self, model_file, pretrained_file)
- self.set_phase_test()
+ caffe.set_phase_test()
if gpu:
- self.set_mode_gpu()
+ caffe.set_mode_gpu()
else:
- self.set_mode_cpu()
+ caffe.set_mode_cpu()
if mean is not None:
self.set_mean(self.inputs[0], mean)
im: resized ndarray with shape (new_dims[0], new_dims[1], K)
"""
if im.shape[-1] == 1 or im.shape[-1] == 3:
- # skimage is fast but only understands {1,3} channel images in [0, 1].
im_min, im_max = im.min(), im.max()
- im_std = (im - im_min) / (im_max - im_min)
- resized_std = resize(im_std, new_dims, order=interp_order)
- resized_im = resized_std * (im_max - im_min) + im_min
+ if im_max > im_min:
+ # skimage is fast but only understands {1,3} channel images in [0, 1].
+ im_std = (im - im_min) / (im_max - im_min)
+ resized_std = resize(im_std, new_dims, order=interp_order)
+ resized_im = resized_std * (im_max - im_min) + im_min
+ else:
+ # the image is a constant -- avoid divide by 0
+ ret = np.empty((new_dims[0], new_dims[1], im.shape[-1]), dtype=np.float32)
+ ret.fill(im_min)
+ return ret
else:
# ndimage interpolates anything but more slowly.
scale = tuple(np.array(new_dims) / np.array(im.shape[:2]))
import numpy as np
from ._caffe import Net, SGDSolver
+from ._caffe import set_mode_cpu, set_mode_gpu, set_phase_train, set_phase_test
+from ._caffe import set_device
import caffe.io
# We directly update methods from Net here (rather than using composition or
python-dateutil>=1.4,<2
protobuf>=2.5.0
python-gflags>=2.0
+pyyaml>=3.10
PORT=${1:-4000}
-echo "usage: build.sh [port]"
+echo "usage: build_docs.sh [port]"
# Find the docs dir, no matter where the script is called
ROOT_DIR="$( cd "$(dirname "$0")"/.. ; pwd -P )"
-#ifndef OSX
#include <opencv2/core/core.hpp>
-#endif
#include <string>
#include <vector>
}
}
-#ifndef OSX
template<typename Dtype>
void DataTransformer<Dtype>::Transform(const cv::Mat& cv_img,
Blob<Dtype>* transformed_blob) {
}
}
}
-#endif
template<typename Dtype>
void DataTransformer<Dtype>::Transform(Blob<Dtype>* input_blob,
+#include <boost/thread.hpp>
#include "caffe/internal_thread.hpp"
-#include "caffe/util/thread.hpp"
-
namespace caffe {
InternalThread::~InternalThread() {
WaitForInternalThreadToExit();
- if (thread_ != NULL) {
- delete thread_;
- }
}
+bool InternalThread::is_started() const {
+ return thread_.get() != NULL && thread_->joinable();
+}
+
+
bool InternalThread::StartInternalThread() {
if (!WaitForInternalThreadToExit()) {
return false;
}
try {
- thread_ = new caffe::Thread
- (&InternalThread::InternalThreadEntry, this);
+ thread_.reset(
+ new boost::thread(&InternalThread::InternalThreadEntry, this));
} catch (...) {
return false;
}
REGISTER_LAYER_CREATOR(TANH, GetTanHLayer);
// Layers that use their constructor as their default creator should be
-// registered in their corresponding cpp files. Do not registere them here.
+// registered in their corresponding cpp files. Do not register them here.
} // namespace caffe
+#include <opencv2/core/core.hpp>
+
#include <stdint.h>
#include <string>
+#include <opencv2/core/core.hpp>
+
#include <fstream> // NOLINT(readability/streams)
#include <iostream> // NOLINT(readability/streams)
#include <string>
}
template <typename Dtype>
-void Net<Dtype>::ShareTrainedLayersWith(Net* other) {
+void Net<Dtype>::ShareTrainedLayersWith(const Net* other) {
int num_source_layers = other->layers().size();
for (int i = 0; i < num_source_layers; ++i) {
Layer<Dtype>* source_layer = other->layers()[i].get();
}
template <typename Dtype>
-void Net<Dtype>::ToProto(NetParameter* param, bool write_diff) {
+void Net<Dtype>::ToProto(NetParameter* param, bool write_diff) const {
param->Clear();
param->set_name(name_);
// Add bottom and top
}
template <typename Dtype>
-bool Net<Dtype>::has_blob(const string& blob_name) {
+bool Net<Dtype>::has_blob(const string& blob_name) const {
return blob_names_index_.find(blob_name) != blob_names_index_.end();
}
template <typename Dtype>
const shared_ptr<Blob<Dtype> > Net<Dtype>::blob_by_name(
- const string& blob_name) {
+ const string& blob_name) const {
shared_ptr<Blob<Dtype> > blob_ptr;
if (has_blob(blob_name)) {
- blob_ptr = blobs_[blob_names_index_[blob_name]];
+ blob_ptr = blobs_[blob_names_index_.find(blob_name)->second];
} else {
blob_ptr.reset((Blob<Dtype>*)(NULL));
LOG(WARNING) << "Unknown blob name " << blob_name;
}
template <typename Dtype>
-bool Net<Dtype>::has_layer(const string& layer_name) {
+bool Net<Dtype>::has_layer(const string& layer_name) const {
return layer_names_index_.find(layer_name) != layer_names_index_.end();
}
template <typename Dtype>
const shared_ptr<Layer<Dtype> > Net<Dtype>::layer_by_name(
- const string& layer_name) {
+ const string& layer_name) const {
shared_ptr<Layer<Dtype> > layer_ptr;
if (has_layer(layer_name)) {
- layer_ptr = layers_[layer_names_index_[layer_name]];
+ layer_ptr = layers_[layer_names_index_.find(layer_name)->second];
} else {
layer_ptr.reset((Layer<Dtype>*)(NULL));
LOG(WARNING) << "Unknown layer name " << layer_name;
optional float max = 4 [default = 1]; // the max value in uniform filler
optional float mean = 5 [default = 0]; // the mean value in Gaussian filler
optional float std = 6 [default = 1]; // the std value in Gaussian filler
- // The expected number of non-zero input weights for a given output in
+ // The expected number of non-zero output weights for a given input in
// Gaussian filler -- the default -1 means don't perform sparsification.
optional int32 sparse = 7 [default = -1];
}
template <typename Dtype>
void SGDSolver<Dtype>::PreSolve() {
// Initialize the history
- vector<shared_ptr<Blob<Dtype> > >& net_params = this->net_->params();
+ const vector<shared_ptr<Blob<Dtype> > >& net_params = this->net_->params();
history_.clear();
update_.clear();
temp_.clear();
template <typename Dtype>
void SGDSolver<Dtype>::ComputeUpdateValue() {
- vector<shared_ptr<Blob<Dtype> > >& net_params = this->net_->params();
- vector<float>& net_params_lr = this->net_->params_lr();
- vector<float>& net_params_weight_decay = this->net_->params_weight_decay();
+ const vector<shared_ptr<Blob<Dtype> > >& net_params = this->net_->params();
+ const vector<float>& net_params_lr = this->net_->params_lr();
+ const vector<float>& net_params_weight_decay =
+ this->net_->params_weight_decay();
// get the learning rate
Dtype rate = GetLearningRate();
if (this->param_.display() && this->iter_ % this->param_.display() == 0) {
template <typename Dtype>
void NesterovSolver<Dtype>::ComputeUpdateValue() {
- vector<shared_ptr<Blob<Dtype> > >& net_params = this->net_->params();
- vector<float>& net_params_lr = this->net_->params_lr();
- vector<float>& net_params_weight_decay = this->net_->params_weight_decay();
+ const vector<shared_ptr<Blob<Dtype> > >& net_params = this->net_->params();
+ const vector<float>& net_params_lr = this->net_->params_lr();
+ const vector<float>& net_params_weight_decay =
+ this->net_->params_weight_decay();
// get the learning rate
Dtype rate = this->GetLearningRate();
if (this->param_.display() && this->iter_ % this->param_.display() == 0) {
template <typename Dtype>
void AdaGradSolver<Dtype>::ComputeUpdateValue() {
- vector<shared_ptr<Blob<Dtype> > >& net_params = this->net_->params();
- vector<float>& net_params_lr = this->net_->params_lr();
- vector<float>& net_params_weight_decay = this->net_->params_weight_decay();
+ const vector<shared_ptr<Blob<Dtype> > >& net_params = this->net_->params();
+ const vector<float>& net_params_lr = this->net_->params_lr();
+ const vector<float>& net_params_weight_decay =
+ this->net_->params_weight_decay();
// get the learning rate
Dtype rate = this->GetLearningRate();
Dtype delta = this->param_.delta();
#include "caffe/proto/caffe.pb.h"
#include "caffe/util/io.hpp"
+const int kProtoReadBytesLimit = INT_MAX; // Max size of 2 GB minus 1 byte.
+
namespace caffe {
using google::protobuf::io::FileInputStream;
CHECK_NE(fd, -1) << "File not found: " << filename;
ZeroCopyInputStream* raw_input = new FileInputStream(fd);
CodedInputStream* coded_input = new CodedInputStream(raw_input);
- coded_input->SetTotalBytesLimit(1073741824, 536870912);
+ coded_input->SetTotalBytesLimit(kProtoReadBytesLimit, 536870912);
bool success = proto->ParseFromCodedStream(coded_input);
return cv_img;
}
+cv::Mat ReadImageToCVMat(const string& filename,
+ const int height, const int width) {
+ return ReadImageToCVMat(filename, height, width, true);
+}
+
+cv::Mat ReadImageToCVMat(const string& filename,
+ const bool is_color) {
+ return ReadImageToCVMat(filename, 0, 0, is_color);
+}
+
+cv::Mat ReadImageToCVMat(const string& filename) {
+ return ReadImageToCVMat(filename, 0, 0, true);
+}
+
bool ReadImageToDatum(const string& filename, const int label,
const int height, const int width, const bool is_color, Datum* datum) {
cv::Mat cv_img = ReadImageToCVMat(filename, height, width, is_color);
return cv_img;
}
+cv::Mat DecodeDatumToCVMat(const Datum& datum,
+ const int height, const int width) {
+ return DecodeDatumToCVMat(datum, height, width, true);
+}
+
+cv::Mat DecodeDatumToCVMat(const Datum& datum,
+ const bool is_color) {
+ return DecodeDatumToCVMat(datum, 0, 0, is_color);
+}
+
+cv::Mat DecodeDatumToCVMat(const Datum& datum) {
+ return DecodeDatumToCVMat(datum, 0, 0, true);
+}
+
// If Datum is encoded will decoded using DecodeDatumToCVMat and CVMatToDatum
// if height and width are set it will resize it
// If Datum is not encoded will do nothing
template <>
void hdf5_save_nd_dataset<float>(
- const hid_t file_id, const string dataset_name, const Blob<float>& blob) {
+ const hid_t file_id, const string& dataset_name, const Blob<float>& blob) {
hsize_t dims[HDF5_NUM_DIMS];
dims[0] = blob.num();
dims[1] = blob.channels();
template <>
void hdf5_save_nd_dataset<double>(
- const hid_t file_id, const string dataset_name, const Blob<double>& blob) {
+ const hid_t file_id, const string& dataset_name, const Blob<double>& blob) {
hsize_t dims[HDF5_NUM_DIMS];
dims[0] = blob.num();
dims[1] = blob.channels();
caffe_net.Backward();
const vector<shared_ptr<Layer<float> > >& layers = caffe_net.layers();
- vector<vector<Blob<float>*> >& bottom_vecs = caffe_net.bottom_vecs();
- vector<vector<Blob<float>*> >& top_vecs = caffe_net.top_vecs();
+ const vector<vector<Blob<float>*> >& bottom_vecs = caffe_net.bottom_vecs();
+ const vector<vector<Blob<float>*> >& top_vecs = caffe_net.top_vecs();
const vector<vector<bool> >& bottom_need_backward =
caffe_net.bottom_need_backward();
LOG(INFO) << "*** Benchmark begins ***";
" http://www.image-net.org/download-images\n");
gflags::ParseCommandLineFlags(&argc, &argv, true);
- if (argc != 4) {
+ if (argc < 4) {
gflags::ShowUsageWithFlagsRestrict(argv[0], "tools/convert_imageset");
return 1;
}