From 028696bf15efeca3acb3db8c42a96f7b9e0f55ff Mon Sep 17 00:00:00 2001
From: iovodov <b@ovdv.ru>
Date: Thu, 03 May 2018 13:33:46 +0000
Subject: [PATCH] Output improvements for detector results: When printing detector results, output was done in random order, obfuscating results for interpreting. Now: 1. Text output includes coordinates of rects in (left,right,top,bottom in pixels) along with label and score 2. Text output is sorted by rect lefts to simplify finding appropriate rects on image 3. If several class probs are > thresh for some detection, the most probable is written first and coordinates for others are not repeated 4. Rects are imprinted in image in order by their best class prob, so most probable rects are always on top and not overlayed by less probable ones 5. Most probable label for rect is always written first Also: 6. Message about low GPU memory include required amount

---
 Makefile |  158 ++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 139 insertions(+), 19 deletions(-)

diff --git a/Makefile b/Makefile
index dc08b46..5c39df1 100644
--- a/Makefile
+++ b/Makefile
@@ -1,29 +1,149 @@
-CC=gcc
-COMMON=-Wall `pkg-config --cflags opencv`
-CFLAGS= $(COMMON) -Ofast -ffast-math -flto
-UNAME = $(shell uname)
-ifeq ($(UNAME), Darwin)
-COMMON += -isystem /usr/local/Cellar/opencv/2.4.6.1/include/opencv -isystem /usr/local/Cellar/opencv/2.4.6.1/include
-else
-CFLAGS += -march=native
-endif
-#CFLAGS= $(COMMON) -O0 -g 
-LDFLAGS=`pkg-config --libs opencv` -lm
+GPU=0
+CUDNN=0
+CUDNN_HALF=0
+OPENCV=0
+AVX=0
+OPENMP=0
+LIBSO=0
+
+# set GPU=1 and CUDNN=1 to speedup on GPU
+# set CUDNN_HALF=1 to further speedup 3 x times (Mixed-precision using Tensor Cores) on GPU Tesla V100, Titan V, DGX-2
+# set AVX=1 and OPENMP=1 to speedup on CPU (if error occurs then set AVX=0)
+
+DEBUG=0
+
+ARCH= -gencode arch=compute_30,code=sm_30 \
+      -gencode arch=compute_35,code=sm_35 \
+      -gencode arch=compute_50,code=[sm_50,compute_50] \
+      -gencode arch=compute_52,code=[sm_52,compute_52] \
+	  -gencode arch=compute_61,code=[sm_61,compute_61]
+
+OS := $(shell uname)
+
+# Tesla V100
+# ARCH= -gencode arch=compute_70,code=[sm_70,compute_70]
+
+# GTX 1080, GTX 1070, GTX 1060, GTX 1050, GTX 1030, Titan Xp, Tesla P40, Tesla P4
+# ARCH= -gencode arch=compute_61,code=sm_61 -gencode arch=compute_61,code=compute_61
+
+# GP100/Tesla P100 � DGX-1
+# ARCH= -gencode arch=compute_60,code=sm_60
+
+# For Jetson Tx1 uncomment:
+# ARCH= -gencode arch=compute_51,code=[sm_51,compute_51]
+
+# For Jetson Tx2 or Drive-PX2 uncomment:
+# ARCH= -gencode arch=compute_62,code=[sm_62,compute_62]
+
+
 VPATH=./src/
-EXEC=cnn
+EXEC=darknet
+OBJDIR=./obj/
 
-OBJ=network.o image.o tests.o connected_layer.o maxpool_layer.o activations.o list.o option_list.o parser.o utils.o data.o matrix.o softmax_layer.o mini_blas.o convolutional_layer.o
+ifeq ($(LIBSO), 1)
+LIBNAMESO=darknet.so
+APPNAMESO=uselib
+endif
 
-all: $(EXEC)
+CC=gcc
+CPP=g++
+NVCC=nvcc 
+OPTS=-Ofast
+LDFLAGS= -lm -pthread 
+COMMON= 
+CFLAGS=-Wall -Wfatal-errors -Wno-unused-result -Wno-unknown-pragmas
 
-$(EXEC): $(OBJ)
-	$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@
+ifeq ($(DEBUG), 1) 
+OPTS= -O0 -g
+else
+ifeq ($(AVX), 1) 
+CFLAGS+= -ffp-contract=fast -mavx -msse4.1 -msse4a
+endif
+endif
 
