Reorganization of codes.
authorYangqing Jia <jiayq84@gmail.com>
Tue, 15 Oct 2013 21:35:14 +0000 (14:35 -0700)
committerYangqing Jia <jiayq84@gmail.com>
Tue, 15 Oct 2013 21:38:28 +0000 (14:38 -0700)
23 files changed:
Makefile [moved from src/Makefile with 62% similarity]
caffe.cloc [moved from src/caffe.cloc with 100% similarity]
examples/demo_mnist.cpp [moved from src/programs/demo_mnist.cpp with 98% similarity]
examples/dump_network.cpp [moved from src/programs/dump_network.cpp with 98% similarity]
examples/imagenet.prototxt [moved from src/programs/imagenet.prototxt with 100% similarity]
examples/imagenet_solver.prototxt [moved from src/programs/imagenet_solver.prototxt with 100% similarity]
examples/net_speed_benchmark.cpp [moved from src/programs/net_speed_benchmark.cpp with 97% similarity]
examples/test_read_imagenet.cpp [moved from src/programs/test_read_imagenet.cpp with 100% similarity]
examples/train_net.cpp [moved from src/programs/train_net.cpp with 96% similarity]
include/caffe/blob.hpp [moved from src/caffe/blob.hpp with 100% similarity]
include/caffe/caffe.hpp [moved from src/caffe/caffe.hpp with 100% similarity]
include/caffe/common.hpp [moved from src/caffe/common.hpp with 100% similarity]
include/caffe/filler.hpp [moved from src/caffe/filler.hpp with 100% similarity]
include/caffe/layer.hpp [moved from src/caffe/layer.hpp with 100% similarity]
include/caffe/net.hpp [moved from src/caffe/net.hpp with 100% similarity]
include/caffe/solver.hpp [moved from src/caffe/optimization/solver.hpp with 100% similarity]
include/caffe/syncedmem.hpp [moved from src/caffe/syncedmem.hpp with 100% similarity]
include/caffe/util/im2col.hpp [moved from src/caffe/util/im2col.hpp with 100% similarity]
include/caffe/util/io.hpp [moved from src/caffe/util/io.hpp with 100% similarity]
include/caffe/util/math_functions.hpp [moved from src/caffe/util/math_functions.hpp with 100% similarity]
include/caffe/vision_layers.hpp [moved from src/caffe/vision_layers.hpp with 100% similarity]
src/caffe/solver.cpp [moved from src/caffe/optimization/solver.cpp with 99% similarity]
src/caffe/test/test_solver_linear_regression.cpp [deleted file]

similarity index 62%
rename from src/Makefile
rename to Makefile
index 60aa139e2bb4ff8c250bbf4f82189fbbac52a05d..7b28bfba0e67b6583e26d5f2135e47baa1a53b69 100644 (file)
+++ b/Makefile
@@ -6,12 +6,12 @@ TEST_GPUID := 1
 NAME := lib$(PROJECT).so
 STATIC_NAME := lib$(PROJECT).a
 # All source files
