Skip to content

Commit

Permalink
Merge pull request #22 from cvjena/master
Browse files Browse the repository at this point in the history
Pull changes for v1.2.0
  • Loading branch information
Clemens-Alexander Brust committed Jun 8, 2015
2 parents 6966b37 + 183fadd commit 1fd36aa
Show file tree
Hide file tree
Showing 32 changed files with 783 additions and 314 deletions.
24 changes: 16 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
cmake_minimum_required(VERSION 2.8)
project(CN24 C CXX)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")

# Get Git SHA1 hash
include(GetGitRevisionDescription)
get_git_head_revision(GIT_REFSPEC GIT_SHA1)
#git_describe(GIT_SHA1)
add_definitions("-DGIT_SHA1=\"${GIT_SHA1} ${GIT_REFSPEC}\"")

# Definitions
set(CN24_SRC "${CN24_SOURCE_DIR}/src")
set(CN24_INC "${CN24_SOURCE_DIR}/include" "${CN24_SOURCE_DIR}/include/cn24"
Expand Down Expand Up @@ -28,11 +36,6 @@ macro (currentdate RESULT)
endif (WIN32)
endmacro (currentdate)

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lc++")
endif()

if(CMAKE_COMPILER_IS_GNUCXX)
# We need C++11
execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion
Expand All @@ -48,7 +51,8 @@ if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra")
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL Clang)
message(STATUS "This is the right compiler, using -std=c++11.")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lc++")
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
message(STATUS "This is the right compiler, no switches needed")
else()
Expand Down Expand Up @@ -158,13 +162,17 @@ endif()

set(CN24_BUILD_OPENCL OFF CACHE BOOL "Build CN24 with OpenCL support")
if(CN24_BUILD_OPENCL)
find_library(OPENCL_ICDL NAMES OpenCL libOpenCL PATHS $ENV{CUDA_PATH}/lib/x64)
find_path(OPENCL_INCLUDE_DIR CL/cl.h cl.h PATHS $ENV{CUDA_PATH}/include)
find_library(OPENCL_ICDL NAMES OpenCL libOpenCL PATHS $ENV{CUDA_PATH}/lib/x64
$ENV{INTELOCLSDKROOT}/lib/x64)
find_path(OPENCL_INCLUDE_DIR CL/cl.h cl.h PATHS $ENV{CUDA_PATH}/include
$ENV{INTELOCLSDKROOT}/include)
message(STATUS "Using OpenCL library: ${OPENCL_ICDL}")
message(STATUS "Using OpenCL include directory: ${OPENCL_INCLUDE_DIR}")
include_directories(${OPENCL_INCLUDE_DIR})
set(CN24_LIBS ${CN24_LIBS} ${OPENCL_ICDL})
add_definitions("-DBUILD_OPENCL")
else()
message(STATUS "Enable OpenCL with -DCN24_BUILD_OPENCL:BOOL=ON to use your GPU")
endif()

set(CN24_BUILD_OPENMP OFF CACHE BOOL "Build CN24 with OpenMP support if possible")
Expand Down
3 changes: 3 additions & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ Contributors from the Computer Vision Group of the Friedrich Schiller University
Dipl.-Inf. Sven Sickert
Marcel Simon M.Sc.
Dr. rer. nat. Erik Rodner

GetGitRevisionDescription.cmake (Boost License 1.0):
Ryan A. Pavlik
23 changes: 23 additions & 0 deletions cmake/BOOST_LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Boost Software License - Version 1.0 - August 17th, 2003

Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:

The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
130 changes: 130 additions & 0 deletions cmake/GetGitRevisionDescription.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# - Returns a version string from Git
#
# These functions force a re-configure on each git commit so that you can
# trust the values of the variables in your build system.
#
# get_git_head_revision(<refspecvar> <hashvar> [<additional arguments to git describe> ...])
#
# Returns the refspec and sha hash of the current head revision
#
# git_describe(<var> [<additional arguments to git describe> ...])
#
# Returns the results of git describe on the source tree, and adjusting
# the output so that it tests false if an error occurs.
#
# git_get_exact_tag(<var> [<additional arguments to git describe> ...])
#
# Returns the results of git describe --exact-match on the source tree,
# and adjusting the output so that it tests false if there was no exact
# matching tag.
#
# Requires CMake 2.6 or newer (uses the 'function' command)
#
# Original Author:
# 2009-2010 Ryan Pavlik <[email protected]> <[email protected]>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

if(__get_git_revision_description)
return()
endif()
set(__get_git_revision_description YES)

