From 2f869e7426e47d5123ee399704ff386bfdee8387 Mon Sep 17 00:00:00 2001 From: Evan Shelhamer Date: Sat, 24 Jan 2015 18:27:15 -0800 Subject: [PATCH 01/23] clarify draw_net.py usage: net prototxt, not caffemodel --- python/draw_net.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/draw_net.py b/python/draw_net.py index ba488294275..abf701572a2 100755 --- a/python/draw_net.py +++ b/python/draw_net.py @@ -11,7 +11,7 @@ def main(argv): if len(argv) != 3: - print 'Usage: %s input_net_proto_file output_image_file' % \ + print 'Usage: %s input_net_prototxt output_image_file' % \ os.path.basename(sys.argv[0]) else: net = caffe_pb2.NetParameter() From 61c63f6d1ed4cd6a3c4b4d9229497fc89c5ef662 Mon Sep 17 00:00:00 2001 From: Evan Shelhamer Date: Sat, 24 Jan 2015 18:28:46 -0800 Subject: [PATCH 02/23] [docs] ask install + hardware questions on caffe-users --- docs/installation.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/installation.md b/docs/installation.md index a42ef5b309c..16e319b4392 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -11,6 +11,8 @@ We have installed Caffe on Ubuntu 14.04, Ubuntu 12.04, OS X 10.9, and OS X 10.8. - [Compilation](#compilation) - [Hardware questions](#hardware_questions) +Ask installation questions on the [caffe-users](https://groups.google.com/forum/#!forum/caffe-users) mailing list. + ## Prerequisites Caffe depends on several software packages. @@ -299,4 +301,4 @@ As a workaround, if you are using Ubuntu 12.04 you can try the following steps t Once installed, check your times against our [reference performance numbers](performance_hardware.html) to make sure everything is configured properly. -Refer to the project's issue tracker for [hardware/compatibility](https://github.com/BVLC/caffe/issues?labels=hardware%2Fcompatibility&page=1&state=open). +Ask hardware questions on the [caffe-users](https://groups.google.com/forum/#!forum/caffe-users) mailing list. From 4cc8195d82f13391545b90c9c61baaca39b6df84 Mon Sep 17 00:00:00 2001 From: Evan Shelhamer Date: Thu, 29 Jan 2015 09:26:12 -0800 Subject: [PATCH 03/23] [docs] send API link to class list --- docs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index ccc8f750eef..bf1d9c3c78b 100644 --- a/docs/index.md +++ b/docs/index.md @@ -46,7 +46,7 @@ Tested on Ubuntu, Red Hat, OS X. BVLC suggests a standard distribution format for Caffe models, and provides trained models. * [Developing & Contributing](/development.html)
Guidelines for development and contributing to Caffe. -* [API Documentation](/doxygen/)
+* [API Documentation](/doxygen/annotated.html)
Developer documentation automagically generated from code comments. ### Examples From 1f7c3dea034ef19acd1addf5aa8f4c2b94bc358c Mon Sep 17 00:00:00 2001 From: Evan Shelhamer Date: Thu, 29 Jan 2015 10:53:44 -0800 Subject: [PATCH 04/23] [docs] add check mode hint to CPU-only mode error --- include/caffe/util/device_alternate.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/caffe/util/device_alternate.hpp b/include/caffe/util/device_alternate.hpp index 3df28a49ac3..1a33b947991 100644 --- a/include/caffe/util/device_alternate.hpp +++ b/include/caffe/util/device_alternate.hpp @@ -7,7 +7,7 @@ // Stub out GPU calls as unavailable. -#define NO_GPU LOG(FATAL) << "CPU-only Mode: cannot make GPU call." +#define NO_GPU LOG(FATAL) << "Cannot make GPU call in CPU-only mode: check mode setting." #define STUB_GPU(classname) \ template \ From 8b9647223346a2528804cb5bc8943f2065846d7d Mon Sep 17 00:00:00 2001 From: Andre Ambrosio Boechat Date: Fri, 30 Jan 2015 13:57:31 -0200 Subject: [PATCH 05/23] Brief explanation of SLICE layer's attributes * A sample code was added. * `slice_dim` and `slice_point` attributes were explained. --- docs/tutorial/layers.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/tutorial/layers.md b/docs/tutorial/layers.md index 5f8f519cdc4..34bb48050e8 100644 --- a/docs/tutorial/layers.md +++ b/docs/tutorial/layers.md @@ -451,6 +451,26 @@ The `CONCAT` layer is a utility layer that concatenates its multiple input blobs The `SLICE` layer is a utility layer that slices an input layer to multiple output layers along a given dimension (currently num or channel only) with given slice indices. +* Sample + + layers { + name: "slicer_label" + type: SLICE + bottom: "label" + ## Example of label with a shape N x 3 x 1 x 1 + top: "label1" + top: "label2" + top: "label3" + slice_param { + slice_dim: 1 + slice_point: 1 + slice_point: 2 + } + } + +`slice_dim` indicates the target dimension and can assume only two values: 0 for num or 1 for channel; `slice_point` indicates indexes in the selected dimension (the number of indexes must be equal to the number of top blobs minus one). + + #### Elementwise Operations `ELTWISE` From 75d0e16be912a8dd23eddd8756ee0d278c66d6ab Mon Sep 17 00:00:00 2001 From: Evan Shelhamer Date: Fri, 30 Jan 2015 11:25:31 -0800 Subject: [PATCH 06/23] lint 1f7c3de --- include/caffe/util/device_alternate.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/caffe/util/device_alternate.hpp b/include/caffe/util/device_alternate.hpp index 1a33b947991..4d731e26199 100644 --- a/include/caffe/util/device_alternate.hpp +++ b/include/caffe/util/device_alternate.hpp @@ -7,7 +7,7 @@ // Stub out GPU calls as unavailable. -#define NO_GPU LOG(FATAL) << "Cannot make GPU call in CPU-only mode: check mode setting." +#define NO_GPU LOG(FATAL) << "Cannot use GPU in CPU-only Caffe: check mode." #define STUB_GPU(classname) \ template \ From 1e0d49a39d1e38c8de2a4c24ab0bff3a71da21ff Mon Sep 17 00:00:00 2001 From: Brandon Amos Date: Mon, 16 Feb 2015 15:09:24 -0500 Subject: [PATCH 07/23] Correct 'epochs' to 'iterations' See https://github.com/BVLC/caffe/blob/master/models/bvlc_reference_caffenet/solver.prototxt --- examples/imagenet/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/imagenet/readme.md b/examples/imagenet/readme.md index 41384f9475b..c2dd62ec963 100644 --- a/examples/imagenet/readme.md +++ b/examples/imagenet/readme.md @@ -67,7 +67,7 @@ We will also lay out a protocol buffer for running the solver. Let's make a few * We will run in batches of 256, and run a total of 450,000 iterations (about 90 epochs). * For every 1,000 iterations, we test the learned net on the validation data. * We set the initial learning rate to 0.01, and decrease it every 100,000 iterations (about 20 epochs). -* Information will be displayed every 20 epochs. +* Information will be displayed every 20 iterations. * The network will be trained with momentum 0.9 and a weight decay of 0.0005. * For every 10,000 iterations, we will take a snapshot of the current status. From af01b9c7354b36620881b0d2e608df83ebcedfd5 Mon Sep 17 00:00:00 2001 From: e3 Date: Thu, 19 Feb 2015 22:07:27 -0800 Subject: [PATCH 08/23] Updated the path for get_ilsvrc_aux.sh to match what is found in the current project --- examples/imagenet/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/imagenet/readme.md b/examples/imagenet/readme.md index c2dd62ec963..a6bdf49ca4d 100644 --- a/examples/imagenet/readme.md +++ b/examples/imagenet/readme.md @@ -26,7 +26,7 @@ We assume that you already have downloaded the ImageNet training data and valida You will first need to prepare some auxiliary data for training. This data can be downloaded by: - ./data/get_ilsvrc_aux.sh + ./data/ilsvrc12/get_ilsvrc_aux.sh The training and validation input are described in `train.txt` and `val.txt` as text listing all the files and their labels. Note that we use a different indexing for labels than the ILSVRC devkit: we sort the synset names in their ASCII order, and then label them from 0 to 999. See `synset_words.txt` for the synset/name mapping. From eabbccd4d3f4ba5e1f7b37bf1e5ae3f7b67992cc Mon Sep 17 00:00:00 2001 From: Evan Shelhamer Date: Fri, 20 Feb 2015 11:18:47 -0800 Subject: [PATCH 09/23] [build] fix dynamic linking of tools set the right rpath for tools and examples respectively thanks for the report @mees! --- Makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 29827270baf..2a75d66e02a 100644 --- a/Makefile +++ b/Makefile @@ -537,7 +537,12 @@ $(TOOL_BUILD_DIR)/%: $(TOOL_BUILD_DIR)/%.bin | $(TOOL_BUILD_DIR) @ $(RM) $@ @ ln -s $(abspath $<) $@ -$(TOOL_BINS) $(EXAMPLE_BINS): %.bin : %.o | $(DYNAMIC_NAME) +$(TOOL_BINS): %.bin : %.o | $(DYNAMIC_NAME) + @ echo CXX/LD -o $@ + $(Q)$(CXX) $< -o $@ $(LINKFLAGS) -l$(PROJECT) $(LDFLAGS) \ + -Wl,-rpath,$(ORIGIN)/../lib + +$(EXAMPLE_BINS): %.bin : %.o | $(DYNAMIC_NAME) @ echo CXX/LD -o $@ $(Q)$(CXX) $< -o $@ $(LINKFLAGS) -l$(PROJECT) $(LDFLAGS) \ -Wl,-rpath,$(ORIGIN)/../../lib From 5a2633370f460b6a4d57c7564a38b14311420ab3 Mon Sep 17 00:00:00 2001 From: Evan Shelhamer Date: Fri, 20 Feb 2015 20:29:53 -0800 Subject: [PATCH 10/23] check caffe tool runs in runtest --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 2a75d66e02a..642bde3571d 100644 --- a/Makefile +++ b/Makefile @@ -450,6 +450,7 @@ $(MAT$(PROJECT)_SO): $(MAT$(PROJECT)_SRC) $(STATIC_NAME) CXXLIBS="\$$CXXLIBS $(STATIC_LINK_COMMAND) $(LDFLAGS)" -output $@ runtest: $(TEST_ALL_BIN) + $(TOOL_BUILD_DIR)/caffe $(TEST_ALL_BIN) $(TEST_GPUID) --gtest_shuffle $(TEST_FILTER) pytest: py From a1e951dcf9f534796de9a0f73f4869b3df33ab58 Mon Sep 17 00:00:00 2001 From: Anatoly Baksheev Date: Sun, 22 Feb 2015 18:58:12 +0300 Subject: [PATCH 11/23] ignore pycharm files --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 73bba6cb364..28f2aca854b 100644 --- a/.gitignore +++ b/.gitignore @@ -44,6 +44,9 @@ # QtCreator files *.user +# PyCharm files +.idea + # OSX dir files .DS_Store From fca05c34c67701368245410e6f7c5e118e84a09f Mon Sep 17 00:00:00 2001 From: Anatoly Baksheev Date: Sun, 22 Feb 2015 19:03:47 +0300 Subject: [PATCH 12/23] set proper CMAKE_INSTALL_RPATH for _caffe.so and tools --- cmake/Misc.cmake | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmake/Misc.cmake b/cmake/Misc.cmake index 608a5f13a79..39569eaf996 100644 --- a/cmake/Misc.cmake +++ b/cmake/Misc.cmake @@ -32,6 +32,11 @@ endif() set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE CACHE BOOLEAN "Use link paths for shared library rpath") set(CMAKE_MACOSX_RPATH TRUE) +list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES ${CMAKE_INSTALL_PREFIX}/lib __is_systtem_dir) +if(${__is_systtem_dir} STREQUAL -1) + set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib) +endif() + # ---[ Funny target if(UNIX OR APPLE) add_custom_target(symlink_to_build COMMAND "ln" "-sf" "${PROJECT_BINARY_DIR}" "${PROJECT_SOURCE_DIR}/build" From 645aa03207b24dc5f092686f399736c9334bc096 Mon Sep 17 00:00:00 2001 From: Anatoly Baksheev Date: Sun, 22 Feb 2015 19:04:22 +0300 Subject: [PATCH 13/23] fixed bug in install-tree: _caffe.so installed by install(TARGET ...) was overwritten with symlink created at build time and installed with install(DIRECTORY ...) --- python/CMakeLists.txt | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 6afed4fa183..a2f82089cac 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -4,7 +4,7 @@ if(NOT HAVE_PYTHON) endif() include_directories(${PYTHON_INCLUDE_DIRS} ${NUMPY_INCLUDE_DIR} ${Boost_INCLUDE_DIRS}) -file(GLOB_RECURSE python_srcs ${PROJECT_SOURCE_DIR}/python/*.cpp) +file(GLOB_RECURSE python_srcs ${CMAKE_SOURCE_DIR}/python/*.cpp) add_library(pycaffe SHARED ${python_srcs}) target_link_libraries(pycaffe ${Caffe_LINK} ${PYTHON_LIBRARIES} ${Boost_LIBRARIES}) @@ -22,9 +22,13 @@ if(UNIX OR APPLE) endif() # ---[ Install -file(GLOB files *.py requirements.txt) -install(FILES ${files} DESTINATION python) -install(DIRECTORY caffe DESTINATION python) -install(TARGETS pycaffe DESTINATION python/caffe) +file(GLOB files1 *.py requirements.txt) +install(FILES ${files1} DESTINATION python) + +file(GLOB files2 caffe/*.py) +install(FILES ${files2} DESTINATION python/caffe) +install(TARGETS pycaffe DESTINATION python/caffe) +install(DIRECTORY caffe/imagenet caffe/proto caffe/test DESTINATION python/caffe) + From 5e06d16d14d8a46d3c7a3f82497c6cb1401e160f Mon Sep 17 00:00:00 2001 From: Anatoly Baksheev Date: Sun, 22 Feb 2015 20:14:40 +0300 Subject: [PATCH 14/23] minor cmake sumamry log fix --- cmake/Summary.cmake | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmake/Summary.cmake b/cmake/Summary.cmake index 3f7dff6b6e0..32931942846 100644 --- a/cmake/Summary.cmake +++ b/cmake/Summary.cmake @@ -107,8 +107,9 @@ function(caffe_print_configuration_summary) caffe_status(" C++ compiler : ${CMAKE_CXX_COMPILER}") caffe_status(" Release CXX flags : ${__flags_rel}") caffe_status(" Debug CXX flags : ${__flags_deb}") - caffe_status(" BUILD_SHARED_LIBS : ${BUILD_SHARED_LIBS}") caffe_status(" Build type : ${CMAKE_BUILD_TYPE}") + caffe_status("") + caffe_status(" BUILD_SHARED_LIBS : ${BUILD_SHARED_LIBS}") caffe_status(" BUILD_python : ${BUILD_python}") caffe_status(" BUILD_matlab : ${BUILD_matlab}") caffe_status(" BUILD_docs : ${BUILD_docs}") @@ -116,8 +117,9 @@ function(caffe_print_configuration_summary) caffe_status("") caffe_status("Dependencies:") caffe_status(" BLAS : " APPLE THEN "Yes (vecLib)" ELSE "Yes (${BLAS})") + caffe_status(" Boost : Yes (ver. ${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION})") caffe_status(" glog : Yes") - caffe_status(" gflags : Yes") + caffe_status(" gflags : Yes") caffe_status(" protobuf : " PROTOBUF_FOUND THEN "Yes (ver. ${PROTOBUF_VERSION})" ELSE "No" ) caffe_status(" lmdb : " LMDB_FOUND THEN "Yes (ver. ${LMDB_VERSION})" ELSE "No") caffe_status(" Snappy : " SNAPPY_FOUND THEN "Yes (ver. ${Snappy_VERSION})" ELSE "No" ) From 569ae01cc309fc3e14352479735a137ae53cfb62 Mon Sep 17 00:00:00 2001 From: James Supancic III Date: Sun, 22 Feb 2015 10:16:45 -0800 Subject: [PATCH 15/23] cpp_lint.py fails silently with Python3 (which is the default on some systems). This commit specifies Python2 with which cpp_lint.py works :-) --- scripts/cpp_lint.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/cpp_lint.py b/scripts/cpp_lint.py index 1b7c6c0536c..f750489f4f9 100755 --- a/scripts/cpp_lint.py +++ b/scripts/cpp_lint.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python2 # # Copyright (c) 2009 Google Inc. All rights reserved. # From 845f9eac2b873e6d018ab83d5a32100ab443a35e Mon Sep 17 00:00:00 2001 From: spmallick Date: Mon, 23 Feb 2015 16:13:20 -0800 Subject: [PATCH 16/23] APPLE was misspelled. in Line 27 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index adea37be565..2a48e062eca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ caffe_option(BUILD_docs "Build documentation" ON IF UNIX OR APPLE) include(cmake/Dependencies.cmake) # ---[ Flags -if(UNIX OR APLE) +if(UNIX OR APPLE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall") endif() From 54037d3942647ff3659028e1d7437f2e8f7cf911 Mon Sep 17 00:00:00 2001 From: philkr Date: Tue, 17 Feb 2015 10:50:12 -0800 Subject: [PATCH 17/23] Making python3 work with cmake and the new python wrapper --- CMakeLists.txt | 1 + cmake/Dependencies.cmake | 39 +++++++++++++++++++++++++++++++++------ docs/installation.md | 4 ++-- python/caffe/_caffe.cpp | 4 +++- python/caffe/io.py | 9 ++++++++- python/caffe/pycaffe.py | 5 ++++- python/classify.py | 6 +++--- python/detect.py | 2 +- python/draw_net.py | 2 +- 9 files changed, 56 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index adea37be565..626d5b44459 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,7 @@ caffe_option(CPU_ONLY "Build Caffe wihtout CUDA support" OFF) # TODO: rename to caffe_option(USE_CUDNN "Build Caffe with cuDNN libary support" ON IF NOT CPU_ONLY) caffe_option(BUILD_SHARED_LIBS "Build shared libraries" ON) caffe_option(BUILD_python "Build Python wrapper" ON) +set(python_version "2" CACHE STRING "Specify which python version to use") caffe_option(BUILD_matlab "Build Matlab wrapper" OFF IF UNIX OR APPLE) caffe_option(BUILD_docs "Build documentation" ON IF UNIX OR APPLE) diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake index aa2dcbe1d0d..b1ac96c6777 100644 --- a/cmake/Dependencies.cmake +++ b/cmake/Dependencies.cmake @@ -92,12 +92,39 @@ endif() # ---[ Python if(BUILD_python) - # disable Python 3 search - find_package(PythonInterp 2.7) - find_package(PythonLibs 2.7) - find_package(NumPy 1.7.1) - find_package(Boost 1.46 COMPONENTS python) - + if(NOT "${python_version}" VERSION_LESS "3.0.0") + # use python3 + find_package(PythonInterp 3.0) + find_package(PythonLibs 3.0) + find_package(NumPy 1.7.1) + # Find the matching boost python implementation + set(version ${PYTHONLIBS_VERSION_STRING}) + + STRING( REPLACE "." "" boost_py_version ${version} ) + find_package(Boost 1.46 COMPONENTS "python-py${boost_py_version}") + set(Boost_PYTHON_FOUND ${Boost_PYTHON-PY${boost_py_version}_FOUND}) + + while(NOT "${version}" STREQUAL "" AND NOT Boost_PYTHON_FOUND) + STRING( REGEX REPLACE "([0-9.]+).[0-9]+" "\\1" version ${version} ) + STRING( REGEX MATCHALL "([0-9.]+).[0-9]+" has_more_version ${version} ) + if("${has_more_version}" STREQUAL "") + break() + endif() + + STRING( REPLACE "." "" boost_py_version ${version} ) + find_package(Boost 1.46 COMPONENTS "python-py${boost_py_version}") + set(Boost_PYTHON_FOUND ${Boost_PYTHON-PY${boost_py_version}_FOUND}) + endwhile() + if(NOT Boost_PYTHON_FOUND) + find_package(Boost 1.46 COMPONENTS python) + endif() + else() + # disable Python 3 search + find_package(PythonInterp 2.7) + find_package(PythonLibs 2.7) + find_package(NumPy 1.7.1) + find_package(Boost 1.46 COMPONENTS python) + endif() if(PYTHONLIBS_FOUND AND NUMPY_FOUND AND Boost_PYTHON_FOUND) set(HAVE_PYTHON TRUE) endif() diff --git a/docs/installation.md b/docs/installation.md index 16575b54029..144e6a34f67 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -30,7 +30,7 @@ Caffe has several dependencies. Pycaffe and Matcaffe interfaces have their own natural needs. -* For Python Caffe: `Python 2.7`, `numpy (>= 1.7)`, boost-provided `boost.python` +* For Python Caffe: `Python 2.7` or `Python 3.3+`, `numpy (>= 1.7)`, boost-provided `boost.python` * For MATLAB Caffe: MATLAB with the `mex` compiler. **cuDNN Caffe**: for fastest operation Caffe is accelerated by drop-in integration of [NVIDIA cuDNN](https://developer.nvidia.com/cudnn). To speed up your Caffe models, install cuDNN then uncomment the `USE_CUDNN := 1` flag in `Makefile.config` when installing Caffe. Acceleration is automatic. For now cuDNN v1 is integrated but see [PR #1731](https://github.com/BVLC/caffe/pull/1731) for v2. @@ -69,7 +69,7 @@ but we suggest first installing the [Anaconda](https://store.continuum.io/cshop/ To import the `caffe` Python module after completing the installation, add the module directory to your `$PYTHONPATH` by `export PYTHONPATH=/path/to/caffe/python:$PYTHONPATH` or the like. You should not import the module in the `caffe/python/caffe` directory! -*Caffe's Python interface works with Python 2.7. Python 3 or earlier Pythons are your own adventure.* +*Caffe's Python interface works with Python 2.7. Python 3.3+ should work out of the box without protobuf support. For protobuf support please install protobuf 3.0 alpha (https://developers.google.com/protocol-buffers/). Earlier Pythons are your own adventure.* #### MATLAB diff --git a/python/caffe/_caffe.cpp b/python/caffe/_caffe.cpp index a5d0e64605e..03967a21029 100644 --- a/python/caffe/_caffe.cpp +++ b/python/caffe/_caffe.cpp @@ -275,7 +275,9 @@ BOOST_PYTHON_MODULE(_caffe) { bp::class_ >("BoolVec") .def(bp::vector_indexing_suite >()); - import_array(); + // boost python expects a void (missing) return value, while import_array + // returns NULL for python3. import_array1() forces a void return value. + import_array1(); } } // namespace caffe diff --git a/python/caffe/io.py b/python/caffe/io.py index 0ce9ecfeeed..f51e3a64d36 100644 --- a/python/caffe/io.py +++ b/python/caffe/io.py @@ -3,7 +3,14 @@ from scipy.ndimage import zoom from skimage.transform import resize -from caffe.proto import caffe_pb2 +try: + # Python3 will most likely not be able to load protobuf + from caffe.proto import caffe_pb2 +except: + if sys.version_info >= (3,0): + print("Failed to include caffe_pb2, things might go wrong!") + else: + raise ## proto / datum / ndarray conversion diff --git a/python/caffe/pycaffe.py b/python/caffe/pycaffe.py index 31c145d77a5..d662d6cc282 100644 --- a/python/caffe/pycaffe.py +++ b/python/caffe/pycaffe.py @@ -4,7 +4,10 @@ """ from collections import OrderedDict -from itertools import izip_longest +try: + from itertools import izip_longest +except: + from itertools import zip_longest as izip_longest import numpy as np from ._caffe import Net, SGDSolver diff --git a/python/classify.py b/python/classify.py index d435a572266..81d06369341 100755 --- a/python/classify.py +++ b/python/classify.py @@ -103,7 +103,7 @@ def main(argv): channel_swap=channel_swap) if args.gpu: - print 'GPU mode' + print('GPU mode') # Load numpy array (.npy), directory glob (*.jpg), or image file. args.input_file = os.path.expanduser(args.input_file) @@ -115,12 +115,12 @@ def main(argv): else: inputs = [caffe.io.load_image(args.input_file)] - print "Classifying %d inputs." % len(inputs) + print("Classifying %d inputs." % len(inputs)) # Classify. start = time.time() predictions = classifier.predict(inputs, not args.center_only) - print "Done in %.2f s." % (time.time() - start) + print("Done in %.2f s." % (time.time() - start)) # Save np.save(args.output_file, predictions) diff --git a/python/detect.py b/python/detect.py index cb0c2645761..d395bd97abf 100755 --- a/python/detect.py +++ b/python/detect.py @@ -115,7 +115,7 @@ def main(argv): context_pad=args.context_pad) if args.gpu: - print 'GPU mode' + print('GPU mode') # Load input. t = time.time() diff --git a/python/draw_net.py b/python/draw_net.py index 4457b793e86..6320f775ef7 100755 --- a/python/draw_net.py +++ b/python/draw_net.py @@ -36,7 +36,7 @@ def main(): args = parse_args() net = caffe_pb2.NetParameter() text_format.Merge(open(args.input_net_proto_file).read(), net) - print 'Drawing net to %s' % args.output_image_file + print('Drawing net to %s' % args.output_image_file) caffe.draw.draw_net_to_file(net, args.output_image_file, args.rankdir) From 2cf5089d273e0e46f51c1b4b7aa018cbf3b983fe Mon Sep 17 00:00:00 2001 From: philkr Date: Tue, 24 Feb 2015 16:02:06 -0800 Subject: [PATCH 18/23] Decoding the datum before feeding it into the reshaping data layer --- src/caffe/layers/data_layer.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/caffe/layers/data_layer.cpp b/src/caffe/layers/data_layer.cpp index 8877caf89c8..1861090f953 100644 --- a/src/caffe/layers/data_layer.cpp +++ b/src/caffe/layers/data_layer.cpp @@ -89,9 +89,17 @@ void DataLayer::InternalThreadEntry() { // Reshape on single input batches for inputs of varying dimension. const int batch_size = this->layer_param_.data_param().batch_size(); const int crop_size = this->layer_param_.transform_param().crop_size(); + bool force_color = this->layer_param_.data_param().force_encoded_color(); if (batch_size == 1 && crop_size == 0) { Datum datum; datum.ParseFromString(cursor_->value()); + if (datum.encoded()) { + if (force_color) { + DecodeDatum(&datum, true); + } else { + DecodeDatumNative(&datum); + } + } this->prefetch_data_.Reshape(1, datum.channels(), datum.height(), datum.width()); this->transformed_data_.Reshape(1, datum.channels(), @@ -104,7 +112,6 @@ void DataLayer::InternalThreadEntry() { if (this->output_labels_) { top_label = this->prefetch_label_.mutable_cpu_data(); } - bool force_color = this->layer_param_.data_param().force_encoded_color(); for (int item_id = 0; item_id < batch_size; ++item_id) { timer.Start(); // get a blob From 4a3887ab1791f7a0ea6d17cafb861f53398a42d5 Mon Sep 17 00:00:00 2001 From: forresti Date: Tue, 24 Feb 2015 16:51:56 -0800 Subject: [PATCH 19/23] fixed matcaffe printout to specify num of args (now including train/test phase) --- matlab/caffe/matcaffe.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/caffe/matcaffe.cpp b/matlab/caffe/matcaffe.cpp index 996d3d2149c..da37d920b20 100644 --- a/matlab/caffe/matcaffe.cpp +++ b/matlab/caffe/matcaffe.cpp @@ -272,7 +272,7 @@ static void get_init_key(MEX_ARGS) { static void init(MEX_ARGS) { if (nrhs != 3) { ostringstream error_msg; - error_msg << "Expected 2 arguments, got " << nrhs; + error_msg << "Expected 3 arguments, got " << nrhs; mex_error(error_msg.str()); } From d2beb8ab20b55aebd25a2fb1f3eed3cf2923efaa Mon Sep 17 00:00:00 2001 From: Gustav Larsson Date: Tue, 24 Feb 2015 23:22:15 -0600 Subject: [PATCH 20/23] Replaced illegal tab in Makefile with spaces. Commands, such as $(error ...), are not allowed to be indented with tabs outside of targets, throwing an error instead of outputting the actual error. The solution is to use innocuous spaces instead. Ideally, spaces should be used everywhere outside targets, but since make does not mind it if variable assignments are tab-indented outside targets, a complete overhaul is not necessary. However, if more errors are added, it might make more sense to be consistent. Also, make will already add a period so I removed it. --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 642bde3571d..033473ac45b 100644 --- a/Makefile +++ b/Makefile @@ -261,7 +261,8 @@ ifneq (,$(findstring clang++,$(CXX))) else ifneq (,$(findstring g++,$(CXX))) STATIC_LINK_COMMAND := -Wl,--whole-archive $(STATIC_NAME) -Wl,--no-whole-archive else - $(error Cannot static link with the $(CXX) compiler.) + # The following line must not be indented with a tab, since we are not inside a target + $(error Cannot static link with the $(CXX) compiler) endif # Debugging From 1377e1be4ee70e9f57f8cef53d767603124ee84f Mon Sep 17 00:00:00 2001 From: Sergey Karayev Date: Tue, 24 Feb 2015 21:52:32 -0800 Subject: [PATCH 21/23] Makefile fix for OS X 10.10 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 642bde3571d..933e9be93f3 100644 --- a/Makefile +++ b/Makefile @@ -319,7 +319,7 @@ else # 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/ + BLAS_INCLUDE ?= /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/ From 25cdd35c9ab1447f06040720243526fc8d0343c5 Mon Sep 17 00:00:00 2001 From: Andre Ambrosio Boechat Date: Wed, 25 Feb 2015 14:56:18 -0300 Subject: [PATCH 22/23] Small fix (visualization) on SLICE layer's documentation The sample was missing some additional spaces to be correctly rendered on the HTML. The mistake was mine. --- docs/tutorial/layers.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/docs/tutorial/layers.md b/docs/tutorial/layers.md index 34bb48050e8..839939f5ad6 100644 --- a/docs/tutorial/layers.md +++ b/docs/tutorial/layers.md @@ -453,20 +453,20 @@ The `SLICE` layer is a utility layer that slices an input layer to multiple outp * Sample - layers { - name: "slicer_label" - type: SLICE - bottom: "label" - ## Example of label with a shape N x 3 x 1 x 1 - top: "label1" - top: "label2" - top: "label3" - slice_param { - slice_dim: 1 - slice_point: 1 - slice_point: 2 - } - } + layers { + name: "slicer_label" + type: SLICE + bottom: "label" + ## Example of label with a shape N x 3 x 1 x 1 + top: "label1" + top: "label2" + top: "label3" + slice_param { + slice_dim: 1 + slice_point: 1 + slice_point: 2 + } + } `slice_dim` indicates the target dimension and can assume only two values: 0 for num or 1 for channel; `slice_point` indicates indexes in the selected dimension (the number of indexes must be equal to the number of top blobs minus one). From 1dcfc3ce220f4fa80e27ffdd7cc0b3223c84c75e Mon Sep 17 00:00:00 2001 From: Evan Shelhamer Date: Wed, 15 Oct 2014 17:04:21 -0700 Subject: [PATCH 23/23] share columnation buffers for convolution to save memory share the im2col / col2im buffers among convolution + deconvolution layers by making the buffer a static member. @longjon deserves all the credit for the reshaping #594 and this patch. --- include/caffe/vision_layers.hpp | 2 +- src/caffe/layers/base_conv_layer.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/caffe/vision_layers.hpp b/include/caffe/vision_layers.hpp index 6cb507a5780..9cc23d1ff42 100644 --- a/include/caffe/vision_layers.hpp +++ b/include/caffe/vision_layers.hpp @@ -107,7 +107,7 @@ class BaseConvolutionLayer : public Layer { int col_offset_; int output_offset_; - Blob col_buffer_; + static Blob col_buffer_; Blob bias_multiplier_; }; diff --git a/src/caffe/layers/base_conv_layer.cpp b/src/caffe/layers/base_conv_layer.cpp index dccd5170c11..a454d42cbb3 100644 --- a/src/caffe/layers/base_conv_layer.cpp +++ b/src/caffe/layers/base_conv_layer.cpp @@ -8,6 +8,9 @@ namespace caffe { +template +Blob BaseConvolutionLayer::col_buffer_; + template void BaseConvolutionLayer::LayerSetUp(const vector*>& bottom, const vector*>& top) {