Joseph Redmon
2015-12-18 9802287b5890d9b2cc250adba1b9810657a95c9c
some fixes
6 files modified
62 ■■■■ changed files
src/blas.c 6 ●●●●● patch | view | raw | blame | history
src/blas.h 1 ●●●● patch | view | raw | blame | history
src/classifier.c 26 ●●●● patch | view | raw | blame | history
src/convolutional_layer.c 24 ●●●● patch | view | raw | blame | history
src/convolutional_layer.h 2 ●●● patch | view | raw | blame | history
src/deconvolutional_layer.c 3 ●●●● patch | view | raw | blame | history
src/blas.c
@@ -92,6 +92,12 @@
    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;
src/blas.h
@@ -13,6 +13,7 @@
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);
src/classifier.c
@@ -143,7 +143,7 @@
    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;
@@ -201,7 +201,7 @@
    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){
@@ -214,7 +214,7 @@
            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);
@@ -229,10 +229,10 @@
    }
}
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);
    }
@@ -241,10 +241,8 @@
    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);
@@ -262,7 +260,7 @@
    args.classes = classes;
    args.n = net.batch;
    args.m = 0;
    args.labels = labels;
    args.labels = 0;
    args.d = &buffer;
    args.type = CLASSIFICATION_DATA;
@@ -283,13 +281,17 @@
        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);
@@ -315,7 +317,7 @@
    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);
}
src/convolutional_layer.c
@@ -194,13 +194,25 @@
#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];
            }
        }
    }
@@ -222,7 +234,7 @@
    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;
@@ -241,10 +253,16 @@
    }
    if(l.batch_normalize){
        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);
}
src/convolutional_layer.h
@@ -31,7 +31,7 @@
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);
src/deconvolutional_layer.c
@@ -134,7 +134,7 @@
    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;
@@ -145,6 +145,7 @@
        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);
}