5 files modified
2 files deleted
| | |
| | | momentum=0.9 |
| | | decay=0.0005 |
| | | |
| | | learning_rate=0.01 |
| | | policy=sigmoid |
| | | gamma=.00002 |
| | | step=400000 |
| | | max_batches=800000 |
| | | learning_rate=0.1 |
| | | policy=poly |
| | | power=4 |
| | | max_batches=500000 |
| | | |
| | | [crop] |
| | | crop_height=224 |
| | |
| | | exposure=1 |
| | | |
| | | [convolutional] |
| | | batch_normalize=1 |
| | | filters=16 |
| | | size=3 |
| | | stride=1 |
| | |
| | | stride=2 |
| | | |
| | | [convolutional] |
| | | batch_normalize=1 |
| | | filters=32 |
| | | size=3 |
| | | stride=1 |
| | |
| | | stride=2 |
| | | |
| | | [convolutional] |
| | | batch_normalize=1 |
| | | filters=64 |
| | | size=3 |
| | | stride=1 |
| | |
| | | stride=2 |
| | | |
| | | [convolutional] |
| | | batch_normalize=1 |
| | | filters=128 |
| | | size=3 |
| | | stride=1 |
| | |
| | | stride=2 |
| | | |
| | | [convolutional] |
| | | batch_normalize=1 |
| | | filters=256 |
| | | size=3 |
| | | stride=1 |
| | |
| | | stride=2 |
| | | |
| | | [convolutional] |
| | | batch_normalize=1 |
| | | filters=512 |
| | | size=3 |
| | | stride=1 |
| | |
| | | stride=2 |
| | | |
| | | [convolutional] |
| | | batch_normalize=1 |
| | | filters=1024 |
| | | size=3 |
| | | stride=1 |
| | |
| | | } |
| | | } |
| | | |
| | | #ifdef OPENCV |
| | | #ifdef GPU |
| | | void demo_coco(char *cfgfile, char *weightfile, float thresh, int cam_index); |
| | | #endif |
| | | #endif |
| | | void demo_coco(char *cfgfile, char *weightfile, float thresh, int cam_index, char *filename); |
| | | static void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, char* filename) |
| | | { |
| | | #if defined(OPENCV) && defined(GPU) |
| | | demo_coco(cfgfile, weightfile, thresh, cam_index, filename); |
| | | #else |
| | | fprintf(stderr, "Need to compile with GPU and OpenCV for demo.\n"); |
| | | #endif |
| | | } |
| | | |
| | | void run_coco(int argc, char **argv) |
| | | { |
| | |
| | | } |
| | | float thresh = find_float_arg(argc, argv, "-thresh", .2); |
| | | int cam_index = find_int_arg(argc, argv, "-c", 0); |
| | | char *file = find_char_arg(argc, argv, "-file", 0); |
| | | |
| | | if(argc < 4){ |
| | | fprintf(stderr, "usage: %s %s [train/test/valid] [cfg] [weights (optional)]\n", argv[0], argv[1]); |
| | |
| | | else if(0==strcmp(argv[2], "train")) train_coco(cfg, weights); |
| | | else if(0==strcmp(argv[2], "valid")) validate_coco(cfg, weights); |
| | | else if(0==strcmp(argv[2], "recall")) validate_coco_recall(cfg, weights); |
| | | #ifdef OPENCV |
| | | #ifdef GPU |
| | | else if(0==strcmp(argv[2], "demo")) demo_coco(cfg, weights, thresh, cam_index); |
| | | #endif |
| | | #endif |
| | | else if(0==strcmp(argv[2], "demo")) demo(cfg, weights, thresh, cam_index, file); |
| | | } |
| | |
| | | static float fps = 0; |
| | | static float demo_thresh = 0; |
| | | |
| | | static const int frames = 3; |
| | | static float *predictions[frames]; |
| | | static int demo_index = 0; |
| | | static image images[frames]; |
| | | static float *avg; |
| | | |
| | | void *fetch_in_thread_coco(void *ptr) |
| | | { |
| | | cv::Mat frame_m; |
| | |
| | | |
| | | detection_layer l = net.layers[net.n-1]; |
| | | float *X = det_s.data; |
| | | float *predictions = network_predict(net, X); |
| | | float *prediction = network_predict(net, X); |
| | | |
| | | memcpy(predictions[demo_index], prediction, l.outputs*sizeof(float)); |
| | | mean_arrays(predictions, frames, l.outputs, avg); |
| | | |
| | | free_image(det_s); |
| | | convert_coco_detections(predictions, l.classes, l.n, l.sqrt, l.side, 1, 1, demo_thresh, probs, boxes, 0); |
| | | convert_coco_detections(avg, l.classes, l.n, l.sqrt, l.side, 1, 1, demo_thresh, probs, boxes, 0); |
| | | if (nms > 0) do_nms(boxes, probs, l.side*l.side*l.n, l.classes, nms); |
| | | printf("\033[2J"); |
| | | printf("\033[1;1H"); |
| | | printf("\nFPS:%.0f\n",fps); |
| | | printf("Objects:\n\n"); |
| | | |
| | | images[demo_index] = det; |
| | | det = images[(demo_index + frames/2 + 1)%frames]; |
| | | demo_index = (demo_index + 1)%frames; |
| | | |
| | | draw_detections(det, l.side*l.side*l.n, demo_thresh, boxes, probs, coco_classes, coco_labels, 80); |
| | | return 0; |
| | | } |
| | | |
| | | extern "C" void demo_coco(char *cfgfile, char *weightfile, float thresh, int cam_index) |
| | | extern "C" void demo_coco(char *cfgfile, char *weightfile, float thresh, int cam_index, const char *filename) |
| | | { |
| | | demo_thresh = thresh; |
| | | printf("YOLO demo\n"); |
| | |
| | | |
| | | srand(2222222); |
| | | |
| | | cv::VideoCapture cam(cam_index); |
| | | cap = cam; |
| | | if(filename){ |
| | | cap.open(filename); |
| | | }else{ |
| | | cap.open(cam_index); |
| | | } |
| | | |
| | | if(!cap.isOpened()) error("Couldn't connect to webcam.\n"); |
| | | |
| | | detection_layer l = net.layers[net.n-1]; |
| | | int j; |
| | | |
| | | avg = (float *) calloc(l.outputs, sizeof(float)); |
| | | for(j = 0; j < frames; ++j) predictions[j] = (float *) calloc(l.outputs, sizeof(float)); |
| | | for(j = 0; j < frames; ++j) images[j] = make_image(1,1,3); |
| | | |
| | | boxes = (box *)calloc(l.side*l.side*l.n, sizeof(box)); |
| | | probs = (float **)calloc(l.side*l.side*l.n, sizeof(float *)); |
| | | for(j = 0; j < l.side*l.side*l.n; ++j) probs[j] = (float *)calloc(l.classes, sizeof(float *)); |
| | |
| | | return sum_array(a,n)/n; |
| | | } |
| | | |
| | | void mean_arrays(float **a, int n, int els, float *avg) |
| | | { |
| | | int i; |
| | | int j; |
| | | memset(avg, 0, els*sizeof(float)); |
| | | for(j = 0; j < n; ++j){ |
| | | for(i = 0; i < els; ++i){ |
| | | avg[i] += a[j][i]; |
| | | } |
| | | } |
| | | for(i = 0; i < els; ++i){ |
| | | avg[i] /= n; |
| | | } |
| | | } |
| | | |
| | | float variance_array(float *a, int n) |
| | | { |
| | | int i; |
| | |
| | | float rand_uniform(); |
| | | float sum_array(float *a, int n); |
| | | float mean_array(float *a, int n); |
| | | void mean_arrays(float **a, int n, int els, float *avg); |
| | | float variance_array(float *a, int n); |
| | | float mag_array(float *a, int n); |
| | | float **one_hot_encode(float *a, int n, int k); |