Skip to content

Commit b6aaff5

Browse files
Output logfile while training
1 parent e2c3017 commit b6aaff5

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

examples/detector.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <stdio.h>
12
#include "darknet.h"
23

34
static int coco_ids[] = {1,2,3,4,5,6,7,8,9,10,11,13,14,15,16,17,18,19,20,21,22,23,24,25,27,28,31,32,33,34,35,36,37,38,39,40,41,42,43,44,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,67,70,72,73,74,75,76,77,78,79,80,81,82,84,85,86,87,88,89,90};
@@ -58,7 +59,17 @@ void train_detector(char *datacfg, char *cfgfile, char *weightfile, int *gpus, i
5859
pthread_t load_thread = load_data(args);
5960
double time;
6061
int count = 0;
61-
//while(i*imgs < N*120){
62+
63+
const char* logfname = "/train_log.csv";
64+
char* logfpath = malloc(strlen(backup_directory) + strlen(logfname));
65+
strcpy(logfpath, backup_directory);
66+
strcat(logfpath, logfname);
67+
FILE *logfile = fopen(logfpath, "w");
68+
printf("Writing log to %s\n", logfpath);
69+
if (logfile == NULL)
70+
printf("Could not open logfile for writing!!\n");
71+
fprintf(logfile, "Batch, Loss, Smooth Loss, Rate, Batch Time, Images Seen\n");
72+
fflush(logfile);
6273
while(get_current_batch(net) < net->max_batches){
6374
if(l.random && count++%10 == 0){
6475
printf("Resizing\n");
@@ -127,6 +138,8 @@ void train_detector(char *datacfg, char *cfgfile, char *weightfile, int *gpus, i
127138

128139
i = get_current_batch(net);
129140
printf("%ld: %f, %f avg, %f rate, %lf seconds, %d images\n", get_current_batch(net), loss, avg_loss, get_current_rate(net), what_time_is_it_now()-time, i*imgs);
141+
fprintf(logfile, "%ld, %f, %f, %f, %lf, %d\n", get_current_batch(net), loss, avg_loss, get_current_rate(net), what_time_is_it_now()-time, i*imgs);
142+
fflush(logfile);
130143
if(i%100==0){
131144
#ifdef GPU
132145
if(ngpus != 1) sync_nets(nets, ngpus, 0);

0 commit comments

Comments
 (0)