diff --git a/.gitignore b/.gitignore
index bea19ff4..eb15c135 100644
--- a/.gitignore
+++ b/.gitignore
@@ -16,6 +16,8 @@ convnet/
decaf/
submission/
cfg/
+weights/
+build/
darknet
.fuse*
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 00000000..30aa626c
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/darknet.iml b/.idea/darknet.iml
new file mode 100644
index 00000000..f08604bb
--- /dev/null
+++ b/.idea/darknet.iml
@@ -0,0 +1,2 @@
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 00000000..8822db8f
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 00000000..33597b7b
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 00000000..94a25f7f
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 00000000..7aa27d78
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,759 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ gpu
+ main(
+ &net
+ net.
+ run_yolo
+ %d x %d /
+ conv %5d %2d
+ load
+ net
+ load_
+
+
+ net->
+ net
+
+
+ $PROJECT_DIR$/src
+ $PROJECT_DIR$
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+ DEFINITION_ORDER
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1551799986641
+
+
+ 1551799986641
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ file://$PROJECT_DIR$/src/parser.c
+ 1172
+
+
+
+ file://$PROJECT_DIR$/src/network.c
+ 54
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 00000000..153eb842
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,55 @@
+cmake_minimum_required(VERSION 3.5)
+project(darknet C)
+
+set(GPU 1)
+set(CUDNN 0)
+set(OPENCV 0)
+set(OPENMP 0)
+set(DEBUG 1)
+
+set(CMAKE_CXX_STANDARD 14)
+set(CMAKE_BINARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/build)
+set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
+set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
+set(DEBUG 1)
+
+include_directories(src include)
+
+set (OPTS -Ofast)
+
+if ( DEBUG )
+ set(OPTS ${OPTS} -O0 -g )
+endif()
+
+set ( NVCC nvcc )
+set ( AR ar )
+set ( ARFLAGS rcs )
+set ( LDFLAGS -lm -pthread )
+set ( CFLAGS ${OPTS} -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC)
+
+if ( OPENMP )
+ set(CFLAGS ${CFLAGS} -fopenmp )
+endif()
+
+if ( OPENCV )
+ set(COMMON ${COMMON} -DOPENCV )
+ set(CFLAGS ${CFLAGS} -DOPENCV )
+ set(LDFLAGS ${LDFLAGS} -L${env.OPENCV_HOME}/lib -lopencv_core -lstdc++)
+endif()
+
+if ( GPU )
+ set(COMMON ${COMMON} -DGPU -I/usr/local/cuda/include/ )
+ set(CFLAGS ${CFLAGS} -DGPU )
+ set(LDFLAGS ${LDFLAGS} -lstdc++ -L/usr/local/cuda/lib64 -lcuda -lcudart -lcublas -lcurand)
+endif()
+
+if ( CUDNN )
+ set(COMMON ${COMMON} -DCUDNN )
+ set(CFLAGS ${CFLAGS} -DCUDNN )
+ set(LDFLAGS ${LDFLAGS} -lcudnn)
+endif()
+
+add_subdirectory(src)
+add_subdirectory(examples)
+
diff --git a/Makefile b/Makefile
deleted file mode 100644
index 63e15e65..00000000
--- a/Makefile
+++ /dev/null
@@ -1,105 +0,0 @@
-GPU=0
-CUDNN=0
-OPENCV=0
-OPENMP=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_20,code=[sm_20,sm_21] \ This one is deprecated?
-
-# This is what I use, uncomment if you know your arch and want to specify
-# ARCH= -gencode arch=compute_52,code=compute_52
-
-VPATH=./src/:./examples
-SLIB=libdarknet.so
-ALIB=libdarknet.a
-EXEC=darknet
-OBJDIR=./obj/
-
-CC=gcc
-CPP=g++
-NVCC=nvcc
-AR=ar
-ARFLAGS=rcs
-OPTS=-Ofast
-LDFLAGS= -lm -pthread
-COMMON= -Iinclude/ -Isrc/
-CFLAGS=-Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC
-
-ifeq ($(OPENMP), 1)
-CFLAGS+= -fopenmp
-endif
-
-ifeq ($(DEBUG), 1)
-OPTS=-O0 -g
-endif
-
-CFLAGS+=$(OPTS)
-
-ifeq ($(OPENCV), 1)
-COMMON+= -DOPENCV
-CFLAGS+= -DOPENCV
-LDFLAGS+= `pkg-config --libs opencv` -lstdc++
-COMMON+= `pkg-config --cflags opencv`
-endif
-
-ifeq ($(GPU), 1)
-COMMON+= -DGPU -I/usr/local/cuda/include/
-CFLAGS+= -DGPU
-LDFLAGS+= -L/usr/local/cuda/lib64 -lcuda -lcudart -lcublas -lcurand
-endif
-
-ifeq ($(CUDNN), 1)
-COMMON+= -DCUDNN
-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 detection_layer.o route_layer.o upsample_layer.o box.o normalization_layer.o avgpool_layer.o layer.o local_layer.o shortcut_layer.o logistic_layer.o activation_layer.o rnn_layer.o gru_layer.o crnn_layer.o demo.o batchnorm_layer.o region_layer.o reorg_layer.o tree.o lstm_layer.o l2norm_layer.o yolo_layer.o iseg_layer.o image_opencv.o
-EXECOBJA=captcha.o lsd.o super.o art.o tag.o cifar.o go.o rnn.o segmenter.o regressor.o classifier.o coco.o yolo.o detector.o nightmare.o instance-segmenter.o darknet.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 avgpool_layer_kernels.o
-endif
-
-EXECOBJ = $(addprefix $(OBJDIR), $(EXECOBJA))
-OBJS = $(addprefix $(OBJDIR), $(OBJ))
-DEPS = $(wildcard src/*.h) Makefile include/darknet.h
-
-all: obj backup results $(SLIB) $(ALIB) $(EXEC)
-#all: obj results $(SLIB) $(ALIB) $(EXEC)
-
-
-$(EXEC): $(EXECOBJ) $(ALIB)
- $(CC) $(COMMON) $(CFLAGS) $^ -o $@ $(LDFLAGS) $(ALIB)
-
-$(ALIB): $(OBJS)
- $(AR) $(ARFLAGS) $@ $^
-
-$(SLIB): $(OBJS)
- $(CC) $(CFLAGS) -shared $^ -o $@ $(LDFLAGS)
-
-$(OBJDIR)%.o: %.cpp $(DEPS)
- $(CPP) $(COMMON) $(CFLAGS) -c $< -o $@
-
-$(OBJDIR)%.o: %.c $(DEPS)
- $(CC) $(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 $(OBJS) $(SLIB) $(ALIB) $(EXEC) $(EXECOBJ) $(OBJDIR)/*
-
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
new file mode 100644
index 00000000..53e15b30
--- /dev/null
+++ b/examples/CMakeLists.txt
@@ -0,0 +1,6 @@
+message("In ${CMAKE_CURRENT_SOURCE_DIR}")
+FILE(GLOB EXAMPLE_SOURCES "*.c" PARENT_SCOPE)
+add_executable(darknet ${EXAMPLE_SOURCES} )
+SET_TARGET_PROPERTIES(darknet PROPERTIES LINKER_LANGUAGE C)
+TARGET_LINK_LIBRARIES(darknet DarkNet pthread m)
+
diff --git a/examples/attention.c b/examples/attention.c
index cd1e579d..934d922a 100644
--- a/examples/attention.c
+++ b/examples/attention.c
@@ -287,7 +287,7 @@ void validate_attention_single(char *datacfg, char *filename, char *weightfile)
printf("\n");
copy_cpu(classes, pred, 1, avgs, 1);
top_k(pred + classes, divs*divs, divs*divs, inds);
- show_image(crop, "crop");
+ show_image(crop, "crop", 0);
for(j = 0; j < extra; ++j){
int index = inds[j];
int row = index / divs;
@@ -298,7 +298,7 @@ void validate_attention_single(char *datacfg, char *filename, char *weightfile)
image tile = crop_image(crop, x, y, net->w, net->h);
float *pred = network_predict(net, tile.data);
axpy_cpu(classes, 1., pred, 1, avgs, 1);
- show_image(tile, "tile");
+ show_image(tile, "tile", 0);
//cvWaitKey(10);
}
if(net->hierarchy) hierarchy_predictions(pred, net->outputs, net->hierarchy, 1, 1);
diff --git a/examples/dice.c b/examples/dice.c.HIDE
similarity index 100%
rename from examples/dice.c
rename to examples/dice.c.HIDE
diff --git a/examples/swag.c b/examples/swag.c
index c22d7855..0dfeb2dc 100644
--- a/examples/swag.c
+++ b/examples/swag.c
@@ -9,16 +9,16 @@ void train_swag(char *cfgfile, char *weightfile)
char *base = basecfg(cfgfile);
printf("%s\n", base);
float avg_loss = -1;
- network net = parse_network_cfg(cfgfile);
+ network* net = parse_network_cfg(cfgfile);
if(weightfile){
- load_weights(&net, weightfile);
+ load_weights(net, weightfile);
}
- printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net.learning_rate, net.momentum, net.decay);
- int imgs = net.batch*net.subdivisions;
- int i = *net.seen/imgs;
+ printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net->learning_rate, net->momentum, net->decay);
+ int imgs = net->batch*net->subdivisions;
+ int i = *net->seen/imgs;
data train, buffer;
- layer l = net.layers[net.n - 1];
+ layer l = net->layers[net->n - 1];
int side = l.side;
int classes = l.classes;
@@ -29,8 +29,8 @@ void train_swag(char *cfgfile, char *weightfile)
char **paths = (char **)list_to_array(plist);
load_args args = {0};
- args.w = net.w;
- args.h = net.h;
+ args.w = net->w;
+ args.h = net->h;
args.paths = paths;
args.n = imgs;
args.m = plist->size;
@@ -43,7 +43,7 @@ void train_swag(char *cfgfile, char *weightfile)
pthread_t load_thread = load_data_in_thread(args);
clock_t time;
//while(i*imgs < N*120){
- while(get_current_batch(net) < net.max_batches){
+ while(get_current_batch(net) < net->max_batches){
i += 1;
time=clock();
pthread_join(load_thread, 0);
diff --git a/examples/voxel.c b/examples/voxel.c
index 01ea9bb9..aa64a9b4 100644
--- a/examples/voxel.c
+++ b/examples/voxel.c
@@ -44,13 +44,13 @@ void train_voxel(char *cfgfile, char *weightfile)
char *base = basecfg(cfgfile);
printf("%s\n", base);
float avg_loss = -1;
- network net = parse_network_cfg(cfgfile);
+ network* net = parse_network_cfg(cfgfile);
if(weightfile){
- load_weights(&net, weightfile);
+ load_weights(net, weightfile);
}
- printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net.learning_rate, net.momentum, net.decay);
- int imgs = net.batch*net.subdivisions;
- int i = *net.seen/imgs;
+ printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net->learning_rate, net->momentum, net->decay);
+ int imgs = net->batch*net->subdivisions;
+ int i = *(net->seen)/imgs;
data train, buffer;
@@ -59,8 +59,8 @@ void train_voxel(char *cfgfile, char *weightfile)
char **paths = (char **)list_to_array(plist);
load_args args = {0};
- args.w = net.w;
- args.h = net.h;
+ args.w = net->w;
+ args.h = net->h;
args.scale = 4;
args.paths = paths;
args.n = imgs;
@@ -71,7 +71,7 @@ void train_voxel(char *cfgfile, char *weightfile)
pthread_t load_thread = load_data_in_thread(args);
clock_t time;
//while(i*imgs < N*120){
- while(get_current_batch(net) < net.max_batches){
+ while(get_current_batch(net) < net->max_batches){
i += 1;
time=clock();
pthread_join(load_thread, 0);
@@ -105,11 +105,11 @@ void train_voxel(char *cfgfile, char *weightfile)
void test_voxel(char *cfgfile, char *weightfile, char *filename)
{
- network net = parse_network_cfg(cfgfile);
+ network* net = parse_network_cfg(cfgfile);
if(weightfile){
- load_weights(&net, weightfile);
+ load_weights(net, weightfile);
}
- set_batch_network(&net, 1);
+ set_batch_network(net, 1);
srand(2222222);
clock_t time;
@@ -126,7 +126,7 @@ void test_voxel(char *cfgfile, char *weightfile, char *filename)
strtok(input, "\n");
}
image im = load_image_color(input, 0, 0);
- resize_network(&net, im.w, im.h);
+ resize_network(net, im.w, im.h);
printf("%d %d\n", im.w, im.h);
float *X = im.data;
diff --git a/examples/writing.c b/examples/writing.c
index 1b6ff83b..623ab8db 100644
--- a/examples/writing.c
+++ b/examples/writing.c
@@ -7,12 +7,12 @@ void train_writing(char *cfgfile, char *weightfile)
float avg_loss = -1;
char *base = basecfg(cfgfile);
printf("%s\n", base);
- network net = parse_network_cfg(cfgfile);
+ network* net = parse_network_cfg(cfgfile);
if(weightfile){
- load_weights(&net, weightfile);
+ load_weights(net, weightfile);
}
- printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net.learning_rate, net.momentum, net.decay);
- int imgs = net.batch*net.subdivisions;
+ printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net->learning_rate, net->momentum, net->decay);
+ int imgs = net->batch*net->subdivisions;
list *plist = get_paths("figures.list");
char **paths = (char **)list_to_array(plist);
clock_t time;
@@ -23,8 +23,8 @@ void train_writing(char *cfgfile, char *weightfile)
data train, buffer;
load_args args = {0};
- args.w = net.w;
- args.h = net.h;
+ args.w = net->w;
+ args.h = net->h;
args.out_w = out.w;
args.out_h = out.h;
args.paths = paths;
@@ -34,8 +34,8 @@ void train_writing(char *cfgfile, char *weightfile)
args.type = WRITING_DATA;
pthread_t load_thread = load_data_in_thread(args);
- int epoch = (*net.seen)/N;
- while(get_current_batch(net) < net.max_batches || net.max_batches == 0){
+ int epoch = *(net->seen)/N;
+ while(get_current_batch(net) < net->max_batches || net->max_batches == 0){
time=clock();
pthread_join(load_thread, 0);
train = buffer;
@@ -63,15 +63,15 @@ void train_writing(char *cfgfile, char *weightfile)
if(avg_loss == -1) avg_loss = loss;
avg_loss = avg_loss*.9 + loss*.1;
- printf("%ld, %.3f: %f, %f avg, %f rate, %lf seconds, %ld images\n", get_current_batch(net), (float)(*net.seen)/N, loss, avg_loss, get_current_rate(net), sec(clock()-time), *net.seen);
+ printf("%ld, %.3f: %f, %f avg, %f rate, %lf seconds, %ld images\n", get_current_batch(net), (float)(*(net->seen))/N, loss, avg_loss, get_current_rate(net), sec(clock()-time), *net->seen);
free_data(train);
if(get_current_batch(net)%100 == 0){
char buff[256];
sprintf(buff, "%s/%s_batch_%ld.weights", backup_directory, base, get_current_batch(net));
save_weights(net, buff);
}
- if(*net.seen/N > epoch){
- epoch = *net.seen/N;
+ if(*net->seen/N > epoch){
+ epoch = *net->seen/N;
char buff[256];
sprintf(buff, "%s/%s_%d.weights",backup_directory,base, epoch);
save_weights(net, buff);
@@ -81,11 +81,11 @@ void train_writing(char *cfgfile, char *weightfile)
void test_writing(char *cfgfile, char *weightfile, char *filename)
{
- network net = parse_network_cfg(cfgfile);
+ network* net = parse_network_cfg(cfgfile);
if(weightfile){
- load_weights(&net, weightfile);
+ load_weights(net, weightfile);
}
- set_batch_network(&net, 1);
+ set_batch_network(net, 1);
srand(2222222);
clock_t time;
char buff[256];
@@ -102,7 +102,7 @@ void test_writing(char *cfgfile, char *weightfile, char *filename)
}
image im = load_image_color(input, 0, 0);
- resize_network(&net, im.w, im.h);
+ resize_network(net, im.w, im.h);
printf("%d %d %d\n", im.h, im.w, im.c);
float *X = im.data;
time=clock();
@@ -114,8 +114,8 @@ void test_writing(char *cfgfile, char *weightfile, char *filename)
image thresh = threshold_image(upsampled, .5);
pred = thresh;
- show_image(pred, "prediction");
- show_image(im, "orig");
+ show_image(pred, "prediction", 0);
+ show_image(im, "orig", 0);
#ifdef OPENCV
cvWaitKey(0);
cvDestroyAllWindows();
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644
index 00000000..33124acd
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -0,0 +1,15 @@
+message("In ${CMAKE_CURRENT_SOURCE_DIR}")
+FILE(GLOB_RECURSE HEADER_FILES "*.h" PARENT_SCOPE)
+FILE(GLOB_RECURSE SOURCE_FILES "*.c" PARENT_SCOPE)
+
+set(HEADER_FILES ${HEADER_FILES} include/darknet.h PARENT_SCOPE)
+set(CUDA_FILES)
+if ( GPU )
+ message("Compiling for GPU...")
+ FILE(GLOB_RECURSE CUDA_FILES "*.cu" PARENT_SCOPE)
+ message("CUDA_FILES = ${CUDA_FILES}")
+endif()
+
+message("SOURCE_FILES = ${SOURCE_FILES}")
+add_library(DarkNet ${HEADER_FILES} ${SOURCE_FILES} ${CUDA_FILES})
+SET_TARGET_PROPERTIES(DarkNet PROPERTIES LINKER_LANGUAGE C)
diff --git a/src/compare.c b/src/compare.c.HIDE
similarity index 100%
rename from src/compare.c
rename to src/compare.c.HIDE
diff --git a/src/convolutional_layer.c b/src/convolutional_layer.c
index 1fb58b09..0bafbf1b 100644
--- a/src/convolutional_layer.c
+++ b/src/convolutional_layer.c
@@ -14,12 +14,12 @@
void swap_binary(convolutional_layer *l)
{
- float *swap = l->weights;
- l->weights = l->binary_weights;
- l->binary_weights = swap;
+ float *swap = l->weights;
+ l->weights = l->binary_weights;
+ l->binary_weights = swap;
#ifdef GPU
- swap = l->weights_gpu;
+ swap = l->weights_gpu;
l->weights_gpu = l->binary_weights_gpu;
l->binary_weights_gpu = swap;
#endif
@@ -27,65 +27,65 @@ void swap_binary(convolutional_layer *l)
void binarize_weights(float *weights, int n, int size, float *binary)
{
- int i, f;
- for(f = 0; f < n; ++f){
- float mean = 0;
- for(i = 0; i < size; ++i){
- mean += fabs(weights[f*size + i]);
- }
- mean = mean / size;
- for(i = 0; i < size; ++i){
- binary[f*size + i] = (weights[f*size + i] > 0) ? mean : -mean;
- }
- }
+ int i, f;
+ for(f = 0; f < n; ++f){
+ float mean = 0;
+ for(i = 0; i < size; ++i){
+ mean += fabs(weights[f*size + i]);
+ }
+ mean = mean / size;
+ for(i = 0; i < size; ++i){
+ binary[f*size + i] = (weights[f*size + i] > 0) ? mean : -mean;
+ }
+ }
}
void binarize_cpu(float *input, int n, float *binary)
{
- int i;
- for(i = 0; i < n; ++i){
- binary[i] = (input[i] > 0) ? 1 : -1;
- }
+ int i;
+ for(i = 0; i < n; ++i){
+ binary[i] = (input[i] > 0) ? 1 : -1;
+ }
}
void binarize_input(float *input, int n, int size, float *binary)
{
- int i, s;
- for(s = 0; s < size; ++s){
- float mean = 0;
- for(i = 0; i < n; ++i){
- mean += fabs(input[i*size + s]);
- }
- mean = mean / n;
- for(i = 0; i < n; ++i){
- binary[i*size + s] = (input[i*size + s] > 0) ? mean : -mean;
- }
- }
+ int i, s;
+ for(s = 0; s < size; ++s){
+ float mean = 0;
+ for(i = 0; i < n; ++i){
+ mean += fabs(input[i*size + s]);
+ }
+ mean = mean / n;
+ for(i = 0; i < n; ++i){
+ binary[i*size + s] = (input[i*size + s] > 0) ? mean : -mean;
+ }
+ }
}
int convolutional_out_height(convolutional_layer l)
{
- return (l.h + 2*l.pad - l.size) / l.stride + 1;
+ return (l.h + 2*l.pad - l.size) / l.stride + 1;
}
int convolutional_out_width(convolutional_layer l)
{
- return (l.w + 2*l.pad - l.size) / l.stride + 1;
+ return (l.w + 2*l.pad - l.size) / l.stride + 1;
}
image get_convolutional_image(convolutional_layer l)
{
- return float_to_image(l.out_w,l.out_h,l.out_c,l.output);
+ return float_to_image(l.out_w,l.out_h,l.out_c,l.output);
}
image get_convolutional_delta(convolutional_layer l)
{
- return float_to_image(l.out_w,l.out_h,l.out_c,l.delta);
+ return float_to_image(l.out_w,l.out_h,l.out_c,l.delta);
}
static size_t get_workspace_size(layer l){
#ifdef CUDNN
- if(gpu_index >= 0){
+ if(gpu_index >= 0){
size_t most = 0;
size_t s = 0;
cudnnGetConvolutionForwardWorkspaceSize(cudnn_handle(),
@@ -115,7 +115,7 @@ static size_t get_workspace_size(layer l){
return most;
}
#endif
- return (size_t)l.out_h*l.out_w*l.size*l.size*l.c/l.groups*sizeof(float);
+ return (size_t)l.out_h*l.out_w*l.size*l.size*l.c/l.groups*sizeof(float);
}
#ifdef GPU
@@ -173,93 +173,96 @@ void cudnn_convolutional_setup(layer *l)
#endif
#endif
-convolutional_layer make_convolutional_layer(int batch, int h, int w, int c, int n, int groups, int size, int stride, int padding, ACTIVATION activation, int batch_normalize, int binary, int xnor, int adam)
+convolutional_layer
+make_convolutional_layer(int batch, int h, int w, int c, int n, int groups,
+ int size, int stride, int padding, ACTIVATION activation,
+ int batch_normalize, int binary, int xnor, int adam)
{
- int i;
- convolutional_layer l = {0};
- l.type = CONVOLUTIONAL;
+ int i;
+ convolutional_layer l = {0};
+ l.type = CONVOLUTIONAL;
- l.groups = groups;
- l.h = h;
- l.w = w;
- l.c = c;
- l.n = n;
- l.binary = binary;
- l.xnor = xnor;
- l.batch = batch;
- l.stride = stride;
- l.size = size;
- l.pad = padding;
- l.batch_normalize = batch_normalize;
+ l.groups = groups;
+ l.h = h;
+ l.w = w;
+ l.c = c;
+ l.n = n;
+ l.binary = binary;
+ l.xnor = xnor;
+ l.batch = batch;
+ l.stride = stride;
+ l.size = size;
+ l.pad = padding;
+ l.batch_normalize = batch_normalize;
- l.weights = calloc(c/groups*n*size*size, sizeof(float));
- l.weight_updates = calloc(c/groups*n*size*size, sizeof(float));
+ l.weights = calloc(c/groups*n*size*size, sizeof(float));
+ l.weight_updates = calloc(c/groups*n*size*size, sizeof(float));
- l.biases = calloc(n, sizeof(float));
- l.bias_updates = calloc(n, sizeof(float));
+ l.biases = calloc(n, sizeof(float));
+ l.bias_updates = calloc(n, sizeof(float));
- l.nweights = c/groups*n*size*size;
- l.nbiases = n;
+ l.nweights = c/groups*n*size*size;
+ l.nbiases = n;
- // float scale = 1./sqrt(size*size*c);
- float scale = sqrt(2./(size*size*c/l.groups));
- //printf("convscale %f\n", scale);
- //scale = .02;
- //for(i = 0; i < c*n*size*size; ++i) l.weights[i] = scale*rand_uniform(-1, 1);
- for(i = 0; i < l.nweights; ++i) l.weights[i] = scale*rand_normal();
- int out_w = convolutional_out_width(l);
- int out_h = convolutional_out_height(l);
- l.out_h = out_h;
- l.out_w = out_w;
- l.out_c = n;
- l.outputs = l.out_h * l.out_w * l.out_c;
- l.inputs = l.w * l.h * l.c;
+ // float scale = 1./sqrt(size*size*c);
+ float scale = sqrt(2./(size*size*c/l.groups));
+ //printf("convscale %f\n", scale);
+ //scale = .02;
+ //for(i = 0; i < c*n*size*size; ++i) l.weights[i] = scale*rand_uniform(-1, 1);
+ for(i = 0; i < l.nweights; ++i) l.weights[i] = scale*rand_normal();
+ int out_w = convolutional_out_width(l);
+ int out_h = convolutional_out_height(l);
+ l.out_h = out_h;
+ l.out_w = out_w;
+ l.out_c = n;
+ l.outputs = l.out_h * l.out_w * l.out_c;
+ l.inputs = l.w * l.h * l.c;
- l.output = calloc(l.batch*l.outputs, sizeof(float));
- l.delta = calloc(l.batch*l.outputs, sizeof(float));
+ l.output = calloc(l.batch*l.outputs, sizeof(float));
+ l.delta = calloc(l.batch*l.outputs, sizeof(float));
- l.forward = forward_convolutional_layer;
- l.backward = backward_convolutional_layer;
- l.update = update_convolutional_layer;
- if(binary){
- l.binary_weights = calloc(l.nweights, sizeof(float));
- l.cweights = calloc(l.nweights, sizeof(char));
- l.scales = calloc(n, sizeof(float));
- }
- if(xnor){
- l.binary_weights = calloc(l.nweights, sizeof(float));
- l.binary_input = calloc(l.inputs*l.batch, sizeof(float));
- }
+ l.forward = forward_convolutional_layer;
+ l.backward = backward_convolutional_layer;
+ l.update = update_convolutional_layer;
+ if(binary){
+ l.binary_weights = calloc(l.nweights, sizeof(float));
+ l.cweights = calloc(l.nweights, sizeof(char));
+ l.scales = calloc(n, sizeof(float));
+ }
+ if(xnor){
+ l.binary_weights = calloc(l.nweights, sizeof(float));
+ l.binary_input = calloc(l.inputs*l.batch, sizeof(float));
+ }
- if(batch_normalize){
- l.scales = calloc(n, sizeof(float));
- l.scale_updates = calloc(n, sizeof(float));
- for(i = 0; i < n; ++i){
- l.scales[i] = 1;
- }
+ if(batch_normalize){
+ l.scales = calloc(n, sizeof(float));
+ l.scale_updates = calloc(n, sizeof(float));
+ for(i = 0; i < n; ++i){
+ l.scales[i] = 1;
+ }
- l.mean = calloc(n, sizeof(float));
- l.variance = calloc(n, sizeof(float));
+ l.mean = calloc(n, sizeof(float));
+ l.variance = calloc(n, sizeof(float));
- l.mean_delta = calloc(n, sizeof(float));
- l.variance_delta = calloc(n, sizeof(float));
+ l.mean_delta = calloc(n, sizeof(float));
+ l.variance_delta = calloc(n, sizeof(float));
- l.rolling_mean = calloc(n, sizeof(float));
- l.rolling_variance = calloc(n, sizeof(float));
- l.x = calloc(l.batch*l.outputs, sizeof(float));
- l.x_norm = calloc(l.batch*l.outputs, sizeof(float));
- }
- if(adam){
- l.m = calloc(l.nweights, sizeof(float));
- l.v = calloc(l.nweights, sizeof(float));
- l.bias_m = calloc(n, sizeof(float));
- l.scale_m = calloc(n, sizeof(float));
- l.bias_v = calloc(n, sizeof(float));
- l.scale_v = calloc(n, sizeof(float));
- }
+ l.rolling_mean = calloc(n, sizeof(float));
+ l.rolling_variance = calloc(n, sizeof(float));
+ l.x = calloc(l.batch*l.outputs, sizeof(float));
+ l.x_norm = calloc(l.batch*l.outputs, sizeof(float));
+ }
+ if(adam){
+ l.m = calloc(l.nweights, sizeof(float));
+ l.v = calloc(l.nweights, sizeof(float));
+ l.bias_m = calloc(n, sizeof(float));
+ l.scale_m = calloc(n, sizeof(float));
+ l.bias_v = calloc(n, sizeof(float));
+ l.scale_v = calloc(n, sizeof(float));
+ }
#ifdef GPU
- l.forward_gpu = forward_convolutional_layer_gpu;
+ l.forward_gpu = forward_convolutional_layer_gpu;
l.backward_gpu = backward_convolutional_layer_gpu;
l.update_gpu = update_convolutional_layer_gpu;
@@ -319,27 +322,27 @@ convolutional_layer make_convolutional_layer(int batch, int h, int w, int c, int
#endif
}
#endif
- l.workspace_size = get_workspace_size(l);
- l.activation = activation;
+ l.workspace_size = get_workspace_size(l);
+ l.activation = activation;
- fprintf(stderr, "conv %5d %2d x%2d /%2d %4d x%4d x%4d -> %4d x%4d x%4d %5.3f BFLOPs\n", n, size, size, stride, w, h, c, l.out_w, l.out_h, l.out_c, (2.0 * l.n * l.size*l.size*l.c/l.groups * l.out_h*l.out_w)/1000000000.);
+ fprintf(stderr, "conv %5d %2d x%2d /%2d %4d x%4d x%4d -> %4d x%4d x%4d %5.3f BFLOPs\n", n, size, size, stride, w, h, c, l.out_w, l.out_h, l.out_c, (2.0 * l.n * l.size*l.size*l.c/l.groups * l.out_h*l.out_w)/1000000000.);
- return l;
+ return l;
}
void denormalize_convolutional_layer(convolutional_layer l)
{
- int i, j;
- for(i = 0; i < l.n; ++i){
- float scale = l.scales[i]/sqrt(l.rolling_variance[i] + .00001);
- for(j = 0; j < l.c/l.groups*l.size*l.size; ++j){
- l.weights[i*l.c/l.groups*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;
- }
+ int i, j;
+ for(i = 0; i < l.n; ++i){
+ float scale = l.scales[i]/sqrt(l.rolling_variance[i] + .00001);
+ for(j = 0; j < l.c/l.groups*l.size*l.size; ++j){
+ l.weights[i*l.c/l.groups*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;
+ }
}
/*
@@ -369,26 +372,26 @@ void test_convolutional_layer()
void resize_convolutional_layer(convolutional_layer *l, int w, int h)
{
- l->w = w;
- l->h = h;
- int out_w = convolutional_out_width(*l);
- int out_h = convolutional_out_height(*l);
+ l->w = w;
+ l->h = h;
+ int out_w = convolutional_out_width(*l);
+ int out_h = convolutional_out_height(*l);
- l->out_w = out_w;
- l->out_h = out_h;
+ l->out_w = out_w;
+ l->out_h = out_h;
- l->outputs = l->out_h * l->out_w * l->out_c;
- l->inputs = l->w * l->h * l->c;
+ l->outputs = l->out_h * l->out_w * l->out_c;
+ l->inputs = l->w * l->h * l->c;
- l->output = realloc(l->output, l->batch*l->outputs*sizeof(float));
- l->delta = realloc(l->delta, l->batch*l->outputs*sizeof(float));
- if(l->batch_normalize){
- l->x = realloc(l->x, l->batch*l->outputs*sizeof(float));
- l->x_norm = realloc(l->x_norm, l->batch*l->outputs*sizeof(float));
- }
+ l->output = realloc(l->output, l->batch*l->outputs*sizeof(float));
+ l->delta = realloc(l->delta, l->batch*l->outputs*sizeof(float));
+ if(l->batch_normalize){
+ l->x = realloc(l->x, l->batch*l->outputs*sizeof(float));
+ l->x_norm = realloc(l->x_norm, l->batch*l->outputs*sizeof(float));
+ }
#ifdef GPU
- cuda_free(l->delta_gpu);
+ cuda_free(l->delta_gpu);
cuda_free(l->output_gpu);
l->delta_gpu = cuda_make_array(l->delta, l->batch*l->outputs);
@@ -405,218 +408,218 @@ void resize_convolutional_layer(convolutional_layer *l, int w, int h)
cudnn_convolutional_setup(l);
#endif
#endif
- l->workspace_size = get_workspace_size(*l);
+ l->workspace_size = get_workspace_size(*l);
}
void add_bias(float *output, float *biases, int batch, int n, int size)
{
- int i,j,b;
- for(b = 0; b < batch; ++b){
- for(i = 0; i < n; ++i){
- for(j = 0; j < size; ++j){
- output[(b*n + i)*size + j] += biases[i];
- }
- }
- }
+ int i,j,b;
+ for(b = 0; b < batch; ++b){
+ for(i = 0; i < n; ++i){
+ for(j = 0; j < size; ++j){
+ output[(b*n + i)*size + j] += biases[i];
+ }
+ }
+ }
}
void scale_bias(float *output, float *scales, int batch, int n, int size)
{
- int i,j,b;
- for(b = 0; b < batch; ++b){
- for(i = 0; i < n; ++i){
- for(j = 0; j < size; ++j){
- output[(b*n + i)*size + j] *= scales[i];
- }
- }
- }
+ int i,j,b;
+ for(b = 0; b < batch; ++b){
+ for(i = 0; i < n; ++i){
+ for(j = 0; j < size; ++j){
+ output[(b*n + i)*size + j] *= scales[i];
+ }
+ }
+ }
}
void backward_bias(float *bias_updates, float *delta, int batch, int n, int size)
{
- int i,b;
- for(b = 0; b < batch; ++b){
- for(i = 0; i < n; ++i){
- bias_updates[i] += sum_array(delta+size*(i+b*n), size);
- }
- }
+ int i,b;
+ for(b = 0; b < batch; ++b){
+ for(i = 0; i < n; ++i){
+ bias_updates[i] += sum_array(delta+size*(i+b*n), size);
+ }
+ }
}
void forward_convolutional_layer(convolutional_layer l, network net)
{
- int i, j;
+ int i, j;
- fill_cpu(l.outputs*l.batch, 0, l.output, 1);
+ fill_cpu(l.outputs*l.batch, 0, l.output, 1);
- if(l.xnor){
- binarize_weights(l.weights, l.n, l.c/l.groups*l.size*l.size, l.binary_weights);
- swap_binary(&l);
- binarize_cpu(net.input, l.c*l.h*l.w*l.batch, l.binary_input);
- net.input = l.binary_input;
- }
+ if(l.xnor){
+ binarize_weights(l.weights, l.n, l.c/l.groups*l.size*l.size, l.binary_weights);
+ swap_binary(&l);
+ binarize_cpu(net.input, l.c*l.h*l.w*l.batch, l.binary_input);
+ net.input = l.binary_input;
+ }
- int m = l.n/l.groups;
- int k = l.size*l.size*l.c/l.groups;
- int n = l.out_w*l.out_h;
- for(i = 0; i < l.batch; ++i){
- for(j = 0; j < l.groups; ++j){
- float *a = l.weights + j*l.nweights/l.groups;
- float *b = net.workspace;
- float *c = l.output + (i*l.groups + j)*n*m;
- float *im = net.input + (i*l.groups + j)*l.c/l.groups*l.h*l.w;
+ int m = l.n/l.groups;
+ int k = l.size*l.size*l.c/l.groups;
+ int n = l.out_w*l.out_h;
+ for(i = 0; i < l.batch; ++i){
+ for(j = 0; j < l.groups; ++j){
+ float *a = l.weights + j*l.nweights/l.groups;
+ float *b = net.workspace;
+ float *c = l.output + (i*l.groups + j)*n*m;
+ float *im = net.input + (i*l.groups + j)*l.c/l.groups*l.h*l.w;
- if (l.size == 1) {
- b = im;
- } else {
- im2col_cpu(im, l.c/l.groups, l.h, l.w, l.size, l.stride, l.pad, b);
- }
- gemm(0,0,m,n,k,1,a,k,b,n,1,c,n);
- }
- }
+ if (l.size == 1) {
+ b = im;
+ } else {
+ im2col_cpu(im, l.c/l.groups, l.h, l.w, l.size, l.stride, l.pad, b);
+ }
+ gemm(0,0,m,n,k,1,a,k,b,n,1,c,n);
+ }
+ }
- if(l.batch_normalize){
- forward_batchnorm_layer(l, net);
- } else {
- add_bias(l.output, l.biases, l.batch, l.n, l.out_h*l.out_w);
- }
+ if(l.batch_normalize){
+ forward_batchnorm_layer(l, net);
+ } else {
+ add_bias(l.output, l.biases, l.batch, l.n, l.out_h*l.out_w);
+ }
- activate_array(l.output, l.outputs*l.batch, l.activation);
- if(l.binary || l.xnor) swap_binary(&l);
+ activate_array(l.output, l.outputs*l.batch, l.activation);
+ if(l.binary || l.xnor) swap_binary(&l);
}
void backward_convolutional_layer(convolutional_layer l, network net)
{
- int i, j;
- int m = l.n/l.groups;
- int n = l.size*l.size*l.c/l.groups;
- int k = l.out_w*l.out_h;
+ int i, j;
+ int m = l.n/l.groups;
+ int n = l.size*l.size*l.c/l.groups;
+ int k = l.out_w*l.out_h;
- gradient_array(l.output, l.outputs*l.batch, l.activation, l.delta);
+ gradient_array(l.output, l.outputs*l.batch, l.activation, l.delta);
- if(l.batch_normalize){
- backward_batchnorm_layer(l, net);
- } else {
- backward_bias(l.bias_updates, l.delta, l.batch, l.n, k);
- }
+ if(l.batch_normalize){
+ backward_batchnorm_layer(l, net);
+ } else {
+ backward_bias(l.bias_updates, l.delta, l.batch, l.n, k);
+ }
- for(i = 0; i < l.batch; ++i){
- for(j = 0; j < l.groups; ++j){
- float *a = l.delta + (i*l.groups + j)*m*k;
- float *b = net.workspace;
- float *c = l.weight_updates + j*l.nweights/l.groups;
+ for(i = 0; i < l.batch; ++i){
+ for(j = 0; j < l.groups; ++j){
+ float *a = l.delta + (i*l.groups + j)*m*k;
+ float *b = net.workspace;
+ float *c = l.weight_updates + j*l.nweights/l.groups;
- float *im = net.input + (i*l.groups + j)*l.c/l.groups*l.h*l.w;
- float *imd = net.delta + (i*l.groups + j)*l.c/l.groups*l.h*l.w;
+ float *im = net.input + (i*l.groups + j)*l.c/l.groups*l.h*l.w;
+ float *imd = net.delta + (i*l.groups + j)*l.c/l.groups*l.h*l.w;
- if(l.size == 1){
- b = im;
- } else {
- im2col_cpu(im, l.c/l.groups, l.h, l.w,
- l.size, l.stride, l.pad, b);
+ if(l.size == 1){
+ b = im;
+ } else {
+ im2col_cpu(im, l.c/l.groups, l.h, l.w,
+ l.size, l.stride, l.pad, b);
+ }
+
+ gemm(0,1,m,n,k,1,a,k,b,k,1,c,n);
+
+ if (net.delta) {
+ a = l.weights + j*l.nweights/l.groups;
+ b = l.delta + (i*l.groups + j)*m*k;
+ c = net.workspace;
+ if (l.size == 1) {
+ c = imd;
}
- gemm(0,1,m,n,k,1,a,k,b,k,1,c,n);
+ gemm(1,0,n,k,m,1,a,n,b,k,0,c,k);
- if (net.delta) {
- a = l.weights + j*l.nweights/l.groups;
- b = l.delta + (i*l.groups + j)*m*k;
- c = net.workspace;
- if (l.size == 1) {
- c = imd;
- }
-
- gemm(1,0,n,k,m,1,a,n,b,k,0,c,k);
-
- if (l.size != 1) {
- col2im_cpu(net.workspace, l.c/l.groups, l.h, l.w, l.size, l.stride, l.pad, imd);
- }
+ if (l.size != 1) {
+ col2im_cpu(net.workspace, l.c/l.groups, l.h, l.w, l.size, l.stride, l.pad, imd);
}
- }
- }
+ }
+ }
+ }
}
void update_convolutional_layer(convolutional_layer l, update_args a)
{
- float learning_rate = a.learning_rate*l.learning_rate_scale;
- float momentum = a.momentum;
- float decay = a.decay;
- int batch = a.batch;
+ float learning_rate = a.learning_rate*l.learning_rate_scale;
+ float momentum = a.momentum;
+ float decay = a.decay;
+ int batch = a.batch;
- axpy_cpu(l.n, learning_rate/batch, l.bias_updates, 1, l.biases, 1);
- scal_cpu(l.n, momentum, l.bias_updates, 1);
+ axpy_cpu(l.n, learning_rate/batch, l.bias_updates, 1, l.biases, 1);
+ scal_cpu(l.n, momentum, l.bias_updates, 1);
- if(l.scales){
- axpy_cpu(l.n, learning_rate/batch, l.scale_updates, 1, l.scales, 1);
- scal_cpu(l.n, momentum, l.scale_updates, 1);
- }
+ if(l.scales){
+ axpy_cpu(l.n, learning_rate/batch, l.scale_updates, 1, l.scales, 1);
+ scal_cpu(l.n, momentum, l.scale_updates, 1);
+ }
- axpy_cpu(l.nweights, -decay*batch, l.weights, 1, l.weight_updates, 1);
- axpy_cpu(l.nweights, learning_rate/batch, l.weight_updates, 1, l.weights, 1);
- scal_cpu(l.nweights, momentum, l.weight_updates, 1);
+ axpy_cpu(l.nweights, -decay*batch, l.weights, 1, l.weight_updates, 1);
+ axpy_cpu(l.nweights, learning_rate/batch, l.weight_updates, 1, l.weights, 1);
+ scal_cpu(l.nweights, momentum, l.weight_updates, 1);
}
image get_convolutional_weight(convolutional_layer l, int i)
{
- int h = l.size;
- int w = l.size;
- int c = l.c/l.groups;
- return float_to_image(w,h,c,l.weights+i*h*w*c);
+ int h = l.size;
+ int w = l.size;
+ int c = l.c/l.groups;
+ return float_to_image(w,h,c,l.weights+i*h*w*c);
}
void rgbgr_weights(convolutional_layer l)
{
- int i;
- for(i = 0; i < l.n; ++i){
- image im = get_convolutional_weight(l, i);
- if (im.c == 3) {
- rgbgr_image(im);
- }
- }
+ int i;
+ for(i = 0; i < l.n; ++i){
+ image im = get_convolutional_weight(l, i);
+ if (im.c == 3) {
+ rgbgr_image(im);
+ }
+ }
}
void rescale_weights(convolutional_layer l, float scale, float trans)
{
- int i;
- for(i = 0; i < l.n; ++i){
- image im = get_convolutional_weight(l, i);
- if (im.c == 3) {
- scale_image(im, scale);
- float sum = sum_array(im.data, im.w*im.h*im.c);
- l.biases[i] += sum*trans;
- }
- }
+ int i;
+ for(i = 0; i < l.n; ++i){
+ image im = get_convolutional_weight(l, i);
+ if (im.c == 3) {
+ scale_image(im, scale);
+ float sum = sum_array(im.data, im.w*im.h*im.c);
+ l.biases[i] += sum*trans;
+ }
+ }
}
image *get_weights(convolutional_layer l)
{
- image *weights = calloc(l.n, sizeof(image));
- int i;
- for(i = 0; i < l.n; ++i){
- weights[i] = copy_image(get_convolutional_weight(l, i));
- normalize_image(weights[i]);
- /*
- char buff[256];
- sprintf(buff, "filter%d", i);
- save_image(weights[i], buff);
- */
- }
- //error("hey");
- return weights;
+ image *weights = calloc(l.n, sizeof(image));
+ int i;
+ for(i = 0; i < l.n; ++i){
+ weights[i] = copy_image(get_convolutional_weight(l, i));
+ normalize_image(weights[i]);
+ /*
+ char buff[256];
+ sprintf(buff, "filter%d", i);
+ save_image(weights[i], buff);
+ */
+ }
+ //error("hey");
+ return weights;
}
image *visualize_convolutional_layer(convolutional_layer l, char *window, image *prev_weights)
{
- image *single_weights = get_weights(l);
- show_images(single_weights, l.n, window);
+ image *single_weights = get_weights(l);
+ show_images(single_weights, l.n, window);
- image delta = get_convolutional_image(l);
- image dc = collapse_image_layers(delta, 1);
- char buff[256];
- sprintf(buff, "%s: Output", window);
- //show_image(dc, buff);
- //save_image(dc, buff);
- free_image(dc);
- return single_weights;
+ image delta = get_convolutional_image(l);
+ image dc = collapse_image_layers(delta, 1);
+ char buff[256];
+ sprintf(buff, "%s: Output", window);
+ //show_image(dc, buff);
+ //save_image(dc, buff);
+ free_image(dc);
+ return single_weights;
}
diff --git a/src/activation_kernels.cu b/src/cuda/activation_kernels.cu
similarity index 100%
rename from src/activation_kernels.cu
rename to src/cuda/activation_kernels.cu
diff --git a/src/avgpool_layer_kernels.cu b/src/cuda/avgpool_layer_kernels.cu
similarity index 100%
rename from src/avgpool_layer_kernels.cu
rename to src/cuda/avgpool_layer_kernels.cu
diff --git a/src/blas_kernels.cu b/src/cuda/blas_kernels.cu
similarity index 100%
rename from src/blas_kernels.cu
rename to src/cuda/blas_kernels.cu
diff --git a/src/col2im_kernels.cu b/src/cuda/col2im_kernels.cu
similarity index 100%
rename from src/col2im_kernels.cu
rename to src/cuda/col2im_kernels.cu
diff --git a/src/convolutional_kernels.cu b/src/cuda/convolutional_kernels.cu
similarity index 100%
rename from src/convolutional_kernels.cu
rename to src/cuda/convolutional_kernels.cu
diff --git a/src/crop_layer_kernels.cu b/src/cuda/crop_layer_kernels.cu
similarity index 100%
rename from src/crop_layer_kernels.cu
rename to src/cuda/crop_layer_kernels.cu
diff --git a/src/deconvolutional_kernels.cu b/src/cuda/deconvolutional_kernels.cu
similarity index 100%
rename from src/deconvolutional_kernels.cu
rename to src/cuda/deconvolutional_kernels.cu
diff --git a/src/dropout_layer_kernels.cu b/src/cuda/dropout_layer_kernels.cu
similarity index 100%
rename from src/dropout_layer_kernels.cu
rename to src/cuda/dropout_layer_kernels.cu
diff --git a/src/im2col_kernels.cu b/src/cuda/im2col_kernels.cu
similarity index 100%
rename from src/im2col_kernels.cu
rename to src/cuda/im2col_kernels.cu
diff --git a/src/maxpool_layer_kernels.cu b/src/cuda/maxpool_layer_kernels.cu
similarity index 100%
rename from src/maxpool_layer_kernels.cu
rename to src/cuda/maxpool_layer_kernels.cu
diff --git a/src/parser.c b/src/parser.c
index c8141c9f..d50a8eca 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -739,7 +739,7 @@ int is_network(section *s)
|| strcmp(s->type, "[network]")==0);
}
-network *parse_network_cfg(char *filename)
+network* parse_network_cfg(char *filename)
{
list *sections = read_cfg(filename);
node *n = sections->front;