Joseph Redmon
2016-03-14 bfa970560649192cbbd26bc442ffe406e8721e8a
cifar and go stuff
4 files modified
2 files added
295 ■■■■■ changed files
Makefile 4 ●●●● patch | view | raw | blame | history
cfg/cifar.cfg 126 ●●●●● patch | view | raw | blame | history
cfg/cifar.test.cfg 119 ●●●●● patch | view | raw | blame | history
src/classifier.c 2 ●●● patch | view | raw | blame | history
src/data.c 6 ●●●●● patch | view | raw | blame | history
src/go.c 38 ●●●● patch | view | raw | blame | history
Makefile
@@ -1,5 +1,5 @@
GPU=0
OPENCV=0
GPU=1
OPENCV=1
DEBUG=0
ARCH= --gpu-architecture=compute_20 --gpu-code=compute_20 
cfg/cifar.cfg
New file
@@ -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]
cfg/cifar.test.cfg
New file
@@ -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]
src/classifier.c
@@ -410,7 +410,7 @@
    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);
src/data.c
@@ -917,8 +917,8 @@
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 @@
            X.vals[count][i] = val;
        }
        ++count;
        free(label);
        free(board);
    }
    X = resize_matrix(X, count);
    y = resize_matrix(y, count);
src/go.c
@@ -23,7 +23,11 @@
    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 @@
            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 @@
            save_weights(net, buff);
        }
    }
    char buff[256];
    sprintf(buff, "%s/%s.weights", backup_directory, base);
    save_weights(net, buff);
@@ -122,9 +129,9 @@
    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 @@
        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 @@
        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 @@
            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 @@
        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 @@
            if (c == 'p'){
                flip_board(board);
                color = -color;
                free(line);
                continue;
            }else{
                char g;
@@ -232,8 +252,10 @@
            if (col > 7) col -= 1;
            board[row*19 + col] = 1;
        }else{
            free(line);
            continue;
        }
        free(line);
        update_board(board);
        flip_board(board);
        color = -color;