Skip to content

Commit

Permalink
some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pjreddie committed Nov 14, 2015
1 parent 9e8a12a commit 0cd2379
Show file tree
Hide file tree
Showing 14 changed files with 817 additions and 55 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ CFLAGS+= -DGPU
LDFLAGS+= -L/usr/local/cuda/lib64 -lcuda -lcudart -lcublas -lcurand
endif

OBJ=gemm.o utils.o cuda.o deconvolutional_layer.o convolutional_layer.o list.o image.o activations.o im2col.o col2im.o blas.o crop_layer.o dropout_layer.o maxpool_layer.o softmax_layer.o data.o matrix.o network.o connected_layer.o cost_layer.o parser.o option_list.o darknet.o detection_layer.o imagenet.o captcha.o route_layer.o writing.o box.o nightmare.o normalization_layer.o avgpool_layer.o coco.o dice.o yolo.o layer.o compare.o classifier.o
OBJ=gemm.o utils.o cuda.o deconvolutional_layer.o convolutional_layer.o list.o image.o activations.o im2col.o col2im.o blas.o crop_layer.o dropout_layer.o maxpool_layer.o softmax_layer.o data.o matrix.o network.o connected_layer.o cost_layer.o parser.o option_list.o darknet.o detection_layer.o imagenet.o captcha.o route_layer.o writing.o box.o nightmare.o normalization_layer.o avgpool_layer.o coco.o dice.o yolo.o layer.o compare.o classifier.o local_layer.o
ifeq ($(GPU), 1)
OBJ+=convolutional_kernels.o deconvolutional_kernels.o activation_kernels.o im2col_kernels.o col2im_kernels.o blas_kernels.o crop_layer_kernels.o dropout_layer_kernels.o maxpool_layer_kernels.o softmax_layer_kernels.o network_kernels.o avgpool_layer_kernels.o yolo_kernels.o
endif
Expand Down
8 changes: 4 additions & 4 deletions src/coco.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ char *coco_classes[] = {"person","bicycle","car","motorcycle","airplane","bus","

int coco_ids[] = {1,2,3,4,5,6,7,8,9,10,11,13,14,15,16,17,18,19,20,21,22,23,24,25,27,28,31,32,33,34,35,36,37,38,39,40,41,42,43,44,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,67,70,72,73,74,75,76,77,78,79,80,81,82,84,85,86,87,88,89,90};

void draw_coco(image im, int num, float thresh, box *boxes, float **probs, char *label)
void draw_coco(image im, int num, float thresh, box *boxes, float **probs)
{
int classes = 80;
int i;
Expand All @@ -38,7 +38,6 @@ void draw_coco(image im, int num, float thresh, box *boxes, float **probs, char
draw_box_width(im, left, top, right, bot, width, red, green, blue);
}
}
show_image(im, label);
}

void train_coco(char *cfgfile, char *weightfile)
Expand Down Expand Up @@ -215,7 +214,7 @@ void validate_coco(char *cfgfile, char *weightfile)
int i=0;
int t;

float thresh = .001;
float thresh = .01;
int nms = 1;
float iou_thresh = .5;

Expand Down Expand Up @@ -393,7 +392,8 @@ void test_coco(char *cfgfile, char *weightfile, char *filename, float thresh)
float *predictions = network_predict(net, X);
printf("%s: Predicted in %f seconds.\n", input, sec(clock()-time));
convert_coco_detections(predictions, l.classes, l.n, l.sqrt, l.side, 1, 1, thresh, probs, boxes, 0);
draw_coco(im, l.side*l.side*l.n, thresh, boxes, probs, "predictions");
draw_coco(im, l.side*l.side*l.n, thresh, boxes, probs);
show_image(im, "predictions");

show_image(sized, "resized");
free_image(im);
Expand Down
109 changes: 109 additions & 0 deletions src/coco_kernels.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
extern "C" {
#include "network.h"
#include "detection_layer.h"
#include "cost_layer.h"
#include "utils.h"
#include "parser.h"
#include "box.h"
#include "image.h"
}

#ifdef OPENCV
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
extern "C" image ipl_to_image(IplImage* src);
extern "C" void convert_coco_detections(float *predictions, int classes, int num, int square, int side, int w, int h, float thresh, float **probs, box *boxes, int only_objectness);
extern "C" void draw_coco(image im, int num, float thresh, box *boxes, float **probs);

static float **probs;
static box *boxes;
static network net;
static image in ;
static image in_s ;
static image det ;
static image det_s;
static image disp ;
static cv::VideoCapture cap(0);

void *fetch_in_thread(void *ptr)
{
cv::Mat frame_m;
cap >> frame_m;
IplImage frame = frame_m;
in = ipl_to_image(&frame);
rgbgr_image(in);
in_s = resize_image(in, net.w, net.h);
return 0;
}

void *detect_in_thread(void *ptr)
{
float nms = .4;
float thresh = .2;

detection_layer l = net.layers[net.n-1];
float *X = det_s.data;
float *predictions = network_predict(net, X);
free_image(det_s);
convert_coco_detections(predictions, l.classes, l.n, l.sqrt, l.side, 1, 1, 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("\nObjects:\n\n");
draw_coco(det, l.side*l.side*l.n, thresh, boxes, probs);
return 0;
}

extern "C" void demo_coco(char *cfgfile, char *weightfile, float thresh)
{
printf("YOLO demo\n");
net = parse_network_cfg(cfgfile);
if(weightfile){
load_weights(&net, weightfile);
}
set_batch_network(&net, 1);

srand(2222222);

if(!cap.isOpened()) error("Couldn't connect to webcam.\n");

detection_layer l = net.layers[net.n-1];
int j;

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 *));

pthread_t fetch_thread;
pthread_t detect_thread;

fetch_in_thread(0);
det = in;
det_s = in_s;

fetch_in_thread(0);
detect_in_thread(0);
disp = det;
det = in;
det_s = in_s;

while(1){
if(pthread_create(&fetch_thread, 0, fetch_in_thread, 0)) error("Thread creation failed");
if(pthread_create(&detect_thread, 0, detect_in_thread, 0)) error("Thread creation failed");
show_image(disp, "YOLO");
free_image(disp);
cvWaitKey(1);
pthread_join(fetch_thread, 0);
pthread_join(detect_thread, 0);

disp = det;
det = in;
det_s = in_s;
}
}
#else
extern "C" void demo_coco(char *cfgfile, char *weightfile, float thresh){
fprintf(stderr, "YOLO-COCO demo needs OpenCV for webcam images.\n");
}
#endif

4 changes: 1 addition & 3 deletions src/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -574,9 +574,7 @@ pthread_t load_data_in_thread(load_args args)
pthread_t thread;
struct load_args *ptr = calloc(1, sizeof(struct load_args));
*ptr = args;
if(pthread_create(&thread, 0, load_thread, ptr)) {
error("Thread creation failed");
}
if(pthread_create(&thread, 0, load_thread, ptr)) error("Thread creation failed");
return thread;
}

Expand Down
3 changes: 2 additions & 1 deletion src/layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ typedef enum {
ROUTE,
COST,
NORMALIZATION,
AVGPOOL
AVGPOOL,
LOCAL
} LAYER_TYPE;

typedef enum{
Expand Down
Loading

0 comments on commit 0cd2379

Please sign in to comment.