void valid_go(char *cfgfile, char *weightfile, int multi) { srand(time(0)); char *base = basecfg(cfgfile); printf("%s\n", base); network net = parse_network_cfg(cfgfile); if(weightfile){ load_weights(&net, weightfile); } set_batch_network(&net, 1); printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net.learning_rate, net.momentum, net.decay); float *board = calloc(19*19, sizeof(float)); float *move = calloc(19*19, sizeof(float)); moves m = load_go_moves("/home/pjreddie/backup/go.test"); int N = m.n; int i; int correct = 0; for(i = 0; i <N; ++i){ char *b = m.data[i]; int row = b[0]; int col = b[1]; int truth = col + 19*row; string_to_board(b+2, board); predict_move(net, board, move, multi); int index = max_index(move, 19*19); if(index == truth) ++correct; printf("%d Accuracy %f\n", i, (float) correct/(i+1)); } }
void train_go(char *cfgfile, char *weightfile) { data_seed = time(0); srand(time(0)); float avg_loss = -1; char *base = basecfg(cfgfile); printf("%s\n", base); network net = parse_network_cfg(cfgfile); if(weightfile){ load_weights(&net, weightfile); } printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net.learning_rate, net.momentum, net.decay); char *backup_directory = "/home/pjreddie/backup/"; char buff[256]; float *board = calloc(19*19*net.batch, sizeof(float)); float *move = calloc(19*19*net.batch, sizeof(float)); moves m = load_go_moves("/home/pjreddie/go.train"); //moves m = load_go_moves("games.txt"); int N = m.n; int epoch = (*net.seen)/N; while(get_current_batch(net) < net.max_batches || net.max_batches == 0){ clock_t time=clock(); random_go_moves(m, board, move, net.batch); float loss = train_network_datum(net, board, move) / net.batch; if(avg_loss == -1) avg_loss = loss; avg_loss = avg_loss*.95 + loss*.05; printf("%d, %.3f: %f, %f avg, %f rate, %lf seconds, %d images\n", get_current_batch(net), (float)(*net.seen)/N, loss, avg_loss, get_current_rate(net), sec(clock()-time), *net.seen); if(*net.seen/N > epoch){ epoch = *net.seen/N; char buff[256]; sprintf(buff, "%s/%s_%d.weights", backup_directory,base, epoch); save_weights(net, buff); } if(get_current_batch(net)%100 == 0){ char buff[256]; sprintf(buff, "%s/%s.backup",backup_directory,base); save_weights(net, buff); } if(get_current_batch(net)%10000 == 0){ char buff[256]; sprintf(buff, "%s/%s_%d.backup",backup_directory,base,get_current_batch(net)); save_weights(net, buff); } } sprintf(buff, "%s/%s.weights", backup_directory, base); save_weights(net, buff); free_network(net); free(base); }