| | |
| | | int i; |
| | | clock_t start = clock(), end; |
| | | for(i = 0; i < 1000; ++i){ |
| | | im2col_cpu(dog.data, dog.c, dog.h, dog.w, size, stride, 0, matrix); |
| | | im2col_cpu(dog.data,1, dog.c, dog.h, dog.w, size, stride, 0, matrix); |
| | | gemm(0,0,n,mw,mh,1,filters,mh,matrix,mw,1,edge.data,mw); |
| | | } |
| | | end = clock(); |
| | |
| | | int size = 3; |
| | | float eps = .00000001; |
| | | image test = make_random_image(5,5, 1); |
| | | convolutional_layer layer = *make_convolutional_layer(1,test.h,test.w,test.c, n, size, stride, 0, RELU); |
| | | convolutional_layer layer = *make_convolutional_layer(1,test.h,test.w,test.c, n, size, stride, 0, RELU,0,0,0); |
| | | image out = get_convolutional_image(layer); |
| | | float **jacobian = calloc(test.h*test.w*test.c, sizeof(float)); |
| | | |
| | |
| | | |
| | | void test_parser() |
| | | { |
| | | network net = parse_network_cfg("test_parser.cfg"); |
| | | float input[1]; |
| | | int count = 0; |
| | | |
| | | float avgerr = 0; |
| | | while(++count < 100000000){ |
| | | float v = ((float)rand()/RAND_MAX); |
| | | float truth = v*v; |
| | | input[0] = v; |
| | | forward_network(net, input, 1); |
| | | float *out = get_network_output(net); |
| | | float *delta = get_network_delta(net); |
| | | float err = pow((out[0]-truth),2.); |
| | | avgerr = .99 * avgerr + .01 * err; |
| | | if(count % 1000000 == 0) printf("%f %f :%f AVG %f \n", truth, out[0], err, avgerr); |
| | | delta[0] = truth - out[0]; |
| | | backward_network(net, input, &truth); |
| | | update_network(net, .001,0,0); |
| | | } |
| | | network net = parse_network_cfg("cfg/test_parser.cfg"); |
| | | save_network(net, "cfg/test_parser_1.cfg"); |
| | | network net2 = parse_network_cfg("cfg/test_parser_1.cfg"); |
| | | save_network(net2, "cfg/test_parser_2.cfg"); |
| | | } |
| | | |
| | | void test_data() |
| | |
| | | //scale_data_rows(train, 1./255.); |
| | | normalize_data_rows(train); |
| | | clock_t start = clock(), end; |
| | | float loss = train_network_sgd(net, train, 1000, lr, momentum, decay); |
| | | float loss = train_network_sgd(net, train, 1000); |
| | | end = clock(); |
| | | printf("%d: %f, Time: %lf seconds, LR: %f, Momentum: %f, Decay: %f\n", i, loss, (float)(end-start)/CLOCKS_PER_SEC, lr, momentum, decay); |
| | | free_data(train); |
| | |
| | | |
| | | void test_cifar10() |
| | | { |
| | | data test = load_cifar10_data("images/cifar10/test_batch.bin"); |
| | | scale_data_rows(test, 1./255); |
| | | srand(222222); |
| | | network net = parse_network_cfg("cfg/cifar10.cfg"); |
| | | //data test = load_cifar10_data("data/cifar10/test_batch.bin"); |
| | | int count = 0; |
| | | float lr = .000005; |
| | | float momentum = .99; |
| | | float decay = 0.001; |
| | | decay = 0; |
| | | int batch = 10000; |
| | | int iters = 10000/net.batch; |
| | | data train = load_all_cifar10(); |
| | | while(++count <= 10000){ |
| | | char buff[256]; |
| | | sprintf(buff, "images/cifar10/data_batch_%d.bin", rand()%5+1); |
| | | data train = load_cifar10_data(buff); |
| | | scale_data_rows(train, 1./255); |
| | | train_network_sgd(net, train, batch, lr, momentum, decay); |
| | | //printf("%5f %5f\n",(double)count*batch/train.X.rows, loss); |
| | | clock_t start = clock(), end; |
| | | float loss = train_network_sgd(net, train, iters); |
| | | end = clock(); |
| | | //visualize_network(net); |
| | | //cvWaitKey(1000); |
| | | |
| | | float test_acc = network_accuracy(net, test); |
| | | printf("%5f %5f\n",(double)count*batch/train.X.rows/5, 1-test_acc); |
| | | free_data(train); |
| | | //float test_acc = network_accuracy(net, test); |
| | | //printf("%d: Loss: %f, Test Acc: %f, Time: %lf seconds, LR: %f, Momentum: %f, Decay: %f\n", count, loss, test_acc,(float)(end-start)/CLOCKS_PER_SEC, net.learning_rate, net.momentum, net.decay); |
| | | printf("%d: Loss: %f, Time: %lf seconds, LR: %f, Momentum: %f, Decay: %f\n", count, loss, (float)(end-start)/CLOCKS_PER_SEC, net.learning_rate, net.momentum, net.decay); |
| | | } |
| | | |
| | | free_data(train); |
| | | } |
| | | |
| | | void test_vince() |
| | |
| | | normalize_data_rows(train); |
| | | |
| | | int count = 0; |
| | | float lr = .00005; |
| | | float momentum = .9; |
| | | float decay = 0.0001; |
| | | decay = 0; |
| | | //float lr = .00005; |
| | | //float momentum = .9; |
| | | //float decay = 0.0001; |
| | | //decay = 0; |
| | | int batch = 10000; |
| | | while(++count <= 10000){ |
| | | float loss = train_network_sgd(net, train, batch, lr, momentum, decay); |
| | | float loss = train_network_sgd(net, train, batch); |
| | | printf("%5f %5f\n",(double)count*batch/train.X.rows, loss); |
| | | } |
| | | } |
| | | |
| | | void test_nist_single() |
| | | { |
| | | srand(222222); |
| | | network net = parse_network_cfg("cfg/nist.cfg"); |
| | | data train = load_categorical_data_csv("data/mnist/mnist_tiny.csv", 0, 10); |
| | | normalize_data_rows(train); |
| | | float loss = train_network_sgd(net, train, 5); |
| | | printf("Loss: %f, LR: %f, Momentum: %f, Decay: %f\n", loss, net.learning_rate, net.momentum, net.decay); |
| | | |
| | | } |
| | | |
| | | void test_nist() |
| | | { |
| | | srand(222222); |
| | | network net = parse_network_cfg("cfg/nist.cfg"); |
| | | data train = load_categorical_data_csv("data/mnist/mnist_train.csv", 0, 10); |
| | | data test = load_categorical_data_csv("data/mnist/mnist_test.csv",0,10); |
| | | normalize_data_rows(train); |
| | | normalize_data_rows(test); |
| | | translate_data_rows(train, -144); |
| | | scale_data_rows(train, 1./128); |
| | | translate_data_rows(test, -144); |
| | | scale_data_rows(test, 1./128); |
| | | //randomize_data(train); |
| | | int count = 0; |
| | | float lr = .0001; |
| | | float momentum = .9; |
| | | float decay = 0.0001; |
| | | //clock_t start = clock(), end; |
| | | int iters = 1000; |
| | | while(++count <= 10){ |
| | | int iters = 10000/net.batch; |
| | | while(++count <= 100){ |
| | | clock_t start = clock(), end; |
| | | float loss = train_network_sgd(net, train, iters, lr, momentum, decay); |
| | | float loss = train_network_sgd(net, train, iters); |
| | | end = clock(); |
| | | float test_acc = network_accuracy(net, test); |
| | | //float test_acc = 0; |
| | | printf("%d: Loss: %f, Test Acc: %f, Time: %lf seconds, LR: %f, Momentum: %f, Decay: %f\n", count, loss, test_acc,(float)(end-start)/CLOCKS_PER_SEC, lr, momentum, decay); |
| | | printf("%d: Loss: %f, Test Acc: %f, Time: %lf seconds, LR: %f, Momentum: %f, Decay: %f\n", count, loss, test_acc,(float)(end-start)/CLOCKS_PER_SEC, net.learning_rate, net.momentum, net.decay); |
| | | //save_network(net, "cfg/nist_basic_trained.cfg"); |
| | | |
| | | //printf("%5d Training Loss: %lf, Params: %f %f %f, ",count*1000, loss, lr, momentum, decay); |
| | | //end = clock(); |
| | |
| | | float decay = .01; |
| | | network net = parse_network_cfg("nist.cfg"); |
| | | while(++count <= 15){ |
| | | float acc = train_network_sgd(net, train, train.X.rows, lr, momentum, decay); |
| | | float acc = train_network_sgd(net, train, train.X.rows); |
| | | printf("Training Accuracy: %lf Learning Rate: %f Momentum: %f Decay: %f\n", acc, lr, momentum, decay ); |
| | | lr /= 2; |
| | | } |
| | |
| | | // printf("%f\n", delta[0]); |
| | | //printf("%f %f\n", truth[index], out[0]); |
| | | //backward_network(net, m.vals[index], ); |
| | | update_network(net, .00001, 0,0); |
| | | update_network(net); |
| | | } |
| | | //float test_acc = error_network(net, m, truth); |
| | | //float valid_acc = error_network(net, ho, ho_truth); |
| | |
| | | float *matrix = calloc(msize, sizeof(float)); |
| | | int i; |
| | | for(i = 0; i < 1000; ++i){ |
| | | im2col_cpu(test.data, c, h, w, size, stride, 0, matrix); |
| | | im2col_cpu(test.data,1, c, h, w, size, stride, 0, matrix); |
| | | //image render = float_to_image(mh, mw, mc, matrix); |
| | | } |
| | | } |
| | |
| | | |
| | | translate_data_rows(train, -144); |
| | | clock_t start = clock(), end; |
| | | float loss = train_network_sgd(net, train, 10, lr, momentum, decay); |
| | | float loss = train_network_sgd(net, train, 10); |
| | | end = clock(); |
| | | printf("%d: %f, Time: %lf seconds, LR: %f, Momentum: %f, Decay: %f\n", i, loss, (float)(end-start)/CLOCKS_PER_SEC, lr, momentum, decay); |
| | | free_data(train); |
| | |
| | | // test_im2row(); |
| | | //test_split(); |
| | | //test_ensemble(); |
| | | //test_nist_single(); |
| | | test_nist(); |
| | | //test_cifar10(); |
| | | //test_vince(); |
| | |
| | | //visualize_cat(); |
| | | //flip_network(); |
| | | //test_visualize(); |
| | | //test_parser(); |
| | | fprintf(stderr, "Success!\n"); |
| | | //test_random_preprocess(); |
| | | //test_random_classify(); |