From 38bd6ae6ba24fc8c14fd61d1238ae94a983434b3 Mon Sep 17 00:00:00 2001 From: Joseph Redmon Date: Mon, 20 Jul 2015 16:16:26 -0700 Subject: [PATCH] Better partial function --- src/darknet.c | 2 +- src/parser.c | 8 ++++++-- src/parser.h | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/darknet.c b/src/darknet.c index a34ccfba..321b5a9f 100644 --- a/src/darknet.c +++ b/src/darknet.c @@ -36,7 +36,7 @@ void partial(char *cfgfile, char *weightfile, char *outfile, int max) load_weights_upto(&net, weightfile, max); } net.seen = 0; - save_weights(net, outfile); + save_weights_upto(net, outfile, max); } #include "convolutional_layer.h" diff --git a/src/parser.c b/src/parser.c index 2a82ee70..5591dc3c 100644 --- a/src/parser.c +++ b/src/parser.c @@ -500,7 +500,7 @@ list *read_cfg(char *filename) return sections; } -void save_weights(network net, char *filename) +void save_weights_upto(network net, char *filename, int cutoff) { fprintf(stderr, "Saving weights to %s\n", filename); FILE *fp = fopen(filename, "w"); @@ -512,7 +512,7 @@ void save_weights(network net, char *filename) fwrite(&net.seen, sizeof(int), 1, fp); int i; - for(i = 0; i < net.n; ++i){ + for(i = 0; i < net.n && i < cutoff; ++i){ layer l = net.layers[i]; if(l.type == CONVOLUTIONAL){ #ifdef GPU @@ -546,6 +546,10 @@ void save_weights(network net, char *filename) } fclose(fp); } +void save_weights(network net, char *filename) +{ + save_weights_upto(net, filename, net.n); +} void load_weights_upto(network *net, char *filename, int cutoff) { diff --git a/src/parser.h b/src/parser.h index b16cc037..fe9e5c47 100644 --- a/src/parser.h +++ b/src/parser.h @@ -5,6 +5,7 @@ network parse_network_cfg(char *filename); void save_network(network net, char *filename); void save_weights(network net, char *filename); +void save_weights_upto(network net, char *filename, int cutoff); void load_weights(network *net, char *filename); void load_weights_upto(network *net, char *filename, int cutoff);