Go to the documentation of this file.00001 #ifndef BASE_LAYER_H
00002 #define BASE_LAYER_H
00003
00004 #include "activations.h"
00005 #include "stddef.h"
00006 #include "tree.h"
00007
00008 struct network_state;
00009
00010 struct layer;
00011 typedef struct layer layer;
00012
00013 typedef enum {
00014 CONVOLUTIONAL,
00015 DECONVOLUTIONAL,
00016 CONNECTED,
00017 MAXPOOL,
00018 SOFTMAX,
00019 DETECTION,
00020 DROPOUT,
00021 CROP,
00022 ROUTE,
00023 COST,
00024 NORMALIZATION,
00025 AVGPOOL,
00026 LOCAL,
00027 SHORTCUT,
00028 ACTIVE,
00029 RNN,
00030 GRU,
00031 CRNN,
00032 BATCHNORM,
00033 NETWORK,
00034 XNOR,
00035 REGION,
00036 REORG,
00037 BLANK
00038 } LAYER_TYPE;
00039
00040 typedef enum{
00041 SSE, MASKED, SMOOTH
00042 } COST_TYPE;
00043
00044 struct layer{
00045 LAYER_TYPE type;
00046 ACTIVATION activation;
00047 COST_TYPE cost_type;
00048 void (*forward) (struct layer, struct network_state);
00049 void (*backward) (struct layer, struct network_state);
00050 void (*update) (struct layer, int, float, float, float);
00051 void (*forward_gpu) (struct layer, struct network_state);
00052 void (*backward_gpu) (struct layer, struct network_state);
00053 void (*update_gpu) (struct layer, int, float, float, float);
00054 int batch_normalize;
00055 int shortcut;
00056 int batch;
00057 int forced;
00058 int flipped;
00059 int inputs;
00060 int outputs;
00061 int truths;
00062 int h,w,c;
00063 int out_h, out_w, out_c;
00064 int n;
00065 int max_boxes;
00066 int groups;
00067 int size;
00068 int side;
00069 int stride;
00070 int reverse;
00071 int pad;
00072 int sqrt;
00073 int flip;
00074 int index;
00075 int binary;
00076 int xnor;
00077 int steps;
00078 int hidden;
00079 float dot;
00080 float angle;
00081 float jitter;
00082 float saturation;
00083 float exposure;
00084 float shift;
00085 float ratio;
00086 int softmax;
00087 int classes;
00088 int coords;
00089 int background;
00090 int rescore;
00091 int objectness;
00092 int does_cost;
00093 int joint;
00094 int noadjust;
00095 int reorg;
00096 int log;
00097
00098 int adam;
00099 float B1;
00100 float B2;
00101 float eps;
00102 float *m_gpu;
00103 float *v_gpu;
00104 int t;
00105 float *m;
00106 float *v;
00107
00108 tree *softmax_tree;
00109 int *map;
00110
00111 float alpha;
00112 float beta;
00113 float kappa;
00114
00115 float coord_scale;
00116 float object_scale;
00117 float noobject_scale;
00118 float class_scale;
00119 int bias_match;
00120 int random;
00121 float thresh;
00122 int classfix;
00123 int absolute;
00124
00125 int dontload;
00126 int dontloadscales;
00127
00128 float temperature;
00129 float probability;
00130 float scale;
00131
00132 int *indexes;
00133 float *rand;
00134 float *cost;
00135 char *cweights;
00136 float *state;
00137 float *prev_state;
00138 float *forgot_state;
00139 float *forgot_delta;
00140 float *state_delta;
00141
00142 float *concat;
00143 float *concat_delta;
00144
00145 float *binary_weights;
00146
00147 float *biases;
00148 float *bias_updates;
00149
00150 float *scales;
00151 float *scale_updates;
00152
00153 float *weights;
00154 float *weight_updates;
00155
00156 float *col_image;
00157 int * input_layers;
00158 int * input_sizes;
00159 float * delta;
00160 float * output;
00161 float * squared;
00162 float * norms;
00163
00164 float * spatial_mean;
00165 float * mean;
00166 float * variance;
00167
00168 float * mean_delta;
00169 float * variance_delta;
00170
00171 float * rolling_mean;
00172 float * rolling_variance;
00173
00174 float * x;
00175 float * x_norm;
00176
00177 struct layer *input_layer;
00178 struct layer *self_layer;
00179 struct layer *output_layer;
00180
00181 struct layer *input_gate_layer;
00182 struct layer *state_gate_layer;
00183 struct layer *input_save_layer;
00184 struct layer *state_save_layer;
00185 struct layer *input_state_layer;
00186 struct layer *state_state_layer;
00187
00188 struct layer *input_z_layer;
00189 struct layer *state_z_layer;
00190
00191 struct layer *input_r_layer;
00192 struct layer *state_r_layer;
00193
00194 struct layer *input_h_layer;
00195 struct layer *state_h_layer;
00196
00197 float *z_cpu;
00198 float *r_cpu;
00199 float *h_cpu;
00200
00201 float *binary_input;
00202
00203 size_t workspace_size;
00204
00205 #ifdef GPU
00206 float *z_gpu;
00207 float *r_gpu;
00208 float *h_gpu;
00209
00210 int *indexes_gpu;
00211 float * prev_state_gpu;
00212 float * forgot_state_gpu;
00213 float * forgot_delta_gpu;
00214 float * state_gpu;
00215 float * state_delta_gpu;
00216 float * gate_gpu;
00217 float * gate_delta_gpu;
00218 float * save_gpu;
00219 float * save_delta_gpu;
00220 float * concat_gpu;
00221 float * concat_delta_gpu;
00222
00223 float *binary_input_gpu;
00224 float *binary_weights_gpu;
00225
00226 float * mean_gpu;
00227 float * variance_gpu;
00228
00229 float * rolling_mean_gpu;
00230 float * rolling_variance_gpu;
00231
00232 float * variance_delta_gpu;
00233 float * mean_delta_gpu;
00234
00235 float * col_image_gpu;
00236
00237 float * x_gpu;
00238 float * x_norm_gpu;
00239 float * weights_gpu;
00240 float * weight_updates_gpu;
00241
00242 float * biases_gpu;
00243 float * bias_updates_gpu;
00244
00245 float * scales_gpu;
00246 float * scale_updates_gpu;
00247
00248 float * output_gpu;
00249 float * delta_gpu;
00250 float * rand_gpu;
00251 float * squared_gpu;
00252 float * norms_gpu;
00253 #ifdef CUDNN
00254 cudnnTensorDescriptor_t srcTensorDesc, dstTensorDesc;
00255 cudnnTensorDescriptor_t dsrcTensorDesc, ddstTensorDesc;
00256 cudnnFilterDescriptor_t weightDesc;
00257 cudnnFilterDescriptor_t dweightDesc;
00258 cudnnConvolutionDescriptor_t convDesc;
00259 cudnnConvolutionFwdAlgo_t fw_algo;
00260 cudnnConvolutionBwdDataAlgo_t bd_algo;
00261 cudnnConvolutionBwdFilterAlgo_t bf_algo;
00262 #endif
00263 #endif
00264 };
00265
00266 void free_layer(layer);
00267
00268 #endif