Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ include(cmake/Dependencies.cmake)

# ---[ Flags
if(UNIX OR APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall -std=c++11")
endif()

if(USE_libstdcpp)
Expand Down
16 changes: 9 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ ifneq ($(CPU_ONLY), 1)
LIBRARIES := cudart cublas curand
endif
LIBRARIES += glog gflags protobuf leveldb snappy \
lmdb boost_system hdf5_hl hdf5 m \
lmdb hdf5_hl hdf5 m \
opencv_core opencv_highgui opencv_imgproc
PYTHON_LIBRARIES := boost_python python2.7
WARNINGS := -Wall -Wno-sign-compare
Expand Down Expand Up @@ -233,7 +233,7 @@ ifeq ($(LINUX), 1)
endif
# boost::thread is reasonably called boost_thread (compare OS X)
# We will also explicitly add stdc++ to the link target.
LIBRARIES += boost_thread stdc++
LIBRARIES += stdc++
endif

# OS X:
Expand All @@ -253,7 +253,7 @@ ifeq ($(OSX), 1)
# gtest needs to use its own tuple to not conflict with clang
COMMON_FLAGS += -DGTEST_USE_OWN_TR1_TUPLE=1
# boost::thread is called boost_thread-mt to mark multithreading on OS X
LIBRARIES += boost_thread-mt
#LIBRARIES += boost_thread-mt
# we need to explicitly ask for the rpath to be obeyed
DYNAMIC_FLAGS := -install_name @rpath/libcaffe.so
ORIGIN := @loader_path
Expand Down Expand Up @@ -344,16 +344,18 @@ LIBRARY_DIRS += $(BLAS_LIB)

LIBRARY_DIRS += $(LIB_BUILD_DIR)

INCLUDE_DIRS += /usr/include/hdf5/serial

# Automatic dependency generation (nvcc is handled separately)
CXXFLAGS += -MMD -MP

# Complete build flags.
COMMON_FLAGS += $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir))
CXXFLAGS += -pthread -fPIC $(COMMON_FLAGS) $(WARNINGS)
NVCCFLAGS += -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
CXXFLAGS += -pthread -fPIC -std=c++11 $(COMMON_FLAGS) $(WARNINGS)
NVCCFLAGS += -ccbin=$(CXX) -Xcompiler -fPIC -std=c++11 $(COMMON_FLAGS)
# mex may invoke an older gcc that is too liberal with -Wuninitalized
MATLAB_CXXFLAGS := $(CXXFLAGS) -Wno-uninitialized
LINKFLAGS += -pthread -fPIC $(COMMON_FLAGS) $(WARNINGS)
LINKFLAGS += -pthread -fPIC -std=c++11 $(COMMON_FLAGS) $(WARNINGS)

USE_PKG_CONFIG ?= 0
ifeq ($(USE_PKG_CONFIG), 1)
Expand Down Expand Up @@ -441,7 +443,7 @@ py: $(PY$(PROJECT)_SO) $(PROTO_GEN_PY)

$(PY$(PROJECT)_SO): $(PY$(PROJECT)_SRC) $(PY$(PROJECT)_HXX) | $(DYNAMIC_NAME)
@ echo CXX/LD -o $@ $<
$(Q)$(CXX) -shared -o $@ $(PY$(PROJECT)_SRC) \
$(Q)$(CXX) -std=c++11 -shared -o $@ $(PY$(PROJECT)_SRC) \
-o $@ $(LINKFLAGS) -l$(PROJECT) $(PYTHON_LDFLAGS) \
-Wl,-rpath,$(ORIGIN)/../../build/lib

Expand Down
6 changes: 3 additions & 3 deletions cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
set(Caffe_LINKER_LIBS "")

# ---[ Boost
find_package(Boost 1.46 REQUIRED COMPONENTS system thread)
include_directories(SYSTEM ${Boost_INCLUDE_DIR})
list(APPEND Caffe_LINKER_LIBS ${Boost_LIBRARIES})
#find_package(Boost 1.46 REQUIRED COMPONENTS system thread)
#include_directories(SYSTEM ${Boost_INCLUDE_DIR})
#list(APPEND Caffe_LINKER_LIBS ${Boost_LIBRARIES})

