| | |
| | | //net.seen=0; |
| | | int imgs = 1024; |
| | | int i = net.seen/imgs; |
| | | int solved = 1; |
| | | int solved = 0; |
| | | list *plist; |
| | | char **labels = get_labels("/data/captcha/reimgs.labels2.list"); |
| | | if (solved){ |
| | | plist = get_paths("/data/captcha/reimgs.solved.list"); |
| | | }else{ |
| | | plist = get_paths("/data/captcha/reimgs.train.list"); |
| | | plist = get_paths("/data/captcha/reimgs.raw.list"); |
| | | } |
| | | char **paths = (char **)list_to_array(plist); |
| | | printf("%d\n", plist->size); |
| | |
| | | srand(2222222); |
| | | int i = 0; |
| | | char **names = get_labels("/data/captcha/reimgs.labels2.list"); |
| | | clock_t time; |
| | | char input[256]; |
| | | int indexes[26]; |
| | | while(1){ |
| | |
| | | } |
| | | image im = load_image_color(input, net.w, net.h); |
| | | float *X = im.data; |
| | | time=clock(); |
| | | float *predictions = network_predict(net, X); |
| | | top_predictions(net, 26, indexes); |
| | | //printf("%s: Predicted in %f seconds.\n", input, sec(clock()-time)); |
| | |
| | | } |
| | | } |
| | | |
| | | void valid_captcha(char *cfgfile, char *weightfile, char *filename) |
| | | { |
| | | char **labels = get_labels("/data/captcha/reimgs.labels.list"); |
| | | network net = parse_network_cfg(cfgfile); |
| | | if(weightfile){ |
| | | load_weights(&net, weightfile); |
| | | } |
| | | list *plist = get_paths("/data/captcha/reimgs.fg.list"); |
| | | char **paths = (char **)list_to_array(plist); |
| | | int N = plist->size; |
| | | int outputs = net.outputs; |
| | | |
| | | set_batch_network(&net, 1); |
| | | srand(2222222); |
| | | int i, j; |
| | | for(i = 0; i < N; ++i){ |
| | | if (i%100 == 0) fprintf(stderr, "%d\n", i); |
| | | image im = load_image_color(paths[i], net.w, net.h); |
| | | float *X = im.data; |
| | | float *predictions = network_predict(net, X); |
| | | //printf("%s: Predicted in %f seconds.\n", input, sec(clock()-time)); |
| | | int truth = -1; |
| | | for(j = 0; j < 13; ++j){ |
| | | if (strstr(paths[i], labels[j])) truth = j; |
| | | } |
| | | if (truth == -1){ |
| | | fprintf(stderr, "bad: %s\n", paths[i]); |
| | | return; |
| | | } |
| | | printf("%d, ", truth); |
| | | for(j = 0; j < outputs; ++j){ |
| | | if (j != 0) printf(", "); |
| | | printf("%f", predictions[j]); |
| | | } |
| | | printf("\n"); |
| | | fflush(stdout); |
| | | free_image(im); |
| | | if (filename) break; |
| | | } |
| | | } |
| | | |
| | | void train_captcha(char *cfgfile, char *weightfile) |
| | | { |
| | | data_seed = time(0); |
| | |
| | | srand(2222222); |
| | | int i = 0; |
| | | char **names = get_labels("/data/captcha/reimgs.labels.list"); |
| | | clock_t time; |
| | | char input[256]; |
| | | int indexes[13]; |
| | | while(1){ |
| | |
| | | } |
| | | image im = load_image_color(input, net.w, net.h); |
| | | float *X = im.data; |
| | | time=clock(); |
| | | float *predictions = network_predict(net, X); |
| | | top_predictions(net, 13, indexes); |
| | | //printf("%s: Predicted in %f seconds.\n", input, sec(clock()-time)); |
| | |
| | | char *filename = (argc > 5) ? argv[5]: 0; |
| | | if(0==strcmp(argv[2], "train")) train_captcha2(cfg, weights); |
| | | else if(0==strcmp(argv[2], "test")) test_captcha2(cfg, weights, filename); |
| | | else if(0==strcmp(argv[2], "valid")) valid_captcha(cfg, weights, filename); |
| | | //if(0==strcmp(argv[2], "test")) test_captcha(cfg, weights); |
| | | //else if(0==strcmp(argv[2], "encode")) encode_captcha(cfg, weights); |
| | | //else if(0==strcmp(argv[2], "decode")) decode_captcha(cfg, weights); |