-%.o: %.c 
-	$(CC) $(CFLAGS) -c $< -o $@
+CFLAGS+=$(OPTS)
+
+ifeq ($(OPENCV), 1) 
+COMMON+= -DOPENCV
+CFLAGS+= -DOPENCV
+LDFLAGS+= `pkg-config --libs opencv` 
+COMMON+= `pkg-config --cflags opencv` 
+endif
+
+ifeq ($(OPENMP), 1)
+CFLAGS+= -fopenmp
+LDFLAGS+= -lgomp
+endif
+
+ifeq ($(GPU), 1)
+COMMON+= -DGPU -I/usr/local/cuda/include/
+CFLAGS+= -DGPU
+ifeq ($(OS),Darwin) #MAC
+LDFLAGS+= -L/usr/local/cuda/lib -lcuda -lcudart -lcublas -lcurand
+else
+LDFLAGS+= -L/usr/local/cuda/lib64 -lcuda -lcudart -lcublas -lcurand
+endif
+endif
+
+ifeq ($(CUDNN), 1)
+COMMON+= -DCUDNN
+ifeq ($(OS),Darwin) #MAC
+CFLAGS+= -DCUDNN -I/usr/local/cuda/include
+LDFLAGS+= -L/usr/local/cuda/lib -lcudnn
+else
+CFLAGS+= -DCUDNN -I/usr/local/cudnn/include
+LDFLAGS+= -L/usr/local/cudnn/lib64 -lcudnn
+endif
+endif
+
+ifeq ($(CUDNN_HALF), 1)
+COMMON+= -DCUDNN_HALF
+CFLAGS+= -DCUDNN_HALF
+ARCH+= -gencode arch=compute_70,code=[sm_70,compute_70]
+endif
+
+OBJ=http_stream.o gemm.o utils.o cuda.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 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 reorg_layer.o reorg_old_layer.o super.o voxel.o tree.o yolo_layer.o upsample_layer.o
+ifeq ($(GPU), 1) 
+LDFLAGS+= -lstdc++ 
+OBJ+=convolutional_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 network_kernels.o avgpool_layer_kernels.o
+endif
+
+OBJS = $(addprefix $(OBJDIR), $(OBJ))
+DEPS = $(wildcard src/*.h) Makefile
+
+all: obj backup results $(EXEC) $(LIBNAMESO) $(APPNAMESO)
+
+ifeq ($(LIBSO), 1) 
+CFLAGS+= -fPIC
+
+$(LIBNAMESO): $(OBJS) src/yolo_v2_class.hpp src/yolo_v2_class.cpp
+	$(CPP) -shared -std=c++11 -fvisibility=hidden -DYOLODLL_EXPORTS $(COMMON) $(CFLAGS) $(OBJS) src/yolo_v2_class.cpp -o $@ $(LDFLAGS)
+	
+$(APPNAMESO): $(LIBNAMESO) src/yolo_v2_class.hpp src/yolo_console_dll.cpp
+	$(CPP) -std=c++11 $(COMMON) $(CFLAGS) -o $@ src/yolo_console_dll.cpp $(LDFLAGS) -L ./ -l:$(LIBNAMESO)
+endif
+
+$(EXEC): $(OBJS)
+	$(CPP) $(COMMON) $(CFLAGS) $^ -o $@ $(LDFLAGS)
+
+$(OBJDIR)%.o: %.c $(DEPS)
+	$(CC) $(COMMON) $(CFLAGS) -c $< -o $@
+
+$(OBJDIR)%.o: %.cpp $(DEPS)
+	$(CPP) $(COMMON) $(CFLAGS) -c $< -o $@
+
+$(OBJDIR)%.o: %.cu $(DEPS)
+	$(NVCC) $(ARCH) $(COMMON) --compiler-options "$(CFLAGS)" -c $< -o $@
+
+obj:
+	mkdir -p obj
+backup:
+	mkdir -p backup
+results:
+	mkdir -p results
 
 .PHONY: clean
 
 clean:
-	rm -rf $(OBJ) $(EXEC)
+	rm -rf $(OBJS) $(EXEC) $(LIBNAMESO) $(APPNAMESO)
 

--
Gitblit v1.10.0