# We must run the following at "include" time, not at function call time,
# to find the path to this module rather than the path to a calling list file
get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)

function(get_git_head_revision _refspecvar _hashvar)
set(GIT_PARENT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(GIT_DIR "${GIT_PARENT_DIR}/.git")
while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories
set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}")
get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH)
if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT)
# We have reached the root directory, we are not in git
set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
return()
endif()
set(GIT_DIR "${GIT_PARENT_DIR}/.git")
endwhile()
# check if this is a submodule
if(NOT IS_DIRECTORY ${GIT_DIR})
file(READ ${GIT_DIR} submodule)
string(REGEX REPLACE "gitdir: (.*)\n$" "\\1" GIT_DIR_RELATIVE ${submodule})
get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH)
get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE} ABSOLUTE)
endif()
set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data")
if(NOT EXISTS "${GIT_DATA}")
file(MAKE_DIRECTORY "${GIT_DATA}")
endif()

if(NOT EXISTS "${GIT_DIR}/HEAD")
return()
endif()
set(HEAD_FILE "${GIT_DATA}/HEAD")
configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY)

configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in"
"${GIT_DATA}/grabRef.cmake"
@ONLY)
include("${GIT_DATA}/grabRef.cmake")

set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE)
set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE)
endfunction()

function(git_describe _var)
if(NOT GIT_FOUND)
find_package(Git QUIET)
endif()
get_git_head_revision(refspec hash)
if(NOT GIT_FOUND)
set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
return()
endif()
if(NOT hash)
set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE)
return()
endif()

# TODO sanitize
#if((${ARGN}" MATCHES "&&") OR
# (ARGN MATCHES "||") OR
# (ARGN MATCHES "\\;"))
# message("Please report the following error to the project!")
# message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}")
#endif()

#message(STATUS "Arguments to execute_process: ${ARGN}")

execute_process(COMMAND
"${GIT_EXECUTABLE}"
describe
${hash}
${ARGN}
WORKING_DIRECTORY
"${CMAKE_SOURCE_DIR}"
RESULT_VARIABLE
res
OUTPUT_VARIABLE
out
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT res EQUAL 0)
set(out "${out}-${res}-NOTFOUND")
endif()

set(${_var} "${out}" PARENT_SCOPE)
endfunction()

function(git_get_exact_tag _var)
git_describe(out --exact-match ${ARGN})
set(${_var} "${out}" PARENT_SCOPE)
endfunction()
41 changes: 41 additions & 0 deletions cmake/GetGitRevisionDescription.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#
# Internal file for GetGitRevisionDescription.cmake
#
# Requires CMake 2.6 or newer (uses the 'function' command)
#
# Original Author:
# 2009-2010 Ryan Pavlik <[email protected]> <[email protected]>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

set(HEAD_HASH)

file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024)

string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS)
if(HEAD_CONTENTS MATCHES "ref")
# named branch
string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}")
if(EXISTS "@GIT_DIR@/${HEAD_REF}")
configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
else()
configure_file("@GIT_DIR@/packed-refs" "@GIT_DATA@/packed-refs" COPYONLY)
file(READ "@GIT_DATA@/packed-refs" PACKED_REFS)
if(${PACKED_REFS} MATCHES "([0-9a-z]*) ${HEAD_REF}")
set(HEAD_HASH "${CMAKE_MATCH_1}")
endif()
endif()
else()
# detached HEAD
configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY)
endif()

if(NOT HEAD_HASH)
file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024)
string(STRIP "${HEAD_HASH}" HEAD_HASH)
endif()
3 changes: 2 additions & 1 deletion include/cn24/net/BinaryStatLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class BinaryStatLayer: public Layer {
bool CreateOutputs (const std::vector< CombinedTensor* >& inputs,
std::vector< CombinedTensor* >& outputs);
bool Connect (const std::vector< CombinedTensor* >& inputs,
const std::vector< CombinedTensor* >& outputs);
const std::vector< CombinedTensor* >& outputs,
const Net* net );
void FeedForward();
void BackPropagate();

Expand Down
3 changes: 2 additions & 1 deletion include/cn24/net/ConfusionMatrixLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ class ConfusionMatrixLayer: public Layer {
bool CreateOutputs (const std::vector< CombinedTensor* >& inputs,
std::vector< CombinedTensor* >& outputs);
bool Connect (const std::vector< CombinedTensor* >& inputs,
const std::vector< CombinedTensor* >& outputs);
const std::vector< CombinedTensor* >& outputs,
const Net* net );
void FeedForward();
void BackPropagate();

