| | |
| | | #include "activation_layer.h" |
| | | #include "deconvolutional_layer.h" |
| | | #include "detection_layer.h" |
| | | #include "region_layer.h" |
| | | #include "normalization_layer.h" |
| | | #include "batchnorm_layer.h" |
| | | #include "maxpool_layer.h" |
| | |
| | | case EXP: |
| | | return net.learning_rate * pow(net.gamma, batch_num); |
| | | case POLY: |
| | | if (batch_num < net.burn_in) return net.learning_rate * pow((float)batch_num / net.burn_in, net.power); |
| | | return net.learning_rate * pow(1 - (float)batch_num / net.max_batches, net.power); |
| | | case RANDOM: |
| | | return net.learning_rate * pow(rand_uniform(0,1), net.power); |
| | | case SIG: |
| | | return net.learning_rate * (1./(1.+exp(net.gamma*(batch_num - net.step)))); |
| | | default: |
| | |
| | | return "softmax"; |
| | | case DETECTION: |
| | | return "detection"; |
| | | case REGION: |
| | | return "region"; |
| | | case DROPOUT: |
| | | return "dropout"; |
| | | case CROP: |
| | |
| | | |
| | | void forward_network(network net, network_state state) |
| | | { |
| | | state.workspace = net.workspace; |
| | | int i; |
| | | for(i = 0; i < net.n; ++i){ |
| | | state.index = i; |
| | |
| | | forward_batchnorm_layer(l, state); |
| | | } else if(l.type == DETECTION){ |
| | | forward_detection_layer(l, state); |
| | | } else if(l.type == REGION){ |
| | | forward_region_layer(l, state); |
| | | } else if(l.type == CONNECTED){ |
| | | forward_connected_layer(l, state); |
| | | } else if(l.type == RNN){ |
| | |
| | | float sum = 0; |
| | | int count = 0; |
| | | for(i = 0; i < net.n; ++i){ |
| | | if(net.layers[i].type == COST){ |
| | | sum += net.layers[i].cost[0]; |
| | | ++count; |
| | | } |
| | | if(net.layers[i].type == DETECTION){ |
| | | if(net.layers[i].cost){ |
| | | sum += net.layers[i].cost[0]; |
| | | ++count; |
| | | } |
| | |
| | | int i; |
| | | float *original_input = state.input; |
| | | float *original_delta = state.delta; |
| | | state.workspace = net.workspace; |
| | | for(i = net.n-1; i >= 0; --i){ |
| | | state.index = i; |
| | | if(i == 0){ |
| | |
| | | backward_dropout_layer(l, state); |
| | | } else if(l.type == DETECTION){ |
| | | backward_detection_layer(l, state); |
| | | } else if(l.type == REGION){ |
| | | backward_region_layer(l, state); |
| | | } else if(l.type == SOFTMAX){ |
| | | if(i != 0) backward_softmax_layer(l, state); |
| | | } else if(l.type == CONNECTED){ |
| | |
| | | int i; |
| | | for(i = 0; i < net->n; ++i){ |
| | | net->layers[i].batch = b; |
| | | #ifdef CUDNN |
| | | if(net->layers[i].type == CONVOLUTIONAL){ |
| | | cudnn_convolutional_setup(net->layers + i); |
| | | } |
| | | #endif |
| | | } |
| | | } |
| | | |
| | |
| | | net->w = w; |
| | | net->h = h; |
| | | int inputs = 0; |
| | | size_t workspace_size = 0; |
| | | //fprintf(stderr, "Resizing to %d x %d...", w, h); |
| | | //fflush(stderr); |
| | | for (i = 0; i < net->n; ++i){ |
| | |
| | | }else{ |
| | | error("Cannot resize this type of layer"); |
| | | } |
| | | if(l.workspace_size > workspace_size) workspace_size = l.workspace_size; |
| | | inputs = l.outputs; |
| | | net->layers[i] = l; |
| | | w = l.out_w; |
| | | h = l.out_h; |
| | | if(l.type == AVGPOOL) break; |
| | | } |
| | | #ifdef GPU |
| | | cuda_free(net->workspace); |
| | | net->workspace = cuda_make_array(0, (workspace_size-1)/sizeof(float)+1); |
| | | #else |
| | | free(net->workspace); |
| | | net->workspace = calloc(1, workspace_size); |
| | | #endif |
| | | //fprintf(stderr, " Done!\n"); |
| | | return 0; |
| | | } |