Skip to content

Commit

Permalink
Clean up old matcaffe wrapper and rename caffe.reset to caffe.reset_all
Browse files Browse the repository at this point in the history
Remove old matlab wrapper but keep the classification demo and hdf5 demo

Change 'caffe.reset()' to 'caffe.reset_all()' to avoid potential name conflict.
Otherwise, Matlab R2015a complains:
Warning: Function reset has the same name as a MATLAB builtin. We suggest you rename the
function to avoid a potential name conflict.
  • Loading branch information
ronghanghu committed May 29, 2015
1 parent 6af8efc commit d3d7d07
Show file tree
Hide file tree
Showing 19 changed files with 63 additions and 905 deletions.
25 changes: 4 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ NONGEN_CXX_SRCS := $(shell find \
src/$(PROJECT) \
include/$(PROJECT) \
python/$(PROJECT) \
matlab/$(PROJECT) \
matlab/+$(PROJECT)/private \
examples \
tools \
Expand All @@ -80,15 +79,12 @@ NONEMPTY_LINT_REPORT := $(BUILD_DIR)/$(LINT_EXT)
PY$(PROJECT)_SRC := python/$(PROJECT)/_$(PROJECT).cpp
PY$(PROJECT)_SO := python/$(PROJECT)/_$(PROJECT).so
PY$(PROJECT)_HXX := include/$(PROJECT)/python_layer.hpp
# MAT$(PROJECT)_SRC is the matlab wrapper for $(PROJECT)
MAT$(PROJECT)_SRC := matlab/$(PROJECT)/mat$(PROJECT).cpp
# MAT$(PROJECT)_PKG_SRC is the mex entrance point of matlab package for $(PROJECT)
MAT$(PROJECT)_PKG_SRC := matlab/+$(PROJECT)/private/$(PROJECT)_.cpp
# MAT$(PROJECT)_SRC is the mex entrance point of matlab package for $(PROJECT)
MAT$(PROJECT)_SRC := matlab/+$(PROJECT)/private/$(PROJECT)_.cpp
ifneq ($(MATLAB_DIR),)
MAT_SO_EXT := $(shell $(MATLAB_DIR)/bin/mexext)
endif
MAT$(PROJECT)_SO := matlab/$(PROJECT)/$(PROJECT).$(MAT_SO_EXT)
MAT$(PROJECT)_PKG_SO := matlab/+$(PROJECT)/private/$(PROJECT)_.$(MAT_SO_EXT)
MAT$(PROJECT)_SO := matlab/+$(PROJECT)/private/$(PROJECT)_.$(MAT_SO_EXT)

##############################
# Derive generated files
Expand Down Expand Up @@ -451,7 +447,7 @@ $(PY$(PROJECT)_SO): $(PY$(PROJECT)_SRC) $(PY$(PROJECT)_HXX) | $(DYNAMIC_NAME)

mat$(PROJECT): mat

mat: $(MAT$(PROJECT)_SO) $(MAT$(PROJECT)_PKG_SO)
mat: $(MAT$(PROJECT)_SO)

$(MAT$(PROJECT)_SO): $(MAT$(PROJECT)_SRC) $(STATIC_NAME)
@ if [ -z "$(MATLAB_DIR)" ]; then \
Expand All @@ -464,18 +460,6 @@ $(MAT$(PROJECT)_SO): $(MAT$(PROJECT)_SRC) $(STATIC_NAME)
CXX="$(CXX)" \
CXXFLAGS="\$$CXXFLAGS $(MATLAB_CXXFLAGS)" \
CXXLIBS="\$$CXXLIBS $(STATIC_LINK_COMMAND) $(LDFLAGS)" -output $@

$(MAT$(PROJECT)_PKG_SO): $(MAT$(PROJECT)_PKG_SRC) $(STATIC_NAME)
@ if [ -z "$(MATLAB_DIR)" ]; then \
echo "MATLAB_DIR must be specified in $(CONFIG_FILE)" \
"to build mat$(PROJECT)."; \
exit 1; \
fi
@ echo MEX $<
$(Q)$(MATLAB_DIR)/bin/mex $(MAT$(PROJECT)_PKG_SRC) \
CXX="$(CXX)" \
CXXFLAGS="\$$CXXFLAGS $(MATLAB_CXXFLAGS)" \
CXXLIBS="\$$CXXLIBS $(STATIC_LINK_COMMAND) $(LDFLAGS)" -output $@

runtest: $(TEST_ALL_BIN)
$(TOOL_BUILD_DIR)/caffe
Expand Down Expand Up @@ -601,7 +585,6 @@ clean:
@- $(RM) -rf $(DISTRIBUTE_DIR)
@- $(RM) $(PY$(PROJECT)_SO)
@- $(RM) $(MAT$(PROJECT)_SO)
@- $(RM) $(MAT$(PROJECT)_PKG_SO)

supercleanfiles:
$(eval SUPERCLEAN_FILES := $(strip \
Expand Down
8 changes: 4 additions & 4 deletions docs/tutorial/interfaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Compile pycaffe by `make pycaffe`. The module dir caffe/python/caffe should be i

## MATLAB

The MATLAB interface -- matcaffe -- is a `caffe` package in caffe/matlab in which you can integrate Caffe in your Matlab code.
The MATLAB interface -- matcaffe -- is the `caffe` package in caffe/matlab in which you can integrate Caffe in your Matlab code.

In MatCaffe, you can

Expand All @@ -84,7 +84,7 @@ In MatCaffe, you can
* Run for a certain number of iterations and give back control to Matlab
* Intermingle arbitrary Matlab code to with gradient steps

A MATLAB demo is in caffe/matlab/matcaffe_demo.m
An ILSVRC image classification demo is in caffe/matlab/classification_demo.m

### Build MatCaffe

Expand Down Expand Up @@ -181,7 +181,7 @@ To get a layer's type (string):

#### Forward and backward

Forward pass can be done using `net.forward` or `net.forward_prefilled`. After creating some data for input blobs like `data = rand(net.blobs('data').shape);` you can run
Forward pass can be done using `net.forward` or `net.forward_prefilled`. Function `net.forward` takes in a cell array of N-D arrays containing data of input blob(s) and outputs a cell array containing data from output blob(s). Function `net.forward_prefilled` uses existing data in input blob(s) during forward pass, takes no input and produces no output. After creating some data for input blobs like `data = rand(net.blobs('data').shape);` you can run

res = net.forward({data});
prob = res{1};
Expand Down Expand Up @@ -274,4 +274,4 @@ We do not provide extra functions for data output as Matlab itself is already qu

#### Clear nets and solvers

Call `caffe.reset()` to clear all solvers and stand-alone nets you have created.
Call `caffe.reset_all()` to clear all solvers and stand-alone nets you have created.
File renamed without changes.
8 changes: 0 additions & 8 deletions matlab/+caffe/reset.m

This file was deleted.

8 changes: 8 additions & 0 deletions matlab/+caffe/reset_all.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function reset_all()
% reset_all()
% clear all solvers and stand-alone nets and reset Caffe to initial status

caffe_('reset');
is_valid_handle('get_new_init_key');

end
4 changes: 2 additions & 2 deletions matlab/+caffe/run_tests.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
% run all tests in this caffe matlab wrapper package

% reset caffe before testing
caffe.reset();
caffe.reset_all();

% put all test cases here
results = [...
run(caffe.test.test_net) ...
run(caffe.test.test_solver) ];

% reset caffe after testing
caffe.reset();
caffe.reset_all();

end
12 changes: 2 additions & 10 deletions matlab/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ function(caffe_fetch_and_set_proper_mexext mexfile_variable)
endfunction()

# global settings
file(GLOB Matlab_srcs caffe/matcaffe.cpp)
file(GLOB Matlab_pkg_srcs +caffe/private/caffe_.cpp)
set(Matlab_caffe_mex ${PROJECT_SOURCE_DIR}/matlab/caffe/caffe.mex)
set(Matlab_caffe_pkg_mex ${PROJECT_SOURCE_DIR}/matlab/+caffe/private/caffe_.mex)
file(GLOB Matlab_srcs +caffe/private/caffe_.cpp)
set(Matlab_caffe_mex ${PROJECT_SOURCE_DIR}/matlab/+caffe/private/caffe_.mex)

caffe_get_current_cflags(cflags)
caffe_parse_linker_libs(Caffe_LINKER_LIBS folders libflags macos_frameworks)
Expand All @@ -52,15 +50,9 @@ if(build_using MATCHES "Matlab")
ARGS -output ${Matlab_caffe_mex} ${Matlab_srcs} ${cflags} ${link_folders} ${libflags}
DEPENDS caffe COMMENT "Building Matlab interface: ${Matlab_caffe_mex}" VERBATIM)
add_custom_target(matlab ALL DEPENDS ${Matlab_caffe_mex} SOURCES ${Matlab_srcs})
caffe_fetch_and_set_proper_mexext(Matlab_caffe_pkg_mex)
add_custom_command(OUTPUT ${Matlab_caffe_pkg_mex} COMMAND ${Matlab_mex}
ARGS -output ${Matlab_caffe_pkg_mex} ${Matlab_pkg_srcs} ${cflags} ${link_folders} ${libflags}
DEPENDS caffe COMMENT "Building Matlab interface: ${Matlab_caffe_pkg_mex}" VERBATIM)
add_custom_target(matlab ALL DEPENDS ${Matlab_caffe_pkg_mex} SOURCES ${Matlab_pkg_srcs})

elseif(build_using MATCHES "Octave")

# Note: Matlab Caffe package cannot be used in Octave, so we don't build it
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(libflags -Wl,-force_load,$<TARGET_LINKER_FILE:caffe> ${libflags})
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
Expand Down
Loading

0 comments on commit d3d7d07

Please sign in to comment.