| | |
| | | |
| | | void train_detection(char *cfgfile, char *weightfile) |
| | | { |
| | | char *train_images = "/home/pjreddie/data/voc/test/train.txt"; |
| | | char *backup_directory = "/home/pjreddie/backup/"; |
| | | srand(time(0)); |
| | | data_seed = time(0); |
| | | char *base = basecfg(cfgfile); |
| | |
| | | int side = sqrt(get_detection_layer_locations(layer)); |
| | | |
| | | char **paths; |
| | | list *plist = get_paths("/home/pjreddie/data/voc/test/train.txt"); |
| | | list *plist = get_paths(train_images); |
| | | int N = plist->size; |
| | | |
| | | paths = (char **)list_to_array(plist); |
| | |
| | | fprintf(stderr, "Starting second stage...\n"); |
| | | net.learning_rate *= 10; |
| | | char buff[256]; |
| | | sprintf(buff, "/home/pjreddie/imagenet_backup/%s_first_stage.weights", base); |
| | | sprintf(buff, "%s/%s_first_stage.weights", backup_directory, base); |
| | | save_weights(net, buff); |
| | | } |
| | | if((i-1)*imgs <= 80*N && i*imgs > N*80){ |
| | | fprintf(stderr, "Second stage done.\n"); |
| | | net.learning_rate *= .1; |
| | | char buff[256]; |
| | | sprintf(buff, "/home/pjreddie/imagenet_backup/%s_second_stage.weights", base); |
| | | sprintf(buff, "%s/%s_second_stage.weights", backup_directory, base); |
| | | save_weights(net, buff); |
| | | return; |
| | | } |
| | | if(i%1000==0){ |
| | | char buff[256]; |
| | | sprintf(buff, "/home/pjreddie/imagenet_backup/%s_%d.weights",base, i); |
| | | sprintf(buff, "%s/%s_%d.weights", backup_directory, base, i); |
| | | save_weights(net, buff); |
| | | } |
| | | free_data(train); |
| | | } |
| | | char buff[256]; |
| | | sprintf(buff, "/home/pjreddie/imagenet_backup/%s_final.weights",base); |
| | | sprintf(buff, "%s/%s_final.weights", backup_directory, base); |
| | | save_weights(net, buff); |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | void do_nms(box *boxes, float **probs, int num_boxes, int classes, float thresh) |
| | | { |
| | | int i, j, k; |
| | | for(i = 0; i < num_boxes*num_boxes; ++i){ |
| | | int any = 0; |
| | | for(k = 0; k < classes; ++k) any = any || (probs[i][k] > 0); |
| | | if(!any) { |
| | | continue; |
| | | } |
| | | for(j = i+1; j < num_boxes*num_boxes; ++j){ |
| | | if (box_iou(boxes[i], boxes[j]) > thresh){ |
| | | for(k = 0; k < classes; ++k){ |
| | | if (probs[i][k] < probs[j][k]) probs[i][k] = 0; |
| | | else probs[j][k] = 0; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | void print_detections(FILE **fps, char *id, box *boxes, float **probs, int num_boxes, int classes, int w, int h) |
| | | { |
| | | int i, j; |