2013-11-04 23:11:01 +04:00
|
|
|
// Oh boy, why am I about to do this....
|
|
|
|
#ifndef NETWORK_H
|
|
|
|
#define NETWORK_H
|
|
|
|
|
|
|
|
#include "image.h"
|
2015-05-11 23:46:49 +03:00
|
|
|
#include "layer.h"
|
2013-11-13 22:50:38 +04:00
|
|
|
#include "data.h"
|
2013-11-04 23:11:01 +04:00
|
|
|
|
2015-09-05 03:52:44 +03:00
|
|
|
typedef enum {
|
2016-05-12 23:36:11 +03:00
|
|
|
CONSTANT, STEP, EXP, POLY, STEPS, SIG, RANDOM
|
2015-09-05 03:52:44 +03:00
|
|
|
} learning_rate_policy;
|
|
|
|
|
2015-12-14 22:57:10 +03:00
|
|
|
typedef struct network{
|
2016-05-13 21:59:43 +03:00
|
|
|
float *workspace;
|
2013-11-04 23:11:01 +04:00
|
|
|
int n;
|
2014-03-13 08:57:34 +04:00
|
|
|
int batch;
|
2015-09-05 03:52:44 +03:00
|
|
|
int *seen;
|
2015-11-04 06:23:17 +03:00
|
|
|
float epoch;
|
2015-03-22 19:56:40 +03:00
|
|
|
int subdivisions;
|
2014-08-08 23:04:15 +04:00
|
|
|
float momentum;
|
|
|
|
float decay;
|
2015-05-11 23:46:49 +03:00
|
|
|
layer *layers;
|
2013-12-07 01:26:09 +04:00
|
|
|
int outputs;
|
2014-01-29 04:28:42 +04:00
|
|
|
float *output;
|
2015-09-05 03:52:44 +03:00
|
|
|
learning_rate_policy policy;
|
|
|
|
|
|
|
|
float learning_rate;
|
|
|
|
float gamma;
|
2015-09-09 22:48:40 +03:00
|
|
|
float scale;
|
2015-09-05 03:52:44 +03:00
|
|
|
float power;
|
2016-01-28 23:30:38 +03:00
|
|
|
int time_steps;
|
2015-09-05 03:52:44 +03:00
|
|
|
int step;
|
|
|
|
int max_batches;
|
2015-09-09 22:48:40 +03:00
|
|
|
float *scales;
|
|
|
|
int *steps;
|
|
|
|
int num_steps;
|
2016-06-20 23:18:59 +03:00
|
|
|
int burn_in;
|
2014-05-10 02:14:52 +04:00
|
|
|
|
2015-03-12 08:20:15 +03:00
|
|
|
int inputs;
|
|
|
|
int h, w, c;
|
2016-03-01 00:54:12 +03:00
|
|
|
int max_crop;
|
2016-05-07 02:25:16 +03:00
|
|
|
int min_crop;
|
2016-08-11 21:54:24 +03:00
|
|
|
float angle;
|
2016-09-08 08:27:56 +03:00
|
|
|
float aspect;
|
2016-08-11 21:54:24 +03:00
|
|
|
float exposure;
|
|
|
|
float saturation;
|
2016-09-02 02:48:41 +03:00
|
|
|
float hue;
|
2015-03-12 08:20:15 +03:00
|
|
|
|
2016-08-06 01:27:07 +03:00
|
|
|
int gpu_index;
|
|
|
|
|
2014-05-10 02:14:52 +04:00
|
|
|
#ifdef GPU
|
2015-01-23 03:38:24 +03:00
|
|
|
float **input_gpu;
|
|
|
|
float **truth_gpu;
|
2014-05-10 02:14:52 +04:00
|
|
|
#endif
|
2013-11-04 23:11:01 +04:00
|
|
|
} network;
|
2015-12-14 22:57:10 +03:00
|
|
|
|
|
|
|
typedef struct network_state {
|
|
|
|
float *truth;
|
|
|
|
float *input;
|
|
|
|
float *delta;
|
2016-05-13 21:59:43 +03:00
|
|
|
float *workspace;
|
2015-12-14 22:57:10 +03:00
|
|
|
int train;
|
|
|
|
int index;
|
|
|
|
network net;
|
|
|
|
} network_state;
|
2013-11-04 23:11:01 +04:00
|
|
|
|
2014-12-17 02:34:10 +03:00
|
|
|
#ifdef GPU
|
2016-09-20 21:34:49 +03:00
|
|
|
float train_networks(network *nets, int n, data d, int interval);
|
|
|
|
void sync_nets(network *nets, int n, int interval);
|
2014-12-17 02:34:10 +03:00
|
|
|
float train_network_datum_gpu(network net, float *x, float *y);
|
2014-11-06 01:49:58 +03:00
|
|
|
float *network_predict_gpu(network net, float *input);
|
2015-01-23 03:38:24 +03:00
|
|
|
float * get_network_output_gpu_layer(network net, int i);
|
|
|
|
float * get_network_delta_gpu_layer(network net, int i);
|
2015-05-07 00:08:16 +03:00
|
|
|
float *get_network_output_gpu(network net);
|
2015-07-08 10:36:43 +03:00
|
|
|
void forward_network_gpu(network net, network_state state);
|
|
|
|
void backward_network_gpu(network net, network_state state);
|
2015-11-26 22:48:01 +03:00
|
|
|
void update_network_gpu(network net);
|
2014-12-17 02:34:10 +03:00
|
|
|
#endif
|
2014-08-28 06:11:46 +04:00
|
|
|
|
2015-09-05 03:52:44 +03:00
|
|
|
float get_current_rate(network net);
|
|
|
|
int get_current_batch(network net);
|
2015-09-01 21:21:01 +03:00
|
|
|
void free_network(network net);
|
2014-12-18 22:28:42 +03:00
|
|
|
void compare_networks(network n1, network n2, data d);
|
2015-01-14 23:18:57 +03:00
|
|
|
char *get_layer_string(LAYER_TYPE a);
|
2014-12-18 22:28:42 +03:00
|
|
|
|
2015-03-12 08:20:15 +03:00
|
|
|
network make_network(int n);
|
|
|
|
void forward_network(network net, network_state state);
|
|
|
|
void backward_network(network net, network_state state);
|
2014-08-08 23:04:15 +04:00
|
|
|
void update_network(network net);
|
2014-12-17 02:34:10 +03:00
|
|
|
|
|
|
|
float train_network(network net, data d);
|
2014-08-08 23:04:15 +04:00
|
|
|
float train_network_batch(network net, data d, int n);
|
2014-12-17 02:34:10 +03:00
|
|
|
float train_network_sgd(network net, data d, int n);
|
2016-01-28 23:30:38 +03:00
|
|
|
float train_network_datum(network net, float *x, float *y);
|
2014-12-17 02:34:10 +03:00
|
|
|
|
2013-12-07 21:38:50 +04:00
|
|
|
matrix network_predict_data(network net, data test);
|
2014-10-25 22:57:26 +04:00
|
|
|
float *network_predict(network net, float *input);
|
2014-01-29 04:28:42 +04:00
|
|
|
float network_accuracy(network net, data d);
|
2015-10-09 22:50:43 +03:00
|
|
|
float *network_accuracies(network net, data d, int n);
|
2014-08-11 23:52:07 +04:00
|
|
|
float network_accuracy_multi(network net, data d, int n);
|
2014-10-25 22:57:26 +04:00
|
|
|
void top_predictions(network net, int n, int *index);
|
2014-01-29 04:28:42 +04:00
|
|
|
float *get_network_output(network net);
|
|
|
|
float *get_network_output_layer(network net, int i);
|
|
|
|
float *get_network_delta_layer(network net, int i);
|
|
|
|
float *get_network_delta(network net);
|
2013-11-07 04:09:41 +04:00
|
|
|
int get_network_output_size_layer(network net, int i);
|
2013-11-13 22:50:38 +04:00
|
|
|
int get_network_output_size(network net);
|
2013-11-04 23:11:01 +04:00
|
|
|
image get_network_image(network net);
|
2013-11-07 04:09:41 +04:00
|
|
|
image get_network_image_layer(network net, int i);
|
2013-12-07 01:26:09 +04:00
|
|
|
int get_predicted_class_network(network net);
|
2013-12-03 04:41:40 +04:00
|
|
|
void print_network(network net);
|
|
|
|
void visualize_network(network net);
|
2015-07-08 10:36:43 +03:00
|
|
|
int resize_network(network *net, int w, int h);
|
2014-12-12 00:15:26 +03:00
|
|
|
void set_batch_network(network *net, int b);
|
2014-05-10 02:14:52 +04:00
|
|
|
int get_network_input_size(network net);
|
2014-10-13 11:29:01 +04:00
|
|
|
float get_network_cost(network net);
|
2015-04-08 01:25:30 +03:00
|
|
|
|
|
|
|
int get_network_nuisance(network net);
|
|
|
|
int get_network_background(network net);
|
2013-11-04 23:11:01 +04:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|