| | |
| | | for(i = 0; i < N; ++i) X[i*INCX] *= ALPHA; |
| | | } |
| | | |
| | | void fill_cpu(int N, float ALPHA, float *X, int INCX) |
| | | { |
| | | int i; |
| | | for(i = 0; i < N; ++i) X[i*INCX] = ALPHA; |
| | | } |
| | | |
| | | void copy_cpu(int N, float *X, int INCX, float *Y, int INCY) |
| | | { |
| | | int i; |
| | |
| | | void axpy_cpu(int N, float ALPHA, float *X, int INCX, float *Y, int INCY); |
| | | void copy_cpu(int N, float *X, int INCX, float *Y, int INCY); |
| | | void scal_cpu(int N, float ALPHA, float *X, int INCX); |
| | | void fill_cpu(int N, float ALPHA, float * X, int INCX); |
| | | float dot_cpu(int N, float *X, int INCX, float *Y, int INCY); |
| | | void test_gpu_blas(); |
| | | void shortcut_cpu(float *out, int w, int h, int c, int batch, int sample, float *add, int stride, int c2); |
| | |
| | | clock_t time; |
| | | float avg_acc = 0; |
| | | float avg_topk = 0; |
| | | int splits = 50; |
| | | int splits = m/1000; |
| | | int num = (i+1)*m/splits - i*m/splits; |
| | | |
| | | data val, buffer; |
| | |
| | | int i = 0; |
| | | char **names = get_labels(name_list); |
| | | clock_t time; |
| | | int indexes[10]; |
| | | int *indexes = calloc(top, sizeof(int)); |
| | | char buff[256]; |
| | | char *input = buff; |
| | | while(1){ |
| | |
| | | if(!input) return; |
| | | strtok(input, "\n"); |
| | | } |
| | | image im = load_image_color(input, 256, 256); |
| | | image im = load_image_color(input, net.w, net.h); |
| | | float *X = im.data; |
| | | time=clock(); |
| | | float *predictions = network_predict(net, X); |
| | |
| | | } |
| | | } |
| | | |
| | | void test_classifier(char *datacfg, char *cfgfile, char *weightfile, char *filename, int target_layer) |
| | | void test_classifier(char *datacfg, char *cfgfile, char *weightfile, int target_layer) |
| | | { |
| | | int curr = 0; |
| | | network net = parse_network_cfg(filename); |
| | | network net = parse_network_cfg(cfgfile); |
| | | if(weightfile){ |
| | | load_weights(&net, weightfile); |
| | | } |
| | |
| | | list *options = read_data_cfg(datacfg); |
| | | |
| | | char *test_list = option_find_str(options, "test", "data/test.list"); |
| | | char *label_list = option_find_str(options, "labels", "data/labels.list"); |
| | | int classes = option_find_int(options, "classes", 2); |
| | | |
| | | char **labels = get_labels(label_list); |
| | | list *plist = get_paths(test_list); |
| | | |
| | | char **paths = (char **)list_to_array(plist); |
| | |
| | | args.classes = classes; |
| | | args.n = net.batch; |
| | | args.m = 0; |
| | | args.labels = labels; |
| | | args.labels = 0; |
| | | args.d = &buffer; |
| | | args.type = CLASSIFICATION_DATA; |
| | | |
| | |
| | | time=clock(); |
| | | matrix pred = network_predict_data(net, val); |
| | | |
| | | int i; |
| | | int i, j; |
| | | if (target_layer >= 0){ |
| | | //layer l = net.layers[target_layer]; |
| | | } |
| | | |
| | | for(i = 0; i < val.X.rows; ++i){ |
| | | |
| | | for(i = 0; i < pred.rows; ++i){ |
| | | printf("%s", paths[curr-net.batch+i]); |
| | | for(j = 0; j < pred.cols; ++j){ |
| | | printf("\t%g", pred.vals[i][j]); |
| | | } |
| | | printf("\n"); |
| | | } |
| | | |
| | | free_matrix(pred); |
| | |
| | | int layer = layer_s ? atoi(layer_s) : -1; |
| | | if(0==strcmp(argv[2], "predict")) predict_classifier(data, cfg, weights, filename); |
| | | else if(0==strcmp(argv[2], "train")) train_classifier(data, cfg, weights); |
| | | else if(0==strcmp(argv[2], "test")) test_classifier(data, cfg, weights,filename, layer); |
| | | else if(0==strcmp(argv[2], "test")) test_classifier(data, cfg, weights, layer); |
| | | else if(0==strcmp(argv[2], "valid")) validate_classifier(data, cfg, weights); |
| | | } |
| | | |
| | |
| | | #endif |
| | | } |
| | | |
| | | void bias_output(float *output, float *biases, int batch, int n, int size) |
| | | void add_bias(float *output, float *biases, int batch, int n, int size) |
| | | { |
| | | int i,j,b; |
| | | for(b = 0; b < batch; ++b){ |
| | | for(i = 0; i < n; ++i){ |
| | | for(j = 0; j < size; ++j){ |
| | | output[(b*n + i)*size + j] = biases[i]; |
| | | output[(b*n + i)*size + j] += biases[i]; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | void scale_bias(float *output, float *scales, int batch, int n, int size) |
| | | { |
| | | int i,j,b; |
| | | for(b = 0; b < batch; ++b){ |
| | | for(i = 0; i < n; ++i){ |
| | | for(j = 0; j < size; ++j){ |
| | | output[(b*n + i)*size + j] *= scales[i]; |
| | | } |
| | | } |
| | | } |
| | |
| | | int out_w = convolutional_out_width(l); |
| | | int i; |
| | | |
| | | bias_output(l.output, l.biases, l.batch, l.n, out_h*out_w); |
| | | fill_cpu(l.outputs*l.batch, 0, l.output, 1); |
| | | |
| | | int m = l.n; |
| | | int k = l.size*l.size*l.c; |
| | |
| | | } |
| | | |
| | | if(l.batch_normalize){ |
| | | mean_cpu(l.output, l.batch, l.n, l.out_h*l.out_w, l.mean); |
| | | variance_cpu(l.output, l.mean, l.batch, l.n, l.out_h*l.out_w, l.variance); |
| | | normalize_cpu(l.output, l.mean, l.variance, l.batch, l.n, l.out_h*l.out_w); |
| | | if(state.train){ |
| | | mean_cpu(l.output, l.batch, l.n, l.out_h*l.out_w, l.mean); |
| | | variance_cpu(l.output, l.mean, l.batch, l.n, l.out_h*l.out_w, l.variance); |
| | | normalize_cpu(l.output, l.mean, l.variance, l.batch, l.n, l.out_h*l.out_w); |
| | | } else { |
| | | normalize_cpu(l.output, l.rolling_mean, l.rolling_variance, l.batch, l.n, l.out_h*l.out_w); |
| | | } |
| | | scale_bias(l.output, l.scales, l.batch, l.n, out_h*out_w); |
| | | } |
| | | add_bias(l.output, l.biases, l.batch, l.n, out_h*out_w); |
| | | |
| | | activate_array(l.output, m*n*l.batch, l.activation); |
| | | } |
| | |
| | | |
| | | void backward_convolutional_layer(convolutional_layer layer, network_state state); |
| | | |
| | | void bias_output(float *output, float *biases, int batch, int n, int size); |
| | | void add_bias(float *output, float *biases, int batch, int n, int size); |
| | | void backward_bias(float *bias_updates, float *delta, int batch, int n, int size); |
| | | |
| | | image get_convolutional_image(convolutional_layer layer); |
| | |
| | | int n = l.h*l.w; |
| | | int k = l.c; |
| | | |
| | | bias_output(l.output, l.biases, l.batch, l.n, size); |
| | | fill_cpu(l.outputs*l.batch, 0, l.output, 1); |
| | | |
| | | for(i = 0; i < l.batch; ++i){ |
| | | float *a = l.filters; |
| | |
| | | |
| | | col2im_cpu(c, l.n, out_h, out_w, l.size, l.stride, 0, l.output+i*l.n*size); |
| | | } |
| | | add_bias(l.output, l.biases, l.batch, l.n, size); |
| | | activate_array(l.output, l.batch*l.n*size, l.activation); |
| | | } |
| | | |