From bfa970560649192cbbd26bc442ffe406e8721e8a Mon Sep 17 00:00:00 2001 From: Joseph Redmon Date: Mon, 14 Mar 2016 15:08:56 -0700 Subject: [PATCH] cifar and go stuff --- Makefile | 4 +- cfg/cifar.cfg | 126 +++++++++++++++++++++++++++++++++++++++++++++ cfg/cifar.test.cfg | 119 ++++++++++++++++++++++++++++++++++++++++++ src/classifier.c | 2 +- src/data.c | 6 ++- src/go.c | 38 +++++++++++--- 6 files changed, 282 insertions(+), 13 deletions(-) create mode 100644 cfg/cifar.cfg create mode 100644 cfg/cifar.test.cfg diff --git a/Makefile b/Makefile index 2ecf6cc1..cd3edcd6 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -GPU=0 -OPENCV=0 +GPU=1 +OPENCV=1 DEBUG=0 ARCH= --gpu-architecture=compute_20 --gpu-code=compute_20 diff --git a/cfg/cifar.cfg b/cfg/cifar.cfg new file mode 100644 index 00000000..f2c801a5 --- /dev/null +++ b/cfg/cifar.cfg @@ -0,0 +1,126 @@ +[net] +batch=128 +subdivisions=1 +height=32 +width=32 +channels=3 +momentum=0.9 +decay=0.0005 + +learning_rate=0.4 +policy=poly +power=4 +max_batches = 50000 + +[crop] +crop_width=28 +crop_height=28 +flip=1 +angle=0 +saturation = 1 +exposure = 1 +noadjust=1 + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[dropout] +probability=.5 + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[dropout] +probability=.5 + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[dropout] +probability=.5 + +[convolutional] +filters=10 +size=1 +stride=1 +pad=1 +activation=leaky + +[avgpool] + +[softmax] +groups=1 + +[cost] + diff --git a/cfg/cifar.test.cfg b/cfg/cifar.test.cfg new file mode 100644 index 00000000..d3afcdd7 --- /dev/null +++ b/cfg/cifar.test.cfg @@ -0,0 +1,119 @@ +[net] +batch=128 +subdivisions=1 +height=32 +width=32 +channels=3 +momentum=0.9 +decay=0.0005 + +learning_rate=0.4 +policy=poly +power=4 +max_batches = 50000 + + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[dropout] +probability=.5 + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[maxpool] +size=2 +stride=2 + +[dropout] +probability=.5 + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[dropout] +probability=.5 + +[convolutional] +filters=10 +size=1 +stride=1 +pad=1 +activation=leaky + +[avgpool] + +[softmax] +groups=1 +temperature=3 + +[cost] + diff --git a/src/classifier.c b/src/classifier.c index 2e974a52..efed514d 100644 --- a/src/classifier.c +++ b/src/classifier.c @@ -410,7 +410,7 @@ void validate_classifier_multi(char *datacfg, char *filename, char *weightfile) char **labels = get_labels(label_list); list *plist = get_paths(valid_list); - int scales[] = {192, 224, 288, 320, 352}; + int scales[] = {160, 192, 224, 288, 320, 352, 384}; int nscales = sizeof(scales)/sizeof(scales[0]); char **paths = (char **)list_to_array(plist); diff --git a/src/data.c b/src/data.c index 8cd3f26d..4d52d11a 100644 --- a/src/data.c +++ b/src/data.c @@ -917,8 +917,8 @@ data load_all_cifar10() data load_go(char *filename) { FILE *fp = fopen(filename, "rb"); - matrix X = make_matrix(128, 361); - matrix y = make_matrix(128, 361); + matrix X = make_matrix(3363059, 361); + matrix y = make_matrix(3363059, 361); int row, col; if(!fp) file_error(filename); @@ -943,6 +943,8 @@ data load_go(char *filename) X.vals[count][i] = val; } ++count; + free(label); + free(board); } X = resize_matrix(X, count); y = resize_matrix(y, count); diff --git a/src/go.c b/src/go.c index f826d1eb..62c4a78f 100644 --- a/src/go.c +++ b/src/go.c @@ -23,7 +23,11 @@ void train_go(char *cfgfile, char *weightfile) char *backup_directory = "/home/pjreddie/backup/"; - data train = load_go("/home/pjreddie/backup/go.train"); + + char buff[256]; + sprintf(buff, "/home/pjreddie/go.train.%02d", rand()%10); + data train = load_go(buff); + int N = train.X.rows; int epoch = (*net.seen)/N; while(get_current_batch(net) < net.max_batches || net.max_batches == 0){ @@ -58,6 +62,10 @@ void train_go(char *cfgfile, char *weightfile) char buff[256]; sprintf(buff, "%s/%s_%d.weights",backup_directory,base, epoch); save_weights(net, buff); + + free_data(train); + sprintf(buff, "/home/pjreddie/go.train.%02d", epoch%10); + train = load_go(buff); } if(get_current_batch(net)%100 == 0){ char buff[256]; @@ -65,7 +73,6 @@ void train_go(char *cfgfile, char *weightfile) save_weights(net, buff); } } - char buff[256]; sprintf(buff, "%s/%s.weights", backup_directory, base); save_weights(net, buff); @@ -122,9 +129,9 @@ void update_board(float *board) free(l); } -void print_board(float *board, int swap) +void print_board(float *board, int swap, int *indexes) { - int i,j; + int i,j,n; printf("\n\n"); printf(" "); for(i = 0; i < 19; ++i){ @@ -135,9 +142,21 @@ void print_board(float *board, int swap) printf("%2d ", 19-j); for(i = 0; i < 19; ++i){ int index = j*19 + i; + if(indexes){ + int found = 0; + for(n = 0; n < 3; ++n){ + if(index == indexes[n]){ + found = 1; + if(n == 0) printf("\uff11"); + else if(n == 1) printf("\uff12"); + else if(n == 2) printf("\uff13"); + } + } + if(found) continue; + } if(board[index]*-swap > 0) printf("\u25C9 "); else if(board[index]*-swap < 0) printf("\u25EF "); - else printf(" "); + else printf("\uFF0b"); } printf("\n"); } @@ -166,7 +185,7 @@ void test_go(char *filename, char *weightfile) float *output = network_predict(net, board); copy_cpu(19*19, output, 1, move, 1); int i; - #ifdef GPU +#ifdef GPU image bim = float_to_image(19, 19, 1, board); for(i = 1; i < 8; ++i){ rotate_image_cw(bim, i); @@ -184,7 +203,7 @@ void test_go(char *filename, char *weightfile) rotate_image_cw(bim, -i); } scal_cpu(19*19, 1./8., move, 1); - #endif +#endif for(i = 0; i < 19*19; ++i){ if(board[i]) move[i] = 0; } @@ -192,7 +211,7 @@ void test_go(char *filename, char *weightfile) int indexes[3]; int row, col; top_k(move, 19*19, 3, indexes); - print_board(board, color); + print_board(board, color, indexes); for(i = 0; i < 3; ++i){ int index = indexes[i]; row = index / 19; @@ -217,6 +236,7 @@ void test_go(char *filename, char *weightfile) if (c == 'p'){ flip_board(board); color = -color; + free(line); continue; }else{ char g; @@ -232,8 +252,10 @@ void test_go(char *filename, char *weightfile) if (col > 7) col -= 1; board[row*19 + col] = 1; }else{ + free(line); continue; } + free(line); update_board(board); flip_board(board); color = -color;