| | |
| | | } |
| | | if(net.types[i] == CONVOLUTIONAL){ |
| | | convolutional_layer layer = *(convolutional_layer *)net.layers[i]; |
| | | backward_convolutional_layer(layer, prev_delta); |
| | | backward_convolutional_layer(layer, prev_input, prev_delta); |
| | | } |
| | | else if(net.types[i] == MAXPOOL){ |
| | | maxpool_layer layer = *(maxpool_layer *)net.layers[i]; |
| | |
| | | fprintf(stderr, "Accuracy: %f\n", (float)correct/d.X.rows); |
| | | } |
| | | |
| | | void set_learning_network(network *net, float rate, float momentum, float decay) |
| | | { |
| | | int i; |
| | | net->learning_rate=rate; |
| | | net->momentum = momentum; |
| | | net->decay = decay; |
| | | for(i = 0; i < net->n; ++i){ |
| | | if(net->types[i] == CONVOLUTIONAL){ |
| | | convolutional_layer *layer = (convolutional_layer *)net->layers[i]; |
| | | layer->learning_rate=rate; |
| | | layer->momentum = momentum; |
| | | layer->decay = decay; |
| | | } |
| | | else if(net->types[i] == CONNECTED){ |
| | | connected_layer *layer = (connected_layer *)net->layers[i]; |
| | | layer->learning_rate=rate; |
| | | layer->momentum = momentum; |
| | | layer->decay = decay; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | void set_batch_network(network *net, int b) |
| | | { |
| | | net->batch = b; |
| | | int i; |
| | | for(i = 0; i < net->n; ++i){ |
| | | if(net->types[i] == CONVOLUTIONAL){ |
| | | convolutional_layer *layer = (convolutional_layer *)net->layers[i]; |
| | | layer->batch = b; |
| | | } |
| | | else if(net->types[i] == MAXPOOL){ |
| | | maxpool_layer *layer = (maxpool_layer *)net->layers[i]; |
| | | layer->batch = b; |
| | | } |
| | | else if(net->types[i] == CONNECTED){ |
| | | connected_layer *layer = (connected_layer *)net->layers[i]; |
| | | layer->batch = b; |
| | | } else if(net->types[i] == DROPOUT){ |
| | | dropout_layer *layer = (dropout_layer *) net->layers[i]; |
| | | layer->batch = b; |
| | | } |
| | | else if(net->types[i] == FREEWEIGHT){ |
| | | freeweight_layer *layer = (freeweight_layer *) net->layers[i]; |
| | | layer->batch = b; |
| | | } |
| | | else if(net->types[i] == SOFTMAX){ |
| | | softmax_layer *layer = (softmax_layer *)net->layers[i]; |
| | | layer->batch = b; |
| | | } |
| | | else if(net->types[i] == COST){ |
| | | cost_layer *layer = (cost_layer *)net->layers[i]; |
| | | layer->batch = b; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | int get_network_input_size_layer(network net, int i) |
| | | { |
| | | if(net.types[i] == CONVOLUTIONAL){ |
| | |
| | | } |
| | | } |
| | | |
| | | void top_predictions(network net, int n, int *index) |
| | | void top_predictions(network net, int k, int *index) |
| | | { |
| | | int i,j; |
| | | int k = get_network_output_size(net); |
| | | int size = get_network_output_size(net); |
| | | float *out = get_network_output(net); |
| | | float thresh = FLT_MAX; |
| | | for(i = 0; i < n; ++i){ |
| | | float max = -FLT_MAX; |
| | | int max_i = -1; |
| | | for(j = 0; j < k; ++j){ |
| | | float val = out[j]; |
| | | if(val > max && val < thresh){ |
| | | max = val; |
| | | max_i = j; |
| | | } |
| | | } |
| | | index[i] = max_i; |
| | | thresh = max; |
| | | } |
| | | top_k(out, size, k, index); |
| | | } |
| | | |
| | | |
| | |
| | | float network_accuracy(network net, data d) |
| | | { |
| | | matrix guess = network_predict_data(net, d); |
| | | float acc = matrix_accuracy(d.y, guess); |
| | | float acc = matrix_topk_accuracy(d.y, guess,1); |
| | | free_matrix(guess); |
| | | return acc; |
| | | } |
| | | |
| | | float *network_accuracies(network net, data d) |
| | | { |
| | | static float acc[2]; |
| | | matrix guess = network_predict_data(net, d); |
| | | acc[0] = matrix_topk_accuracy(d.y, guess,1); |
| | | acc[1] = matrix_topk_accuracy(d.y, guess,5); |
| | | free_matrix(guess); |
| | | return acc; |
| | | } |
| | | |
| | | |
| | | float network_accuracy_multi(network net, data d, int n) |
| | | { |
| | | matrix guess = network_predict_data_multi(net, d, n); |
| | | float acc = matrix_accuracy(d.y, guess); |
| | | float acc = matrix_topk_accuracy(d.y, guess,1); |
| | | free_matrix(guess); |
| | | return acc; |
| | | } |