| | |
| | | #include "list.h" |
| | | #include "option_list.h" |
| | | #include "utils.h" |
| | | #include "opencl.h" |
| | | |
| | | typedef struct{ |
| | | char *type; |
| | |
| | | |
| | | 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); |
| | |
| | | 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); |
| | |
| | | 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; |
| | | } |
| | |
| | | }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; |
| | | } |
| | |
| | | if(count == 0){ |
| | | net->batch = option_find_int(options, "batch",1); |
| | | input = option_find_int(options, "input",1); |
| | | float learning_rate = option_find_float(options, "learning_rate", .001); |
| | | float momentum = option_find_float(options, "momentum", .9); |
| | | float decay = option_find_float(options, "decay", .0001); |
| | | net->learning_rate = learning_rate; |
| | | net->momentum = momentum; |
| | | net->decay = decay; |
| | | }else{ |
| | | input = get_network_output_size_layer(*net, count-1); |
| | | } |
| | |
| | | |
| | | int read_option(char *s, list *options) |
| | | { |
| | | int i; |
| | | int len = strlen(s); |
| | | size_t i; |
| | | size_t len = strlen(s); |
| | | char *val = 0; |
| | | for(i = 0; i < len; ++i){ |
| | | if(s[i] == '='){ |
| | |
| | | |
| | | void print_convolutional_cfg(FILE *fp, convolutional_layer *l, network net, int count) |
| | | { |
| | | #ifdef GPU |
| | | if(gpu_index >= 0) pull_convolutional_layer(*l); |
| | | #endif |
| | | int i; |
| | | fprintf(fp, "[convolutional]\n"); |
| | | if(count == 0) { |
| | |
| | | |
| | | void print_connected_cfg(FILE *fp, connected_layer *l, network net, int count) |
| | | { |
| | | #ifdef GPU |
| | | if(gpu_index >= 0) pull_connected_layer(*l); |
| | | #endif |
| | | int i; |
| | | fprintf(fp, "[connected]\n"); |
| | | if(count == 0){ |
| | |
| | | |
| | | 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"); |
| | | } |