diff --git a/Makefile b/Makefile index 1aaceefa..3374dcc1 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ -GPU=0 -CUDNN=0 -OPENCV=0 +GPU=1 +CUDNN=1 +OPENCV=1 DEBUG=0 ARCH= --gpu-architecture=compute_52 --gpu-code=compute_52 @@ -41,7 +41,7 @@ CFLAGS+= -DCUDNN LDFLAGS+= -lcudnn 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 local_layer.o swag.o shortcut_layer.o activation_layer.o rnn_layer.o gru_layer.o rnn.o rnn_vid.o crnn_layer.o demo.o tag.o cifar.o go.o batchnorm_layer.o art.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 detector.o layer.o compare.o classifier.o local_layer.o swag.o shortcut_layer.o activation_layer.o rnn_layer.o gru_layer.o rnn.o rnn_vid.o crnn_layer.o demo.o tag.o cifar.o go.o batchnorm_layer.o art.o region_layer.o ifeq ($(GPU), 1) LDFLAGS+= -lstdc++ 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 diff --git a/data/labels/aeroplane.png b/data/labels/aeroplane.png index 5b2f1d73..3681a79f 100644 Binary files a/data/labels/aeroplane.png and b/data/labels/aeroplane.png differ diff --git a/data/labels/airplane.png b/data/labels/airplane.png index 9a9ba89e..cdbf7e6c 100644 Binary files a/data/labels/airplane.png and b/data/labels/airplane.png differ diff --git a/data/labels/apple.png b/data/labels/apple.png index 69f1b58e..4036af5a 100644 Binary files a/data/labels/apple.png and b/data/labels/apple.png differ diff --git a/data/labels/backpack.png b/data/labels/backpack.png index 32a9a4a0..6385c667 100644 Binary files a/data/labels/backpack.png and b/data/labels/backpack.png differ diff --git a/data/labels/banana.png b/data/labels/banana.png index a77eac64..85da2b9a 100644 Binary files a/data/labels/banana.png and b/data/labels/banana.png differ diff --git a/data/labels/baseball bat.png b/data/labels/baseball bat.png index 134830ef..e6894703 100644 Binary files a/data/labels/baseball bat.png and b/data/labels/baseball bat.png differ diff --git a/data/labels/baseball glove.png b/data/labels/baseball glove.png index 4416e05a..09a22c5a 100644 Binary files a/data/labels/baseball glove.png and b/data/labels/baseball glove.png differ diff --git a/data/labels/bear.png b/data/labels/bear.png index 22470687..044c419a 100644 Binary files a/data/labels/bear.png and b/data/labels/bear.png differ diff --git a/data/labels/bed.png b/data/labels/bed.png index c316d709..c69898fd 100644 Binary files a/data/labels/bed.png and b/data/labels/bed.png differ diff --git a/data/labels/bench.png b/data/labels/bench.png index e8edcebc..97f25cdc 100644 Binary files a/data/labels/bench.png and b/data/labels/bench.png differ diff --git a/data/labels/bicycle.png b/data/labels/bicycle.png index 6c2bfbc5..6d0ddf1b 100644 Binary files a/data/labels/bicycle.png and b/data/labels/bicycle.png differ diff --git a/data/labels/bird.png b/data/labels/bird.png index 8d1510ab..3d9fefef 100644 Binary files a/data/labels/bird.png and b/data/labels/bird.png differ diff --git a/data/labels/boat.png b/data/labels/boat.png index b43070e5..c6a4b31b 100644 Binary files a/data/labels/boat.png and b/data/labels/boat.png differ diff --git a/data/labels/book.png b/data/labels/book.png index 401b513c..0937c7fa 100644 Binary files a/data/labels/book.png and b/data/labels/book.png differ diff --git a/data/labels/bottle.png b/data/labels/bottle.png index 04109744..71acf12f 100644 Binary files a/data/labels/bottle.png and b/data/labels/bottle.png differ diff --git a/data/labels/bowl.png b/data/labels/bowl.png index da19ad96..461d9732 100644 Binary files a/data/labels/bowl.png and b/data/labels/bowl.png differ diff --git a/data/labels/broccoli.png b/data/labels/broccoli.png index c96bcfcb..5b6efd78 100644 Binary files a/data/labels/broccoli.png and b/data/labels/broccoli.png differ diff --git a/data/labels/bus.png b/data/labels/bus.png index 661d6533..9a4f94a7 100644 Binary files a/data/labels/bus.png and b/data/labels/bus.png differ diff --git a/data/labels/cake.png b/data/labels/cake.png index 39b8ea55..54f3bf18 100644 Binary files a/data/labels/cake.png and b/data/labels/cake.png differ diff --git a/data/labels/car.png b/data/labels/car.png index 430637a8..76b61bb3 100644 Binary files a/data/labels/car.png and b/data/labels/car.png differ diff --git a/data/labels/carrot.png b/data/labels/carrot.png index 5fe7dd3a..4c494559 100644 Binary files a/data/labels/carrot.png and b/data/labels/carrot.png differ diff --git a/data/labels/cat.png b/data/labels/cat.png index 6b462705..1206e47a 100644 Binary files a/data/labels/cat.png and b/data/labels/cat.png differ diff --git a/data/labels/cell phone.png b/data/labels/cell phone.png index 40fee524..331fbd53 100644 Binary files a/data/labels/cell phone.png and b/data/labels/cell phone.png differ diff --git a/data/labels/chair.png b/data/labels/chair.png index f306c4bb..da33e79c 100644 Binary files a/data/labels/chair.png and b/data/labels/chair.png differ diff --git a/data/labels/clock.png b/data/labels/clock.png index aacf1e95..804e53d6 100644 Binary files a/data/labels/clock.png and b/data/labels/clock.png differ diff --git a/data/labels/couch.png b/data/labels/couch.png index 94c0bebd..0369b950 100644 Binary files a/data/labels/couch.png and b/data/labels/couch.png differ diff --git a/data/labels/cow.png b/data/labels/cow.png index c9084848..98fb3383 100644 Binary files a/data/labels/cow.png and b/data/labels/cow.png differ diff --git a/data/labels/cup.png b/data/labels/cup.png index 67caab4b..d33cc59f 100644 Binary files a/data/labels/cup.png and b/data/labels/cup.png differ diff --git a/data/labels/dining table.png b/data/labels/dining table.png index f5c173e6..11c8fd14 100644 Binary files a/data/labels/dining table.png and b/data/labels/dining table.png differ diff --git a/data/labels/diningtable.png b/data/labels/diningtable.png index 6fb8ce91..d9a199bc 100644 Binary files a/data/labels/diningtable.png and b/data/labels/diningtable.png differ diff --git a/data/labels/dog.png b/data/labels/dog.png index f5cf46b5..fa08f345 100644 Binary files a/data/labels/dog.png and b/data/labels/dog.png differ diff --git a/data/labels/donut.png b/data/labels/donut.png index 79c21f60..2ce75b26 100644 Binary files a/data/labels/donut.png and b/data/labels/donut.png differ diff --git a/data/labels/elephant.png b/data/labels/elephant.png index ca391e8e..1b1f2481 100644 Binary files a/data/labels/elephant.png and b/data/labels/elephant.png differ diff --git a/data/labels/fire hydrant.png b/data/labels/fire hydrant.png index f78bd907..708b7f4b 100644 Binary files a/data/labels/fire hydrant.png and b/data/labels/fire hydrant.png differ diff --git a/data/labels/fork.png b/data/labels/fork.png index 06ce2b4f..674b38b4 100644 Binary files a/data/labels/fork.png and b/data/labels/fork.png differ diff --git a/data/labels/frisbee.png b/data/labels/frisbee.png index 153ef9f5..644de6ba 100644 Binary files a/data/labels/frisbee.png and b/data/labels/frisbee.png differ diff --git a/data/labels/giraffe.png b/data/labels/giraffe.png index dedf3d68..21a4206f 100644 Binary files a/data/labels/giraffe.png and b/data/labels/giraffe.png differ diff --git a/data/labels/hair drier.png b/data/labels/hair drier.png index d015ed5a..5e93b08e 100644 Binary files a/data/labels/hair drier.png and b/data/labels/hair drier.png differ diff --git a/data/labels/handbag.png b/data/labels/handbag.png index 7954984a..6b5b23d6 100644 Binary files a/data/labels/handbag.png and b/data/labels/handbag.png differ diff --git a/data/labels/horse.png b/data/labels/horse.png index b0df7c55..1faff90d 100644 Binary files a/data/labels/horse.png and b/data/labels/horse.png differ diff --git a/data/labels/hot dog.png b/data/labels/hot dog.png index 5812a40b..2b3924e2 100644 Binary files a/data/labels/hot dog.png and b/data/labels/hot dog.png differ diff --git a/data/labels/keyboard.png b/data/labels/keyboard.png index 3fb76c53..265f4462 100644 Binary files a/data/labels/keyboard.png and b/data/labels/keyboard.png differ diff --git a/data/labels/kite.png b/data/labels/kite.png index b3b96e04..6a5ff8c3 100644 Binary files a/data/labels/kite.png and b/data/labels/kite.png differ diff --git a/data/labels/knife.png b/data/labels/knife.png index 28037e3c..30cc9be9 100644 Binary files a/data/labels/knife.png and b/data/labels/knife.png differ diff --git a/data/labels/laptop.png b/data/labels/laptop.png index 55d95e8e..db1a6344 100644 Binary files a/data/labels/laptop.png and b/data/labels/laptop.png differ diff --git a/data/labels/microwave.png b/data/labels/microwave.png index 4bb53268..0933f998 100644 Binary files a/data/labels/microwave.png and b/data/labels/microwave.png differ diff --git a/data/labels/motorbike.png b/data/labels/motorbike.png index 7091ca42..afd054b3 100644 Binary files a/data/labels/motorbike.png and b/data/labels/motorbike.png differ diff --git a/data/labels/motorcycle.png b/data/labels/motorcycle.png index fc8b0deb..e0f52640 100644 Binary files a/data/labels/motorcycle.png and b/data/labels/motorcycle.png differ diff --git a/data/labels/mouse.png b/data/labels/mouse.png index 915a5f39..5b146d58 100644 Binary files a/data/labels/mouse.png and b/data/labels/mouse.png differ diff --git a/data/labels/orange.png b/data/labels/orange.png index 9c4363e0..54a59782 100644 Binary files a/data/labels/orange.png and b/data/labels/orange.png differ diff --git a/data/labels/oven.png b/data/labels/oven.png index cd48c8bd..87c0917c 100644 Binary files a/data/labels/oven.png and b/data/labels/oven.png differ diff --git a/data/labels/parking meter.png b/data/labels/parking meter.png index afb6a7ae..440d2f69 100644 Binary files a/data/labels/parking meter.png and b/data/labels/parking meter.png differ diff --git a/data/labels/person.png b/data/labels/person.png index 33a9666e..c6e2ec6d 100644 Binary files a/data/labels/person.png and b/data/labels/person.png differ diff --git a/data/labels/pizza.png b/data/labels/pizza.png index a08c0166..d3f689f1 100644 Binary files a/data/labels/pizza.png and b/data/labels/pizza.png differ diff --git a/data/labels/potted plant.png b/data/labels/potted plant.png index 07bb49ca..93e833e5 100644 Binary files a/data/labels/potted plant.png and b/data/labels/potted plant.png differ diff --git a/data/labels/pottedplant.png b/data/labels/pottedplant.png index 569b86b1..30f8a5a1 100644 Binary files a/data/labels/pottedplant.png and b/data/labels/pottedplant.png differ diff --git a/data/labels/refrigerator.png b/data/labels/refrigerator.png index 0f8c9599..f7646a75 100644 Binary files a/data/labels/refrigerator.png and b/data/labels/refrigerator.png differ diff --git a/data/labels/remote.png b/data/labels/remote.png index 714893b9..e929b3fd 100644 Binary files a/data/labels/remote.png and b/data/labels/remote.png differ diff --git a/data/labels/sandwich.png b/data/labels/sandwich.png index 5d2d77e6..dd17f90f 100644 Binary files a/data/labels/sandwich.png and b/data/labels/sandwich.png differ diff --git a/data/labels/scissors.png b/data/labels/scissors.png index b5583c8a..88ae2f72 100644 Binary files a/data/labels/scissors.png and b/data/labels/scissors.png differ diff --git a/data/labels/sheep.png b/data/labels/sheep.png index 2b32bf8e..3dd27f01 100644 Binary files a/data/labels/sheep.png and b/data/labels/sheep.png differ diff --git a/data/labels/sink.png b/data/labels/sink.png index d97981e7..5107cc54 100644 Binary files a/data/labels/sink.png and b/data/labels/sink.png differ diff --git a/data/labels/skateboard.png b/data/labels/skateboard.png index e5df2554..492b46b9 100644 Binary files a/data/labels/skateboard.png and b/data/labels/skateboard.png differ diff --git a/data/labels/skis.png b/data/labels/skis.png index f222197a..8359b2bf 100644 Binary files a/data/labels/skis.png and b/data/labels/skis.png differ diff --git a/data/labels/snowboard.png b/data/labels/snowboard.png index 8c2b06c7..a9d3de32 100644 Binary files a/data/labels/snowboard.png and b/data/labels/snowboard.png differ diff --git a/data/labels/sofa.png b/data/labels/sofa.png index a555a310..fb7b5944 100644 Binary files a/data/labels/sofa.png and b/data/labels/sofa.png differ diff --git a/data/labels/spoon.png b/data/labels/spoon.png index 127dfd19..48a9cf9f 100644 Binary files a/data/labels/spoon.png and b/data/labels/spoon.png differ diff --git a/data/labels/sports ball.png b/data/labels/sports ball.png index 957d37ad..89789a91 100644 Binary files a/data/labels/sports ball.png and b/data/labels/sports ball.png differ diff --git a/data/labels/stop sign.png b/data/labels/stop sign.png index e32e371c..d1f43e75 100644 Binary files a/data/labels/stop sign.png and b/data/labels/stop sign.png differ diff --git a/data/labels/suitcase.png b/data/labels/suitcase.png index c5b38982..f2e0c3ff 100644 Binary files a/data/labels/suitcase.png and b/data/labels/suitcase.png differ diff --git a/data/labels/surfboard.png b/data/labels/surfboard.png index adbc0d98..57c26ce2 100644 Binary files a/data/labels/surfboard.png and b/data/labels/surfboard.png differ diff --git a/data/labels/teddy bear.png b/data/labels/teddy bear.png index b79fb209..0ae0f6ed 100644 Binary files a/data/labels/teddy bear.png and b/data/labels/teddy bear.png differ diff --git a/data/labels/tennis racket.png b/data/labels/tennis racket.png index 2390718d..210628f1 100644 Binary files a/data/labels/tennis racket.png and b/data/labels/tennis racket.png differ diff --git a/data/labels/tie.png b/data/labels/tie.png index a547fad6..5cca45a7 100644 Binary files a/data/labels/tie.png and b/data/labels/tie.png differ diff --git a/data/labels/toaster.png b/data/labels/toaster.png index 4c59a916..ff56fa82 100644 Binary files a/data/labels/toaster.png and b/data/labels/toaster.png differ diff --git a/data/labels/toilet.png b/data/labels/toilet.png index c7aa726a..ef6f745d 100644 Binary files a/data/labels/toilet.png and b/data/labels/toilet.png differ diff --git a/data/labels/toothbrush.png b/data/labels/toothbrush.png index 67877b09..e0e2ba10 100644 Binary files a/data/labels/toothbrush.png and b/data/labels/toothbrush.png differ diff --git a/data/labels/traffic light.png b/data/labels/traffic light.png index bd1e7c95..32a03774 100644 Binary files a/data/labels/traffic light.png and b/data/labels/traffic light.png differ diff --git a/data/labels/train.png b/data/labels/train.png index ec6d0dd0..ebca5ca9 100644 Binary files a/data/labels/train.png and b/data/labels/train.png differ diff --git a/data/labels/truck.png b/data/labels/truck.png index e6173f20..d24af46f 100644 Binary files a/data/labels/truck.png and b/data/labels/truck.png differ diff --git a/data/labels/tv.png b/data/labels/tv.png index 92b23c3a..fa5e4586 100644 Binary files a/data/labels/tv.png and b/data/labels/tv.png differ diff --git a/data/labels/tvmonitor.png b/data/labels/tvmonitor.png index 2250e412..e7b88a80 100644 Binary files a/data/labels/tvmonitor.png and b/data/labels/tvmonitor.png differ diff --git a/data/labels/umbrella.png b/data/labels/umbrella.png index 4e32d8b8..e581da1f 100644 Binary files a/data/labels/umbrella.png and b/data/labels/umbrella.png differ diff --git a/data/labels/vase.png b/data/labels/vase.png index 54cdf074..a6cccec3 100644 Binary files a/data/labels/vase.png and b/data/labels/vase.png differ diff --git a/data/labels/wine glass.png b/data/labels/wine glass.png index 1cac27d0..0491f71e 100644 Binary files a/data/labels/wine glass.png and b/data/labels/wine glass.png differ diff --git a/data/labels/zebra.png b/data/labels/zebra.png index a05c115d..9f798cd1 100644 Binary files a/data/labels/zebra.png and b/data/labels/zebra.png differ diff --git a/src/coco.c b/src/coco.c index af6f7b63..8ded9511 100644 --- a/src/coco.c +++ b/src/coco.c @@ -348,9 +348,8 @@ void test_coco(char *cfgfile, char *weightfile, char *filename, float thresh) convert_detections(predictions, l.classes, l.n, l.sqrt, l.side, 1, 1, thresh, probs, boxes, 0); if (nms) do_nms_sort(boxes, probs, l.side*l.side*l.n, l.classes, nms); draw_detections(im, l.side*l.side*l.n, thresh, boxes, probs, coco_classes, coco_labels, 80); + save_image(im, "prediction"); show_image(im, "predictions"); - - show_image(sized, "resized"); free_image(im); free_image(sized); #ifdef OPENCV diff --git a/src/connected_layer.c b/src/connected_layer.c index f20aa93c..e7784ea5 100644 --- a/src/connected_layer.c +++ b/src/connected_layer.c @@ -192,6 +192,9 @@ void denormalize_connected_layer(layer l) l.weights[i*l.inputs + j] *= scale; } l.biases[i] -= l.rolling_mean[i] * scale; + l.scales[i] = 1; + l.rolling_mean[i] = 0; + l.rolling_variance[i] = 1; } } @@ -257,7 +260,6 @@ void forward_connected_layer_gpu(connected_layer l, network_state state) axpy_ongpu(l.outputs, 1, l.biases_gpu, 1, l.output_gpu + i*l.outputs, 1); } activate_array_ongpu(l.output_gpu, l.outputs*l.batch, l.activation); - } void backward_connected_layer_gpu(connected_layer l, network_state state) diff --git a/src/convolutional_layer.c b/src/convolutional_layer.c index 4014a24d..e8ae49c9 100644 --- a/src/convolutional_layer.c +++ b/src/convolutional_layer.c @@ -301,6 +301,9 @@ void denormalize_convolutional_layer(convolutional_layer l) l.filters[i*l.c*l.size*l.size + j] *= scale; } l.biases[i] -= l.rolling_mean[i] * scale; + l.scales[i] = 1; + l.rolling_mean[i] = 0; + l.rolling_variance[i] = 1; } } @@ -434,7 +437,7 @@ void forward_convolutional_layer(convolutional_layer l, network_state state) } */ - if(l.xnor ){ + if(l.xnor){ binarize_filters(l.filters, l.n, l.c*l.size*l.size, l.binary_filters); swap_binary(&l); binarize_cpu(state.input, l.c*l.h*l.w*l.batch, l.binary_input); diff --git a/src/darknet.c b/src/darknet.c index aee9521e..49c9747e 100644 --- a/src/darknet.c +++ b/src/darknet.c @@ -14,6 +14,7 @@ extern void run_imagenet(int argc, char **argv); extern void run_yolo(int argc, char **argv); +extern void run_detector(int argc, char **argv); extern void run_coco(int argc, char **argv); extern void run_writing(int argc, char **argv); extern void run_captcha(int argc, char **argv); @@ -97,12 +98,13 @@ void operations(char *cfgfile) for(i = 0; i < net.n; ++i){ layer l = net.layers[i]; if(l.type == CONVOLUTIONAL){ - ops += 2 * l.n * l.size*l.size*l.c * l.out_h*l.out_w; + ops += 2l * l.n * l.size*l.size*l.c * l.out_h*l.out_w; } else if(l.type == CONNECTED){ - ops += 2 * l.inputs * l.outputs; + ops += 2l * l.inputs * l.outputs; } } printf("Floating Point Operations: %ld\n", ops); + printf("Floating Point Operations: %.2f Bn\n", (float)ops/1000000000.); } void partial(char *cfgfile, char *weightfile, char *outfile, int max) @@ -164,6 +166,47 @@ void rgbgr_net(char *cfgfile, char *weightfile, char *outfile) save_weights(net, outfile); } +void reset_normalize_net(char *cfgfile, char *weightfile, char *outfile) +{ + gpu_index = -1; + network net = parse_network_cfg(cfgfile); + if (weightfile) { + load_weights(&net, weightfile); + } + int i; + for (i = 0; i < net.n; ++i) { + layer l = net.layers[i]; + if (l.type == CONVOLUTIONAL && l.batch_normalize) { + denormalize_convolutional_layer(l); + } + if (l.type == CONNECTED && l.batch_normalize) { + denormalize_connected_layer(l); + } + if (l.type == GRU && l.batch_normalize) { + denormalize_connected_layer(*l.input_z_layer); + denormalize_connected_layer(*l.input_r_layer); + denormalize_connected_layer(*l.input_h_layer); + denormalize_connected_layer(*l.state_z_layer); + denormalize_connected_layer(*l.state_r_layer); + denormalize_connected_layer(*l.state_h_layer); + } + } + save_weights(net, outfile); +} + +layer normalize_layer(layer l, int n) +{ + int j; + l.batch_normalize=1; + l.scales = calloc(n, sizeof(float)); + for(j = 0; j < n; ++j){ + l.scales[j] = 1; + } + l.rolling_mean = calloc(n, sizeof(float)); + l.rolling_variance = calloc(n, sizeof(float)); + return l; +} + void normalize_net(char *cfgfile, char *weightfile, char *outfile) { gpu_index = -1; @@ -171,17 +214,23 @@ void normalize_net(char *cfgfile, char *weightfile, char *outfile) if(weightfile){ load_weights(&net, weightfile); } - int i, j; + int i; for(i = 0; i < net.n; ++i){ layer l = net.layers[i]; - if(l.type == CONVOLUTIONAL){ + if(l.type == CONVOLUTIONAL && !l.batch_normalize){ + net.layers[i] = normalize_layer(l, l.n); + } + if (l.type == CONNECTED && !l.batch_normalize) { + net.layers[i] = normalize_layer(l, l.outputs); + } + if (l.type == GRU && l.batch_normalize) { + *l.input_z_layer = normalize_layer(*l.input_z_layer, l.input_z_layer->outputs); + *l.input_r_layer = normalize_layer(*l.input_r_layer, l.input_r_layer->outputs); + *l.input_h_layer = normalize_layer(*l.input_h_layer, l.input_h_layer->outputs); + *l.state_z_layer = normalize_layer(*l.state_z_layer, l.state_z_layer->outputs); + *l.state_r_layer = normalize_layer(*l.state_r_layer, l.state_r_layer->outputs); + *l.state_h_layer = normalize_layer(*l.state_h_layer, l.state_h_layer->outputs); net.layers[i].batch_normalize=1; - net.layers[i].scales = calloc(l.n, sizeof(float)); - for(j = 0; j < l.n; ++j){ - net.layers[i].scales[i] = 1; - } - net.layers[i].rolling_mean = calloc(l.n, sizeof(float)); - net.layers[i].rolling_variance = calloc(l.n, sizeof(float)); } } save_weights(net, outfile); @@ -265,6 +314,8 @@ int main(int argc, char **argv) average(argc, argv); } else if (0 == strcmp(argv[1], "yolo")){ run_yolo(argc, argv); + } else if (0 == strcmp(argv[1], "detector")){ + run_detector(argc, argv); } else if (0 == strcmp(argv[1], "cifar")){ run_cifar(argc, argv); } else if (0 == strcmp(argv[1], "go")){ @@ -299,6 +350,8 @@ int main(int argc, char **argv) change_rate(argv[2], atof(argv[3]), (argc > 4) ? atof(argv[4]) : 0); } else if (0 == strcmp(argv[1], "rgbgr")){ rgbgr_net(argv[2], argv[3], argv[4]); + } else if (0 == strcmp(argv[1], "reset")){ + reset_normalize_net(argv[2], argv[3], argv[4]); } else if (0 == strcmp(argv[1], "denormalize")){ denormalize_net(argv[2], argv[3], argv[4]); } else if (0 == strcmp(argv[1], "normalize")){ diff --git a/src/data.c b/src/data.c index fcbdfc9b..afd7506f 100644 --- a/src/data.c +++ b/src/data.c @@ -297,11 +297,11 @@ void fill_truth_detection(char *path, int num_boxes, float *truth, int classes, if (w < .01 || h < .01) continue; - truth[i*5+0] = id; - truth[i*5+1] = x; - truth[i*5+2] = y; - truth[i*5+3] = w; - truth[i*5+4] = h; + truth[i*5+0] = x; + truth[i*5+1] = y; + truth[i*5+2] = w; + truth[i*5+3] = h; + truth[i*5+4] = id; } free(boxes); } diff --git a/src/demo.c b/src/demo.c index 0b870cf4..2e7ab938 100644 --- a/src/demo.c +++ b/src/demo.c @@ -8,7 +8,7 @@ #include "demo.h" #include -#define FRAMES 3 +#define FRAMES 1 #ifdef OPENCV #include "opencv2/highgui/highgui_c.h" diff --git a/src/detection_layer.h b/src/detection_layer.h index 75d9b7f0..e8c3a725 100644 --- a/src/detection_layer.h +++ b/src/detection_layer.h @@ -1,5 +1,5 @@ -#ifndef REGION_LAYER_H -#define REGION_LAYER_H +#ifndef DETECTION_LAYER_H +#define DETECTION_LAYER_H #include "layer.h" #include "network.h" diff --git a/src/image.c b/src/image.c index 3bfa8623..98e80c90 100644 --- a/src/image.c +++ b/src/image.c @@ -109,14 +109,17 @@ void draw_detections(image im, int num, float thresh, box *boxes, float **probs, int class = max_index(probs[i], classes); float prob = probs[i][class]; if(prob > thresh){ - int width = pow(prob, 1./2.)*10+1; - width = 8; + //int width = pow(prob, 1./2.)*30+1; + int width = 8; printf("%s: %.0f%%\n", names[class], prob*100); int offset = class*1 % classes; float red = get_color(2,offset,classes); float green = get_color(1,offset,classes); float blue = get_color(0,offset,classes); float rgb[3]; + + //width = prob*20+2; + rgb[0] = red; rgb[1] = green; rgb[2] = blue; diff --git a/src/layer.h b/src/layer.h index 18f98c7e..7182acd7 100644 --- a/src/layer.h +++ b/src/layer.h @@ -29,6 +29,7 @@ typedef enum { BATCHNORM, NETWORK, XNOR, + REGION, BLANK } LAYER_TYPE; diff --git a/src/network.c b/src/network.c index a9e50277..6ed82cea 100644 --- a/src/network.c +++ b/src/network.c @@ -16,6 +16,7 @@ #include "activation_layer.h" #include "deconvolutional_layer.h" #include "detection_layer.h" +#include "region_layer.h" #include "normalization_layer.h" #include "batchnorm_layer.h" #include "maxpool_layer.h" @@ -103,6 +104,8 @@ char *get_layer_string(LAYER_TYPE a) return "softmax"; case DETECTION: return "detection"; + case REGION: + return "region"; case DROPOUT: return "dropout"; case CROP: @@ -160,6 +163,8 @@ void forward_network(network net, network_state state) forward_batchnorm_layer(l, state); } else if(l.type == DETECTION){ forward_detection_layer(l, state); + } else if(l.type == REGION){ + forward_region_layer(l, state); } else if(l.type == CONNECTED){ forward_connected_layer(l, state); } else if(l.type == RNN){ @@ -230,11 +235,7 @@ float get_network_cost(network net) float sum = 0; int count = 0; for(i = 0; i < net.n; ++i){ - if(net.layers[i].type == COST){ - sum += net.layers[i].cost[0]; - ++count; - } - if(net.layers[i].type == DETECTION){ + if(net.layers[i].cost){ sum += net.layers[i].cost[0]; ++count; } @@ -284,6 +285,8 @@ void backward_network(network net, network_state state) backward_dropout_layer(l, state); } else if(l.type == DETECTION){ backward_detection_layer(l, state); + } else if(l.type == REGION){ + backward_region_layer(l, state); } else if(l.type == SOFTMAX){ if(i != 0) backward_softmax_layer(l, state); } else if(l.type == CONNECTED){ diff --git a/src/network_kernels.cu b/src/network_kernels.cu index 285f72cf..e1d41295 100644 --- a/src/network_kernels.cu +++ b/src/network_kernels.cu @@ -19,6 +19,7 @@ extern "C" { #include "gru_layer.h" #include "crnn_layer.h" #include "detection_layer.h" +#include "region_layer.h" #include "convolutional_layer.h" #include "activation_layer.h" #include "deconvolutional_layer.h" @@ -59,6 +60,8 @@ void forward_network_gpu(network net, network_state state) forward_local_layer_gpu(l, state); } else if(l.type == DETECTION){ forward_detection_layer_gpu(l, state); + } else if(l.type == REGION){ + forward_region_layer_gpu(l, state); } else if(l.type == CONNECTED){ forward_connected_layer_gpu(l, state); } else if(l.type == RNN){ @@ -125,6 +128,8 @@ void backward_network_gpu(network net, network_state state) backward_dropout_layer_gpu(l, state); } else if(l.type == DETECTION){ backward_detection_layer_gpu(l, state); + } else if(l.type == REGION){ + backward_region_layer_gpu(l, state); } else if(l.type == NORMALIZATION){ backward_normalization_layer_gpu(l, state); } else if(l.type == BATCHNORM){ @@ -181,7 +186,7 @@ float train_network_datum_gpu(network net, float *x, float *y) state.net = net; int x_size = get_network_input_size(net)*net.batch; int y_size = get_network_output_size(net)*net.batch; - if(net.layers[net.n-1].type == DETECTION) y_size = net.layers[net.n-1].truths*net.batch; + if(net.layers[net.n-1].truths) y_size = net.layers[net.n-1].truths*net.batch; if(!*net.input_gpu){ *net.input_gpu = cuda_make_array(x, x_size); *net.truth_gpu = cuda_make_array(y, y_size); diff --git a/src/parser.c b/src/parser.c index 1e5be4d9..b5c399fc 100644 --- a/src/parser.c +++ b/src/parser.c @@ -19,6 +19,7 @@ #include "softmax_layer.h" #include "dropout_layer.h" #include "detection_layer.h" +#include "region_layer.h" #include "avgpool_layer.h" #include "local_layer.h" #include "route_layer.h" @@ -51,6 +52,7 @@ int is_crop(section *s); int is_shortcut(section *s); int is_cost(section *s); int is_detection(section *s); +int is_region(section *s); int is_route(section *s); list *read_cfg(char *filename); @@ -245,6 +247,25 @@ softmax_layer parse_softmax(list *options, size_params params) return layer; } +layer parse_region(list *options, size_params params) +{ + int coords = option_find_int(options, "coords", 4); + int classes = option_find_int(options, "classes", 20); + int num = option_find_int(options, "num", 1); + layer l = make_region_layer(params.batch, params.w, params.h, num, classes, coords); + assert(l.outputs == params.inputs); + + l.softmax = option_find_int(options, "softmax", 0); + l.max_boxes = option_find_int_quiet(options, "max",30); + l.jitter = option_find_float(options, "jitter", .2); + l.rescore = option_find_int_quiet(options, "rescore",0); + + l.coord_scale = option_find_float(options, "coord_scale", 1); + l.object_scale = option_find_float(options, "object_scale", 1); + l.noobject_scale = option_find_float(options, "noobject_scale", 1); + l.class_scale = option_find_float(options, "class_scale", 1); + return l; +} detection_layer parse_detection(list *options, size_params params) { int coords = option_find_int(options, "coords", 1); @@ -557,6 +578,8 @@ network parse_network_cfg(char *filename) l = parse_crop(options, params); }else if(is_cost(s)){ l = parse_cost(options, params); + }else if(is_region(s)){ + l = parse_region(options, params); }else if(is_detection(s)){ l = parse_detection(options, params); }else if(is_softmax(s)){ @@ -620,6 +643,7 @@ LAYER_TYPE string_to_layer_type(char * type) if (strcmp(type, "[crop]")==0) return CROP; if (strcmp(type, "[cost]")==0) return COST; if (strcmp(type, "[detection]")==0) return DETECTION; + if (strcmp(type, "[region]")==0) return REGION; if (strcmp(type, "[local]")==0) return LOCAL; if (strcmp(type, "[deconv]")==0 || strcmp(type, "[deconvolutional]")==0) return DECONVOLUTIONAL; @@ -659,6 +683,10 @@ int is_cost(section *s) { return (strcmp(s->type, "[cost]")==0); } +int is_region(section *s) +{ + return (strcmp(s->type, "[region]")==0); +} int is_detection(section *s) { return (strcmp(s->type, "[detection]")==0);