Expand Down
7 changes: 5 additions & 2 deletions include/cn24/net/ConvolutionLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ class ConvolutionLayer : public SimpleLayer {
* @param kheight Height of the kernels
* @param output_maps Number of output feature maps
* @param seed Random seed for weight generation
* @param dropout_fraction Propability of a feature map to be dropped out
*/
ConvolutionLayer(const unsigned int kwidth, const unsigned int kheight,
const unsigned int output_maps, const int seed = 0);
const unsigned int output_maps, const int seed = 0,
const datum dropout_fraction = 0.0 );

// Implementations for SimpleLayer
bool CreateOutputs (const std::vector< CombinedTensor* >& inputs,
Expand Down Expand Up @@ -79,10 +81,11 @@ class ConvolutionLayer : public SimpleLayer {
CombinedTensor* bias_ = nullptr;
Tensor delta_buffer_;
Tensor bias_buffer_;
Tensor dropout_mask_;

std::mt19937 rand_;

datum weight_factor_ = 1.0;
datum dropout_fraction_ = 0.0;
};

}
Expand Down
5 changes: 4 additions & 1 deletion include/cn24/net/DatasetInputLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class DatasetInputLayer : public Layer, public TrainingLayer {
bool CreateOutputs (const std::vector< CombinedTensor* >& inputs,
std::vector< CombinedTensor* >& outputs);
bool Connect (const std::vector< CombinedTensor* >& inputs,
const std::vector< CombinedTensor* >& outputs);
const std::vector< CombinedTensor* >& outputs,
const Net* net );
void FeedForward();
void BackPropagate();

Expand All @@ -57,6 +58,8 @@ class DatasetInputLayer : public Layer, public TrainingLayer {
unsigned int GetSamplesInTrainingSet();
unsigned int GetSamplesInTestingSet();
unsigned int GetBatchSize();
unsigned int GetLabelWidth();
unsigned int GetLabelHeight();

inline datum GetLossSamplingProbability() {
return loss_sampling_p_;
Expand Down
3 changes: 2 additions & 1 deletion include/cn24/net/ErrorLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class ErrorLayer : public Layer, public LossFunctionLayer {
bool CreateOutputs (const std::vector< CombinedTensor* >& inputs,
std::vector< CombinedTensor* >& outputs);
bool Connect (const std::vector< CombinedTensor* >& inputs,
const std::vector< CombinedTensor* >& outputs);
const std::vector< CombinedTensor* >& outputs,
const Net* net );
void FeedForward();
void BackPropagate();

Expand Down
3 changes: 2 additions & 1 deletion include/cn24/net/InputLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class InputLayer: public Layer {
virtual bool CreateOutputs (const std::vector< CombinedTensor* >& inputs,
std::vector< CombinedTensor* >& outputs);
virtual bool Connect (const std::vector< CombinedTensor* >& inputs,
const std::vector< CombinedTensor* >& outputs);
const std::vector< CombinedTensor* >& outputs,
const Net* net );
virtual void FeedForward() { }
virtual void BackPropagate() { }

Expand Down
6 changes: 4 additions & 2 deletions include/cn24/net/Layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace Conv {

class Net;
class Trainer;
class GradientTester;
class Layer {
Expand All @@ -48,8 +49,9 @@ class Layer {
* @param outputs The outputs to the layer
*/
virtual bool Connect (const std::vector<CombinedTensor*>& inputs,
const std::vector<CombinedTensor*>& outputs) = 0;

const std::vector<CombinedTensor*>& outputs,
const Net* net) = 0;

/**
* @brief Performs a forward pass
*/
Expand Down
11 changes: 11 additions & 0 deletions include/cn24/net/Net.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,17 @@ class Net {
}
}

/**
* @brief Returns true if the net is currently testing
*/
inline bool IsTesting() const { return is_testing_; }

/**
* @brief Sets this net's testing status
*
* @param is_testing The new testing status
*/
inline void SetIsTesting(bool is_testing) { is_testing_ = is_testing; }
/**
* @brief Enables the built-in layer view GUI. Needs CMake build option.
*/
Expand All @@ -202,6 +212,7 @@ class Net {
std::chrono::duration<double>* forward_durations_ = nullptr;
std::chrono::duration<double>* backward_durations_ = nullptr;

bool is_testing_ = false;
};

}
Expand Down
Loading

0 comments on commit 1fd36aa

Please sign in to comment.