-CXX_SRCS := $(shell find caffe ! -name "test_*.cpp" -name "*.cpp")
-CU_SRCS := $(shell find caffe -name "*.cu")
-TEST_SRCS := $(shell find caffe -name "test_*.cpp")
-GTEST_SRC := gtest/gtest-all.cpp
-PROGRAM_SRCS := $(shell find programs -name "*.cpp")
-PROTO_SRCS := $(wildcard caffe/proto/*.proto)
+CXX_SRCS := $(shell find src/caffe ! -name "test_*.cpp" -name "*.cpp")
+CU_SRCS := $(shell find src/caffe -name "*.cu")
+TEST_SRCS := $(shell find src/caffe -name "test_*.cpp")
+GTEST_SRC := src/gtest/gtest-all.cpp
+EXAMPLE_SRCS := $(shell find examples -name "*.cpp")
+PROTO_SRCS := $(wildcard src/caffe/proto/*.proto)
 # The generated files for protocol buffers
 PROTO_GEN_HEADER := ${PROTO_SRCS:.proto=.pb.h}
 PROTO_GEN_CC := ${PROTO_SRCS:.proto=.pb.cc}
@@ -22,11 +22,11 @@ CU_OBJS := ${CU_SRCS:.cu=.cuo}
 PROTO_OBJS := ${PROTO_GEN_CC:.cc=.o}
 OBJS := $(PROTO_OBJS) $(CXX_OBJS) $(CU_OBJS)
 # program and test objects
-PROGRAM_OBJS := ${PROGRAM_SRCS:.cpp=.o}
+EXAMPLE_OBJS := ${EXAMPLE_SRCS:.cpp=.o}
 TEST_OBJS := ${TEST_SRCS:.cpp=.o}
 GTEST_OBJ := ${GTEST_SRC:.cpp=.o}
 # program and test bins
-PROGRAM_BINS :=${PROGRAM_OBJS:.o=.bin}
+EXAMPLE_BINS :=${EXAMPLE_OBJS:.o=.bin}
 TEST_BINS := ${TEST_OBJS:.o=.testbin}
 
 # define third-party library paths
@@ -40,10 +40,11 @@ MKL_INCLUDE_DIR := $(MKL_DIR)/include
 MKL_LIB_DIR := $(MKL_DIR)/lib $(MKL_DIR)/lib/intel64
 
 # define inclue and libaries
-INCLUDE_DIRS := . /usr/local/include $(CUDA_INCLUDE_DIR) $(MKL_INCLUDE_DIR)
-LIBRARY_DIRS := . /usr/lib /usr/local/lib $(CUDA_LIB_DIR) $(MKL_LIB_DIR)
+# We put src here just for gtest
+INCLUDE_DIRS := ./src ./include /usr/local/include $(CUDA_INCLUDE_DIR) $(MKL_INCLUDE_DIR)
+LIBRARY_DIRS := /usr/lib /usr/local/lib $(CUDA_LIB_DIR) $(MKL_LIB_DIR)
 LIBRARIES := cuda cudart cublas protobuf glog mkl_rt mkl_intel_thread curand \
-               leveldb snappy pthread tcmalloc
+               leveldb snappy pthread
 WARNINGS := -Wall
 
 COMMON_FLAGS := $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir))
@@ -54,16 +55,16 @@ LDFLAGS += $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) \
 
 NVCC = nvcc $(NVCCFLAGS) $(CPPFLAGS) $(CUDA_ARCH)
 
-.PHONY: all test clean distclean linecount program
+.PHONY: all test clean distclean linecount examples distribute
 
-all: $(NAME) $(STATIC_NAME) test program
+all: $(NAME) $(STATIC_NAME) test examples
 
 linecount: clean
-       cloc --read-lang-def=caffe.cloc caffe/
+       cloc --read-lang-def=caffe.cloc src/caffe/
 
 test: $(TEST_BINS)
 
-program: $(PROGRAM_BINS)
+examples: $(EXAMPLE_BINS)
 
 $(NAME): $(PROTO_OBJS) $(OBJS)
        $(CXX) -shared $(OBJS) -o $(NAME) $(LDFLAGS) $(WARNINGS)
@@ -77,22 +78,34 @@ runtest: test
 $(TEST_BINS): %.testbin : %.o $(GTEST_OBJ) $(STATIC_NAME)
        $(CXX) $< $(GTEST_OBJ) $(STATIC_NAME) -o $@ $(LDFLAGS) $(WARNINGS)
 
-$(PROGRAM_BINS): %.bin : %.o $(STATIC_NAME)
+$(EXAMPLE_BINS): %.bin : %.o $(STATIC_NAME)
        $(CXX) $< $(STATIC_NAME) -o $@ $(LDFLAGS) $(WARNINGS)
 
 $(OBJS): $(PROTO_GEN_CC)
 
-$(PROGRAM_OBJS): $(PROTO_GEN_CC)
+$(EXAMPLE_OBJS): $(PROTO_GEN_CC)
 
 $(CU_OBJS): %.cuo: %.cu
        $(NVCC) -c $< -o $@
 
 $(PROTO_GEN_CC): $(PROTO_SRCS)
-       protoc $(PROTO_SRCS) --cpp_out=. --python_out=.
+       protoc --proto_path=src --cpp_out=src --python_out=src $(PROTO_SRCS)
+       mkdir -p include/caffe/proto
+       cp $(PROTO_GEN_HEADER) include/caffe/proto/
 
 clean:
-       @- $(RM) $(NAME) $(STATIC_NAME) $(TEST_BINS) $(PROGRAM_BINS)
-       @- $(RM) $(OBJS) $(TEST_OBJS) $(PROGRAM_OBJS)
+       @- $(RM) $(NAME) $(STATIC_NAME) $(TEST_BINS) $(EXAMPLE_BINS)
+       @- $(RM) $(OBJS) $(TEST_OBJS) $(EXAMPLE_OBJS)
        @- $(RM) $(PROTO_GEN_HEADER) $(PROTO_GEN_CC) $(PROTO_GEN_PY)
+       @- $(RM) -rf build
 
 distclean: clean
+
+distribute: all
+       mkdir build
+       cp -r include build/
+       mkdir build/bin
+       cp $(EXAMPLE_BINS) build/bin
+       mkdir build/lib
+       cp $(NAME) build/lib
+       cp $(STATIC_NAME) build/lib
similarity index 100%
rename from src/caffe.cloc
rename to caffe.cloc
similarity index 98%
rename from src/programs/demo_mnist.cpp
rename to examples/demo_mnist.cpp
index 284b671fd54e85522fd9b8a6c8f112fcacf83533..c513a6aaebca9571a486ef7bdd8f9134c71e1cf7 100644 (file)
@@ -12,7 +12,7 @@
 #include "caffe/filler.hpp"
 #include "caffe/proto/caffe.pb.h"
 #include "caffe/util/io.hpp"
-#include "caffe/optimization/solver.hpp"
+#include "caffe/solver.hpp"
 
 using namespace caffe;
 
similarity index 98%
rename from src/programs/dump_network.cpp
rename to examples/dump_network.cpp
index 8dd8b0df337e9048fc327e6b5f55ae01afaac82b..1fb8115a7deec3657f65fb819873b55ef978f935 100644 (file)
@@ -21,7 +21,7 @@
 #include "caffe/filler.hpp"
 #include "caffe/proto/caffe.pb.h"
 #include "caffe/util/io.hpp"
-#include "caffe/optimization/solver.hpp"
+#include "caffe/solver.hpp"
 
 using namespace caffe;
 
similarity index 97%
rename from src/programs/net_speed_benchmark.cpp
rename to examples/net_speed_benchmark.cpp
index 560c5d87bbf62dbe3cf28141ed529f150ae4ef3c..97e8223b9753be8d2dd795664193dd276d2b7cef 100644 (file)
@@ -13,7 +13,7 @@
 #include "caffe/filler.hpp"
 #include "caffe/proto/caffe.pb.h"
 #include "caffe/util/io.hpp"
-#include "caffe/optimization/solver.hpp"
+#include "caffe/solver.hpp"
 
 using namespace caffe;
 
similarity index 96%
rename from src/programs/train_net.cpp
rename to examples/train_net.cpp
index 15f431517324157a4d1acd81d977f44f0b92f19c..ec88b6f5c4559c884f8ee28a198908fa99a5377c 100644 (file)
@@ -15,7 +15,7 @@
 #include "caffe/filler.hpp"
 #include "caffe/proto/caffe.pb.h"
 #include "caffe/util/io.hpp"
-#include "caffe/optimization/solver.hpp"
+#include "caffe/solver.hpp"
 
 using namespace caffe;
 
similarity index 100%
rename from src/caffe/blob.hpp
rename to include/caffe/blob.hpp
similarity index 100%
rename from src/caffe/caffe.hpp
rename to include/caffe/caffe.hpp
similarity index 100%
rename from src/caffe/layer.hpp
rename to include/caffe/layer.hpp
similarity index 100%
rename from src/caffe/net.hpp
rename to include/caffe/net.hpp
similarity index 99%
rename from src/caffe/optimization/solver.cpp
rename to src/caffe/solver.cpp
index 0c68330e05f39d0d86d91904cfba88d36bdfc6e4..425bd421e082e4e62fde685d207c339b366f9e5b 100644 (file)
@@ -8,7 +8,7 @@
 
 #include "caffe/net.hpp"
 #include "caffe/proto/caffe.pb.h"
-#include "caffe/optimization/solver.hpp"
+#include "caffe/solver.hpp"
 #include "caffe/util/io.hpp"
 #include "caffe/util/math_functions.hpp"
 
diff --git a/src/caffe/test/test_solver_linear_regression.cpp b/src/caffe/test/test_solver_linear_regression.cpp
deleted file mode 100644 (file)
index 8fd504b..0000000
+++ /dev/null
@@ -1,125 +0,0 @@
-// Copyright 2013 Yangqing Jia
-
-#include <cuda_runtime.h>
-#include <fcntl.h>
-#include <google/protobuf/text_format.h>
-#include <google/protobuf/io/zero_copy_stream_impl.h>
-#include <gtest/gtest.h>
-
-#include <cstring>
-
-#include "caffe/blob.hpp"
-#include "caffe/common.hpp"
-#include "caffe/net.hpp"
-#include "caffe/filler.hpp"
-#include "caffe/proto/caffe.pb.h"
-#include "caffe/util/io.hpp"
-#include "caffe/optimization/solver.hpp"
-
-#include "caffe/test/test_caffe_main.hpp"
-
-namespace caffe {
-
-template <typename Dtype>
-class SolverTest : public ::testing::Test {};
-
-typedef ::testing::Types<float, double> Dtypes;
-TYPED_TEST_CASE(SolverTest, Dtypes);
-
-TYPED_TEST(SolverTest, TestSolveGPU) {
-  Caffe::set_mode(Caffe::GPU);
-
-  NetParameter net_param;
-  ReadProtoFromTextFile("data/linear_regression.prototxt",
-      &net_param);
-  // check if things are right
-  EXPECT_EQ(net_param.layers_size(), 3);
-  EXPECT_EQ(net_param.input_size(), 0);
-  vector<Blob<TypeParam>*> bottom_vec;
-  Net<TypeParam> caffe_net(net_param, bottom_vec);
-  EXPECT_EQ(caffe_net.layer_names().size(), 3);
-  EXPECT_EQ(caffe_net.blob_names().size(), 3);
-
-  // Run the network without training.
-  LOG(INFO) << "Performing Forward";
-  caffe_net.Forward(bottom_vec);
-  LOG(INFO) << "Performing Backward";
-  LOG(INFO) << "Initial loss: " << caffe_net.Backward();
-
-  SolverParameter solver_param;
-  solver_param.set_base_lr(0.1);
-  solver_param.set_display(0);
-  solver_param.set_max_iter(100);
-  solver_param.set_lr_policy("inv");
-  solver_param.set_gamma(1.);
-  solver_param.set_power(0.75);
-  solver_param.set_momentum(0.9);
-
-  LOG(INFO) << "Starting Optimization";
-  SGDSolver<TypeParam> solver(solver_param);
-  solver.Solve(&caffe_net);
-  LOG(INFO) << "Optimization Done.";
-  LOG(INFO) << "Weight: " << caffe_net.params()[0]->cpu_data()[0] << ", "
-      << caffe_net.params()[0]->cpu_data()[1];
-  LOG(INFO) << "Bias: " << caffe_net.params()[1]->cpu_data()[0];
-
-  EXPECT_GE(caffe_net.params()[0]->cpu_data()[0], 0.3);
-  EXPECT_LE(caffe_net.params()[0]->cpu_data()[0], 0.35);
-
-  EXPECT_GE(caffe_net.params()[0]->cpu_data()[1], 0.3);
-  EXPECT_LE(caffe_net.params()[0]->cpu_data()[1], 0.35);
-
-  EXPECT_GE(caffe_net.params()[1]->cpu_data()[0], -0.01);
-  EXPECT_LE(caffe_net.params()[1]->cpu_data()[0], 0.01);
-}
-
-
-
-TYPED_TEST(SolverTest, TestSolveCPU) {
-  Caffe::set_mode(Caffe::CPU);
-
-  NetParameter net_param;
-  ReadProtoFromTextFile("data/linear_regression.prototxt",
-      &net_param);
-  // check if things are right
-  EXPECT_EQ(net_param.layers_size(), 3);
-  EXPECT_EQ(net_param.input_size(), 0);
-  vector<Blob<TypeParam>*> bottom_vec;
-  Net<TypeParam> caffe_net(net_param, bottom_vec);
-  EXPECT_EQ(caffe_net.layer_names().size(), 3);
-  EXPECT_EQ(caffe_net.blob_names().size(), 3);
-
-  // Run the network without training.
-  LOG(INFO) << "Performing Forward";
-  caffe_net.Forward(bottom_vec);
-  LOG(INFO) << "Performing Backward";
-  LOG(INFO) << "Initial loss: " << caffe_net.Backward();
-
-  SolverParameter solver_param;
-  solver_param.set_base_lr(0.1);
-  solver_param.set_display(0);
-  solver_param.set_max_iter(100);
-  solver_param.set_lr_policy("inv");
-  solver_param.set_gamma(1.);
-  solver_param.set_power(0.75);
-  solver_param.set_momentum(0.9);
-
-  LOG(INFO) << "Starting Optimization";
-  SGDSolver<TypeParam> solver(solver_param);
-  solver.Solve(&caffe_net);
-  LOG(INFO) << "Optimization Done.";
-  LOG(INFO) << "Weight: " << caffe_net.params()[0]->cpu_data()[0] << ", "
-      << caffe_net.params()[0]->cpu_data()[1];
-  LOG(INFO) << "Bias: " << caffe_net.params()[1]->cpu_data()[0];
-
-  EXPECT_GE(caffe_net.params()[0]->cpu_data()[0], 0.3);
-  EXPECT_LE(caffe_net.params()[0]->cpu_data()[0], 0.35);
-
-  EXPECT_GE(caffe_net.params()[0]->cpu_data()[1], 0.3);
-  EXPECT_LE(caffe_net.params()[0]->cpu_data()[1], 0.35);
-
-  EXPECT_GE(caffe_net.params()[1]->cpu_data()[0], -0.01);
-  EXPECT_LE(caffe_net.params()[1]->cpu_data()[0], 0.01);
-}
-
-}  // namespace caffe