|
|
| network (const std::string &name="") |
| |
|
std::string | name () const |
| | name of the network
|
| |
|
void | init_weight () |
| | explicitly initialize weights of all layers
|
| |
|
vec_t | predict (const vec_t &in) |
| | executes forward-propagation and returns output
|
| |
|
tensor_t | predict (const tensor_t &in) |
| | executes forward-propagation and returns output
|
| |
|
std::vector< tensor_t > | predict (const std::vector< tensor_t > &in) |
| | executes forward-propagation and returns output
|
| |
|
float_t | predict_max_value (const vec_t &in) |
| | executes forward-propagation and returns maximum output
|
| |
|
label_t | predict_label (const vec_t &in) |
| | executes forward-propagation and returns maximum output index
|
| |
| template<typename Range > |
| vec_t | predict (const Range &in) |
| | executes forward-propagation and returns output
|
| |
| template<typename Error , typename Optimizer , typename OnBatchEnumerate , typename OnEpochEnumerate > |
| bool | train (Optimizer &optimizer, const std::vector< vec_t > &inputs, const std::vector< label_t > &class_labels, size_t batch_size, int epoch, OnBatchEnumerate on_batch_enumerate, OnEpochEnumerate on_epoch_enumerate, const bool reset_weights=false, const int n_threads=CNN_TASK_SIZE, const std::vector< vec_t > &t_cost=std::vector< vec_t >()) |
| | trains the network for a fixed number of epochs (for classification task)
|
| |
| template<typename Error , typename Optimizer , typename OnBatchEnumerate , typename OnEpochEnumerate , typename T , typename U > |
| bool | fit (Optimizer &optimizer, const std::vector< T > &inputs, const std::vector< U > &desired_outputs, size_t batch_size, int epoch, OnBatchEnumerate on_batch_enumerate, OnEpochEnumerate on_epoch_enumerate, const bool reset_weights=false, const int n_threads=CNN_TASK_SIZE, const std::vector< U > &t_cost=std::vector< U >()) |
| | trains the network for a fixed number of epochs to generate desired output.
|
| |
| template<typename Error , typename Optimizer , typename T , typename U > |
| bool | fit (Optimizer &optimizer, const std::vector< T > &inputs, const std::vector< U > &desired_outputs, size_t batch_size=1, int epoch=1) |
| |
| template<typename Error , typename Optimizer > |
| bool | train (Optimizer &optimizer, const std::vector< vec_t > &inputs, const std::vector< label_t > &class_labels, size_t batch_size=1, int epoch=1) |
| |
| template<typename Error , typename Optimizer > |
| bool | train (Optimizer &optimizer, const std::vector< vec_t > &in, const std::vector< vec_t > &t, size_t batch_size=1, int epoch=1) |
| |
| void | set_netphase (net_phase phase) |
| | set the netphase to train or test
|
| |
|
result | test (const std::vector< vec_t > &in, const std::vector< label_t > &t) |
| | test and generate confusion-matrix for classification task
|
| |
|
std::vector< vec_t > | test (const std::vector< vec_t > &in) |
| | generate output for each input
|
| |
|
template<typename E > |
| float_t | get_loss (const std::vector< vec_t > &in, const std::vector< vec_t > &t) |
| | calculate loss value (the smaller, the better) for regression task
|
| |
|
template<typename E , typename T > |
| float_t | get_loss (const std::vector< T > &in, const std::vector< tensor_t > &t) |
| | calculate loss value (the smaller, the better) for regression task
|
| |
|
template<typename E > |
| bool | gradient_check (const std::vector< tensor_t > &in, const std::vector< std::vector< label_t > > &t, float_t eps, grad_check_mode mode) |
| | checking gradients calculated by bprop detail information: http://ufldl.stanford.edu/wiki/index.php/Gradient_checking_and_advanced_optimization
|
| |
|
size_t | layer_size () const |
| | return number of layers
|
| |
| size_t | depth () const |
| |
|
const layer * | operator[] (size_t index) const |
| | return raw pointer of index-th layer
|
| |
|
layer * | operator[] (size_t index) |
| | return raw pointer of index-th layer
|
| |
|
template<typename T > |
| const T & | at (size_t index) const |
| | return index-th layer as <T> throw nn_error if index-th layer cannot be converted to T
|
| |
|
template<typename T > |
| T & | at (size_t index) |
| |
|
serial_size_t | out_data_size () const |
| | return total number of elements of output data
|
| |
|
serial_size_t | in_data_size () const |
| | return total number of elements of input data
|
| |
|
template<typename WeightInit > |
| network & | weight_init (const WeightInit &f) |
| | set weight initializer to all layers
|
| |
|
template<typename BiasInit > |
| network & | bias_init (const BiasInit &f) |
| | set bias initializer to all layers
|
| |
|
template<typename T > |
| bool | has_same_weights (const network< T > &rhs, float_t eps) const |
| | returns if 2 networks have almost(<eps) the same weights
|
| |
|
iterator | begin () |
| |
|
iterator | end () |
| |
|
const_iterator | begin () const |
| |
|
const_iterator | end () const |
| |
|
void | load (const std::string &filename, content_type what=content_type::weights_and_model, file_format format=file_format::binary) |
| |
|
void | save (const std::string &filename, content_type what=content_type::weights_and_model, file_format format=file_format::binary) const |
| |
|
std::string | to_json () const |
| | save the network architecture as json string
|
| |
| void | from_json (const std::string &json_string) |
| | load the network architecture from json string
|
| |
| void | save (std::ostream &os) const |
| |
|
void | load (std::istream &is) |
| |
| void | fast_load (const char *filepath) |
| | load network weights from filepath, 30 times faster than stream reading
|
| |
|
template<typename OutputArchive > |
| void | to_archive (OutputArchive &ar, content_type what=content_type::weights_and_model) const |
| |
|
template<typename InputArchive > |
| void | from_archive (InputArchive &ar, content_type what=content_type::weights_and_model) |
| |
A model of neural networks in tiny-dnn.
There are two types of network model available: sequential and graph. A graph representation describe network as computational graph - each node of graph is layer, and each directed edge holds tensor and its gradients. Sequential representation describe network as linked list - each layer has at most one predecessor and one successor layer.
Two types of network is represented as network<sequential> and network<graph> class. These two classes have same API, except for its construction.
using namespace tiny_dnn;
using namespace tiny_dnn::layers;
std::vector<vec_t> data;
std::vector<label_t> label;
network<sequential> net("foo");
std::cout << net.name(); // "foo"
// simply stack layers by operator <<
net << fc<tan_h>(50, 200) << fc<tan_h>(200, 10);
// prepare optimizer
adagrad opt;
// then train
net.train<mse>(opt, data, label, 10, 20);
- Parameters
-
| NetType | specify the network is "sequential" or "graph". "sequential" means the network doesn't have any branch or merge pass. if the network has branch/merge, "graph" can be used. |