# ---[ Threads
find_package(Threads REQUIRED)
Expand Down
10 changes: 5 additions & 5 deletions examples/cifar10/convert_cifar_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
// http://www.cs.toronto.edu/~kriz/cifar.html

#include <fstream> // NOLINT(readability/streams)
#include <memory>
#include <string>

#include "boost/scoped_ptr.hpp"
#include "glog/logging.h"
#include "google/protobuf/text_format.h"
#include "stdint.h"
Expand All @@ -18,7 +18,7 @@
#include "caffe/util/db.hpp"

using caffe::Datum;
using boost::scoped_ptr;
using std::unique_ptr;
using std::string;
namespace db = caffe::db;

Expand All @@ -37,9 +37,9 @@ void read_image(std::ifstream* file, int* label, char* buffer) {

void convert_dataset(const string& input_folder, const string& output_folder,
const string& db_type) {
scoped_ptr<db::DB> train_db(db::GetDB(db_type));
unique_ptr<db::DB> train_db(db::GetDB(db_type));
train_db->Open(output_folder + "/cifar10_train_" + db_type, db::NEW);
scoped_ptr<db::Transaction> txn(train_db->NewTransaction());
unique_ptr<db::Transaction> txn(train_db->NewTransaction());
// Data buffer
int label;
char str_buffer[kCIFARImageNBytes];
Expand Down Expand Up @@ -71,7 +71,7 @@ void convert_dataset(const string& input_folder, const string& output_folder,
train_db->Close();

LOG(INFO) << "Writing Testing data";
scoped_ptr<db::DB> test_db(db::GetDB(db_type));
unique_ptr<db::DB> test_db(db::GetDB(db_type));
test_db->Open(output_folder + "/cifar10_test_" + db_type, db::NEW);
txn.reset(test_db->NewTransaction());
// Open files
Expand Down
7 changes: 6 additions & 1 deletion examples/cpp_classification/classification.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
#include <caffe/caffe.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

#include <caffe/caffe.hpp>

#include <iomanip>
#include <iosfwd>
#include <memory>
#include <string>
#include <utility>
#include <vector>



using namespace caffe; // NOLINT(build/namespaces)
using std::string;

Expand Down
1 change: 0 additions & 1 deletion include/caffe/blob.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef CAFFE_BLOB_HPP_
#define CAFFE_BLOB_HPP_

#include <algorithm>
#include <string>
#include <vector>

Expand Down
15 changes: 7 additions & 8 deletions include/caffe/common.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef CAFFE_COMMON_HPP_
#define CAFFE_COMMON_HPP_

#include <boost/shared_ptr.hpp>
#include <gflags/gflags.h>
#include <glog/logging.h>

Expand All @@ -10,6 +9,7 @@
#include <fstream> // NOLINT(readability/streams)
#include <iostream> // NOLINT(readability/streams)
#include <map>
#include <memory>
#include <set>
#include <sstream>
#include <string>
Expand Down Expand Up @@ -70,9 +70,8 @@ namespace cv { class Mat; }

namespace caffe {

// We will use the boost shared_ptr instead of the new C++11 one mainly
// because cuda does not work (at least now) well with C++11 features.
using boost::shared_ptr;

using std::shared_ptr;

// Common functions and classes from std that caffe often uses.
using std::fstream;
Expand Down Expand Up @@ -106,7 +105,7 @@ class Caffe {
}
enum Brew { CPU, GPU };

// This random number generator facade hides boost and CUDA rng
// This random number generator facade hides std and CUDA rng
// implementation from one another (for cross-platform compatibility).
class RNG {
public:
Expand All @@ -117,10 +116,10 @@ class Caffe {
void* generator();
private:
class Generator;
shared_ptr<Generator> generator_;
std::shared_ptr<Generator> generator_;
};

// Getters for boost rng, curand, and cublas handles
// Getters for std rng, curand, and cublas handles
inline static RNG& rng_stream() {
if (!Get().random_generator_) {
Get().random_generator_.reset(new RNG());
Expand All @@ -142,7 +141,7 @@ class Caffe {
// freed in a non-pinned way, which may cause problems - I haven't verified
// it personally but better to note it here in the header file.
inline static void set_mode(Brew mode) { Get().mode_ = mode; }
// Sets the random seed of both boost and curand
// Sets the random seed of both std and curand
static void set_random_seed(const unsigned int seed);
// Sets the device. Since we have cublas and curand stuff, set device also
// requires us to reset those values.
Expand Down
1 change: 0 additions & 1 deletion include/caffe/data_layers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <utility>
#include <vector>

#include "boost/scoped_ptr.hpp"
#include "hdf5.h"

#include "caffe/blob.hpp"
Expand Down
11 changes: 3 additions & 8 deletions include/caffe/internal_thread.hpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
#ifndef CAFFE_INTERNAL_THREAD_HPP_
#define CAFFE_INTERNAL_THREAD_HPP_
#include <thread>

#include "caffe/common.hpp"

/**
Forward declare boost::thread instead of including boost/thread.hpp
to avoid a boost/NVCC issues (#1009, #1010) on OSX.
*/
namespace boost { class thread; }

namespace caffe {

/**
* Virtual class encapsulate boost::thread for use in base class
* Virtual class encapsulate std::thread for use in base class
* The child class will acquire the ability to run a single thread,
* by reimplementing the virutal function InternalThreadEntry.
*/
Expand All @@ -34,7 +29,7 @@ class InternalThread {
with the code you want your thread to run. */
virtual void InternalThreadEntry() {}

shared_ptr<boost::thread> thread_;
shared_ptr<std::thread> thread_;
};

} // namespace caffe
Expand Down
1 change: 0 additions & 1 deletion include/caffe/layer.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef CAFFE_LAYER_H_
#define CAFFE_LAYER_H_

#include <algorithm>
#include <string>
#include <vector>

Expand Down
9 changes: 6 additions & 3 deletions include/caffe/util/benchmark.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef CAFFE_UTIL_BENCHMARK_H_
#define CAFFE_UTIL_BENCHMARK_H_

#include <boost/date_time/posix_time/posix_time.hpp>
#include <chrono>

#include "caffe/util/device_alternate.hpp"

Expand Down Expand Up @@ -31,8 +31,11 @@ class Timer {
cudaEvent_t start_gpu_;
cudaEvent_t stop_gpu_;
#endif
boost::posix_time::ptime start_cpu_;
boost::posix_time::ptime stop_cpu_;
typedef std::chrono::high_resolution_clock clock;
typedef std::chrono::microseconds microseconds;
typedef std::chrono::milliseconds milliseconds;
clock::time_point start_cpu_;
clock::time_point stop_cpu_;
float elapsed_milliseconds_;
float elapsed_microseconds_;
};
Expand Down
17 changes: 17 additions & 0 deletions include/caffe/util/io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <unistd.h>
#include <string>
#include <vector>


#include "google/protobuf/message.h"
#include "hdf5.h"
Expand Down Expand Up @@ -140,6 +142,21 @@ cv::Mat DecodeDatumToCVMat(const Datum& datum, bool is_color);

void CVMatToDatum(const cv::Mat& cv_img, Datum* datum);

inline void string_split(vector<string>* tokens, const string& str,
const string& delimiters) {
// Skip delimiters at beginning.
string::size_type lastPos = str.find_first_not_of(delimiters, 0);
// Find first "non-delimiter".
string::size_type pos = str.find_first_of(delimiters, lastPos);
while (string::npos != pos || string::npos != lastPos) {
// Found a token, add it to the vector.
tokens->push_back(str.substr(lastPos, pos - lastPos));
// Skip delimiters. Note the "not_of"
lastPos = str.find_first_not_of(delimiters, pos);
// Find next "non-delimiter"
pos = str.find_first_of(delimiters, lastPos);
}
}
template <typename Dtype>
void hdf5_load_nd_dataset_helper(
hid_t file_id, const char* dataset_name_, int min_dim, int max_dim,
Expand Down
7 changes: 3 additions & 4 deletions include/caffe/util/rng.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
#include <algorithm>
#include <iterator>

#include "boost/random/mersenne_twister.hpp"
#include "boost/random/uniform_int.hpp"
#include <random>

#include "caffe/common.hpp"

namespace caffe {

typedef boost::mt19937 rng_t;
typedef std::mt19937_64 rng_t;

inline rng_t* caffe_rng() {
return static_cast<caffe::rng_t*>(Caffe::rng_stream().generator());
Expand All @@ -23,7 +22,7 @@ inline void shuffle(RandomAccessIterator begin, RandomAccessIterator end,
RandomGenerator* gen) {
typedef typename std::iterator_traits<RandomAccessIterator>::difference_type
difference_type;
typedef typename boost::uniform_int<difference_type> dist_type;
typedef typename std::uniform_int_distribution<difference_type> dist_type;

difference_type length = std::distance(begin, end);
if (length <= 0) return;
Expand Down
1 change: 1 addition & 0 deletions include/caffe/vision_layers.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef CAFFE_VISION_LAYERS_HPP_
#define CAFFE_VISION_LAYERS_HPP_

#include <memory>
#include <string>
#include <utility>
#include <vector>
Expand Down
2 changes: 1 addition & 1 deletion python/caffe/_caffe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void Net_SetInputArrays(Net<Dtype>* net, bp::object data_obj,
bp::object labels_obj) {
// check that this network has an input MemoryDataLayer
shared_ptr<MemoryDataLayer<Dtype> > md_layer =
boost::dynamic_pointer_cast<MemoryDataLayer<Dtype> >(net->layers()[0]);
std::dynamic_pointer_cast<MemoryDataLayer<Dtype> >(net->layers()[0]);
if (!md_layer) {
throw std::runtime_error("set_input_arrays may only be called if the"
" first layer is a MemoryDataLayer");
Expand Down
16 changes: 11 additions & 5 deletions scripts/travis/travis_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,23 @@ MAKE="make --jobs=$NUM_THREADS"

# This ppa is for gflags and glog
add-apt-repository -y ppa:tuleu/precise-backports
# This ppa is for boost 1.54
add-apt-repository -y ppa:boost-latest/ppa
# This ppa is for g++ 4.8
add-apt-repository -y ppa:ubuntu-toolchain-r/test

apt-get -y update
apt-get install \
wget git curl \
g++-4.8 wget git curl \
python-dev python-numpy \
libleveldb-dev libsnappy-dev libopencv-dev \
libboost-dev libboost-system-dev libboost-python-dev libboost-thread-dev \
libboost-python1.54-dev \
libprotobuf-dev protobuf-compiler \
libatlas-dev libatlas-base-dev \
libhdf5-serial-dev libgflags-dev libgoogle-glog-dev \
bc

update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 90
# Add a special apt-repository to install CMake 2.8.9 for CMake Caffe build,
# if needed. By default, Aptitude in Ubuntu 12.04 installs CMake 2.8.7, but
# Caffe requires a minimum CMake version of 2.8.8.
Expand All @@ -31,19 +37,19 @@ fi

# Install CUDA, if needed
if $WITH_CUDA; then
CUDA_URL=http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1204/x86_64/cuda-repo-ubuntu1204_6.5-14_amd64.deb
CUDA_URL=http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1204/x86_64/cuda-repo-ubuntu1204_7.0-28_amd64.deb
CUDA_FILE=/tmp/cuda_install.deb
curl $CUDA_URL -o $CUDA_FILE
dpkg -i $CUDA_FILE
rm -f $CUDA_FILE
apt-get -y update
# Install the minimal CUDA subpackages required to test Caffe build.
# For a full CUDA installation, add 'cuda' to the list of packages.
apt-get -y install cuda-core-6-5 cuda-cublas-6-5 cuda-cublas-dev-6-5 cuda-cudart-6-5 cuda-cudart-dev-6-5 cuda-curand-6-5 cuda-curand-dev-6-5
apt-get -y install cuda-core-7-0 cuda-cublas-7-0 cuda-cublas-dev-7-0 cuda-cudart-7-0 cuda-cudart-dev-7-0 cuda-curand-7-0 cuda-curand-dev-7-0
# Create CUDA symlink at /usr/local/cuda
# (This would normally be created by the CUDA installer, but we create it
# manually since we did a partial installation.)
ln -s /usr/local/cuda-6.5 /usr/local/cuda
ln -s /usr/local/cuda-7.0 /usr/local/cuda
fi

# Install LMDB
Expand Down
Loading