mirror of
https://github.com/pjreddie/darknet.git
synced 2023-08-10 21:13:14 +03:00
cifar and go stuff
This commit is contained in:
parent
3439232730
commit
bfa9705606
4
Makefile
4
Makefile
@ -1,5 +1,5 @@
|
|||||||
GPU=0
|
GPU=1
|
||||||
OPENCV=0
|
OPENCV=1
|
||||||
DEBUG=0
|
DEBUG=0
|
||||||
|
|
||||||
ARCH= --gpu-architecture=compute_20 --gpu-code=compute_20
|
ARCH= --gpu-architecture=compute_20 --gpu-code=compute_20
|
||||||
|
126
cfg/cifar.cfg
Normal file
126
cfg/cifar.cfg
Normal 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]
|
||||||
|
|
119
cfg/cifar.test.cfg
Normal file
119
cfg/cifar.test.cfg
Normal 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]
|
||||||
|
|
@ -410,7 +410,7 @@ void validate_classifier_multi(char *datacfg, char *filename, char *weightfile)
|
|||||||
|
|
||||||
char **labels = get_labels(label_list);
|
char **labels = get_labels(label_list);
|
||||||
list *plist = get_paths(valid_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]);
|
int nscales = sizeof(scales)/sizeof(scales[0]);
|
||||||
|
|
||||||
char **paths = (char **)list_to_array(plist);
|
char **paths = (char **)list_to_array(plist);
|
||||||
|
@ -917,8 +917,8 @@ data load_all_cifar10()
|
|||||||
data load_go(char *filename)
|
data load_go(char *filename)
|
||||||
{
|
{
|
||||||
FILE *fp = fopen(filename, "rb");
|
FILE *fp = fopen(filename, "rb");
|
||||||
matrix X = make_matrix(128, 361);
|
matrix X = make_matrix(3363059, 361);
|
||||||
matrix y = make_matrix(128, 361);
|
matrix y = make_matrix(3363059, 361);
|
||||||
int row, col;
|
int row, col;
|
||||||
|
|
||||||
if(!fp) file_error(filename);
|
if(!fp) file_error(filename);
|
||||||
@ -943,6 +943,8 @@ data load_go(char *filename)
|
|||||||
X.vals[count][i] = val;
|
X.vals[count][i] = val;
|
||||||
}
|
}
|
||||||
++count;
|
++count;
|
||||||
|
free(label);
|
||||||
|
free(board);
|
||||||
}
|
}
|
||||||
X = resize_matrix(X, count);
|
X = resize_matrix(X, count);
|
||||||
y = resize_matrix(y, count);
|
y = resize_matrix(y, count);
|
||||||
|
38
src/go.c
38
src/go.c
@ -23,7 +23,11 @@ void train_go(char *cfgfile, char *weightfile)
|
|||||||
|
|
||||||
char *backup_directory = "/home/pjreddie/backup/";
|
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 N = train.X.rows;
|
||||||
int epoch = (*net.seen)/N;
|
int epoch = (*net.seen)/N;
|
||||||
while(get_current_batch(net) < net.max_batches || net.max_batches == 0){
|
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];
|
char buff[256];
|
||||||
sprintf(buff, "%s/%s_%d.weights",backup_directory,base, epoch);
|
sprintf(buff, "%s/%s_%d.weights",backup_directory,base, epoch);
|
||||||
save_weights(net, buff);
|
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){
|
if(get_current_batch(net)%100 == 0){
|
||||||
char buff[256];
|
char buff[256];
|
||||||
@ -65,7 +73,6 @@ void train_go(char *cfgfile, char *weightfile)
|
|||||||
save_weights(net, buff);
|
save_weights(net, buff);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
char buff[256];
|
|
||||||
sprintf(buff, "%s/%s.weights", backup_directory, base);
|
sprintf(buff, "%s/%s.weights", backup_directory, base);
|
||||||
save_weights(net, buff);
|
save_weights(net, buff);
|
||||||
|
|
||||||
@ -122,9 +129,9 @@ void update_board(float *board)
|
|||||||
free(l);
|
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("\n\n");
|
||||||
printf(" ");
|
printf(" ");
|
||||||
for(i = 0; i < 19; ++i){
|
for(i = 0; i < 19; ++i){
|
||||||
@ -135,9 +142,21 @@ void print_board(float *board, int swap)
|
|||||||
printf("%2d ", 19-j);
|
printf("%2d ", 19-j);
|
||||||
for(i = 0; i < 19; ++i){
|
for(i = 0; i < 19; ++i){
|
||||||
int index = j*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 ");
|
if(board[index]*-swap > 0) printf("\u25C9 ");
|
||||||
else if(board[index]*-swap < 0) printf("\u25EF ");
|
else if(board[index]*-swap < 0) printf("\u25EF ");
|
||||||
else printf(" ");
|
else printf("\uFF0b");
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
@ -166,7 +185,7 @@ void test_go(char *filename, char *weightfile)
|
|||||||
float *output = network_predict(net, board);
|
float *output = network_predict(net, board);
|
||||||
copy_cpu(19*19, output, 1, move, 1);
|
copy_cpu(19*19, output, 1, move, 1);
|
||||||
int i;
|
int i;
|
||||||
#ifdef GPU
|
#ifdef GPU
|
||||||
image bim = float_to_image(19, 19, 1, board);
|
image bim = float_to_image(19, 19, 1, board);
|
||||||
for(i = 1; i < 8; ++i){
|
for(i = 1; i < 8; ++i){
|
||||||
rotate_image_cw(bim, i);
|
rotate_image_cw(bim, i);
|
||||||
@ -184,7 +203,7 @@ void test_go(char *filename, char *weightfile)
|
|||||||
rotate_image_cw(bim, -i);
|
rotate_image_cw(bim, -i);
|
||||||
}
|
}
|
||||||
scal_cpu(19*19, 1./8., move, 1);
|
scal_cpu(19*19, 1./8., move, 1);
|
||||||
#endif
|
#endif
|
||||||
for(i = 0; i < 19*19; ++i){
|
for(i = 0; i < 19*19; ++i){
|
||||||
if(board[i]) move[i] = 0;
|
if(board[i]) move[i] = 0;
|
||||||
}
|
}
|
||||||
@ -192,7 +211,7 @@ void test_go(char *filename, char *weightfile)
|
|||||||
int indexes[3];
|
int indexes[3];
|
||||||
int row, col;
|
int row, col;
|
||||||
top_k(move, 19*19, 3, indexes);
|
top_k(move, 19*19, 3, indexes);
|
||||||
print_board(board, color);
|
print_board(board, color, indexes);
|
||||||
for(i = 0; i < 3; ++i){
|
for(i = 0; i < 3; ++i){
|
||||||
int index = indexes[i];
|
int index = indexes[i];
|
||||||
row = index / 19;
|
row = index / 19;
|
||||||
@ -217,6 +236,7 @@ void test_go(char *filename, char *weightfile)
|
|||||||
if (c == 'p'){
|
if (c == 'p'){
|
||||||
flip_board(board);
|
flip_board(board);
|
||||||
color = -color;
|
color = -color;
|
||||||
|
free(line);
|
||||||
continue;
|
continue;
|
||||||
}else{
|
}else{
|
||||||
char g;
|
char g;
|
||||||
@ -232,8 +252,10 @@ void test_go(char *filename, char *weightfile)
|
|||||||
if (col > 7) col -= 1;
|
if (col > 7) col -= 1;
|
||||||
board[row*19 + col] = 1;
|
board[row*19 + col] = 1;
|
||||||
}else{
|
}else{
|
||||||
|
free(line);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
free(line);
|
||||||
update_board(board);
|
update_board(board);
|
||||||
flip_board(board);
|
flip_board(board);
|
||||||
color = -color;
|
color = -color;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user