Joseph Redmon
2014-12-03 ff67f0347653c35c67ddbafad8dc76bbd868047e
src/parser.c
@@ -67,7 +67,6 @@
convolutional_layer *parse_convolutional(list *options, network *net, int count)
{
    int i;
    int h,w,c;
    float learning_rate, momentum, decay;
    int n = option_find_int(options, "filters",1);
@@ -98,34 +97,19 @@
        if(h == 0) error("Layer before convolutional layer must output image.");
    }
    convolutional_layer *layer = make_convolutional_layer(net->batch,h,w,c,n,size,stride,pad,activation,learning_rate,momentum,decay);
    char *data = option_find_str(options, "data", 0);
    if(data){
        char *curr = data;
        char *next = data;
        for(i = 0; i < n; ++i){
            while(*++next !='\0' && *next != ',');
            *next = '\0';
            sscanf(curr, "%g", &layer->biases[i]);
            curr = next+1;
        }
        for(i = 0; i < c*n*size*size; ++i){
            while(*++next !='\0' && *next != ',');
            *next = '\0';
            sscanf(curr, "%g", &layer->filters[i]);
            curr = next+1;
        }
    }
    char *weights = option_find_str(options, "weights", 0);
    char *biases = option_find_str(options, "biases", 0);
    parse_data(biases, layer->biases, n);
    parse_data(weights, layer->filters, c*n*size*size);
    parse_data(biases, layer->biases, n);
    #ifdef GPU
    push_convolutional_layer(*layer);
    #endif
    option_unused(options);
    return layer;
}
connected_layer *parse_connected(list *options, network *net, int count)
{
    int i;
    int input;
    float learning_rate, momentum, decay;
    int output = option_find_int(options, "output",1);
@@ -147,27 +131,13 @@
        input =  get_network_output_size_layer(*net, count-1);
    }
    connected_layer *layer = make_connected_layer(net->batch, input, output, activation,learning_rate,momentum,decay);
    char *data = option_find_str(options, "data", 0);
    if(data){
        char *curr = data;
        char *next = data;
        for(i = 0; i < output; ++i){
            while(*++next !='\0' && *next != ',');
            *next = '\0';
            sscanf(curr, "%g", &layer->biases[i]);
            curr = next+1;
        }
        for(i = 0; i < input*output; ++i){
            while(*++next !='\0' && *next != ',');
            *next = '\0';
            sscanf(curr, "%g", &layer->weights[i]);
            curr = next+1;
        }
    }
    char *weights = option_find_str(options, "weights", 0);
    char *biases = option_find_str(options, "biases", 0);
    parse_data(biases, layer->biases, output);
    parse_data(weights, layer->weights, input*output);
    #ifdef GPU
    push_connected_layer(*layer);
    #endif
    option_unused(options);
    return layer;
}
@@ -195,7 +165,9 @@
    }else{
        input =  get_network_output_size_layer(*net, count-1);
    }
    cost_layer *layer = make_cost_layer(net->batch, input);
    char *type_s = option_find_str(options, "type", "sse");
    COST_TYPE type = get_cost_type(type_s);
    cost_layer *layer = make_cost_layer(net->batch, input, type);
    option_unused(options);
    return layer;
}
@@ -595,7 +567,7 @@
void print_cost_cfg(FILE *fp, cost_layer *l, network net, int count)
{
    fprintf(fp, "[cost]\n");
    fprintf(fp, "[cost]\ntype=%s\n", get_cost_string(l->type));
    if(count == 0) fprintf(fp, "batch=%d\ninput=%d\n", l->batch, l->inputs);
    fprintf(fp, "\n");
}