mirror of
https://github.com/pjreddie/darknet.git
synced 2023-08-10 21:13:14 +03:00
Added dice code
This commit is contained in:
parent
eb98da5000
commit
5635523326
6
Makefile
6
Makefile
@ -1,5 +1,5 @@
|
||||
GPU=0
|
||||
OPENCV=0
|
||||
GPU=1
|
||||
OPENCV=1
|
||||
DEBUG=0
|
||||
|
||||
ARCH= --gpu-architecture=compute_20 --gpu-code=compute_20
|
||||
@ -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 detection.o route_layer.o writing.o box.o nightmare.o normalization_layer.o avgpool_layer.o coco.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 detection.o route_layer.o writing.o box.o nightmare.o normalization_layer.o avgpool_layer.o coco.o dice.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
|
||||
endif
|
||||
|
20
scripts/dice_label.sh
Normal file
20
scripts/dice_label.sh
Normal file
@ -0,0 +1,20 @@
|
||||
mkdir -p images
|
||||
mkdir -p images/orig
|
||||
mkdir -p images/train
|
||||
mkdir -p images/val
|
||||
|
||||
ffmpeg -i Face1.mp4 images/orig/face1_%6d.jpg
|
||||
ffmpeg -i Face2.mp4 images/orig/face2_%6d.jpg
|
||||
ffmpeg -i Face3.mp4 images/orig/face3_%6d.jpg
|
||||
ffmpeg -i Face4.mp4 images/orig/face4_%6d.jpg
|
||||
ffmpeg -i Face5.mp4 images/orig/face5_%6d.jpg
|
||||
ffmpeg -i Face6.mp4 images/orig/face6_%6d.jpg
|
||||
|
||||
mogrify -resize 100x100^ -gravity center -crop 100x100+0+0 +repage images/orig/*
|
||||
|
||||
ls images/orig/* | shuf | head -n 1000 | xargs mv -t images/val
|
||||
mv images/orig/* images/train
|
||||
|
||||
find `pwd`/images/train > dice.train.list -name \*.jpg
|
||||
find `pwd`/images/val > dice.val.list -name \*.jpg
|
||||
|
@ -15,6 +15,7 @@ extern void run_coco(int argc, char **argv);
|
||||
extern void run_writing(int argc, char **argv);
|
||||
extern void run_captcha(int argc, char **argv);
|
||||
extern void run_nightmare(int argc, char **argv);
|
||||
extern void run_dice(int argc, char **argv);
|
||||
|
||||
void change_rate(char *filename, float scale, float add)
|
||||
{
|
||||
@ -115,6 +116,8 @@ int main(int argc, char **argv)
|
||||
run_detection(argc, argv);
|
||||
} else if (0 == strcmp(argv[1], "coco")){
|
||||
run_coco(argc, argv);
|
||||
} else if (0 == strcmp(argv[1], "dice")){
|
||||
run_dice(argc, argv);
|
||||
} else if (0 == strcmp(argv[1], "writing")){
|
||||
run_writing(argc, argv);
|
||||
} else if (0 == strcmp(argv[1], "test")){
|
||||
|
118
src/dice.c
Normal file
118
src/dice.c
Normal file
@ -0,0 +1,118 @@
|
||||
#include "network.h"
|
||||
#include "utils.h"
|
||||
#include "parser.h"
|
||||
|
||||
char *dice_labels[] = {"face1","face2","face3","face4","face5","face6"};
|
||||
|
||||
void train_dice(char *cfgfile, char *weightfile)
|
||||
{
|
||||
data_seed = time(0);
|
||||
srand(time(0));
|
||||
float avg_loss = -1;
|
||||
char *base = basecfg(cfgfile);
|
||||
char *backup_directory = "/home/pjreddie/backup/";
|
||||
printf("%s\n", base);
|
||||
network net = parse_network_cfg(cfgfile);
|
||||
if(weightfile){
|
||||
load_weights(&net, weightfile);
|
||||
}
|
||||
printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net.learning_rate, net.momentum, net.decay);
|
||||
int imgs = 1024;
|
||||
int i = net.seen/imgs;
|
||||
char **labels = dice_labels;
|
||||
list *plist = get_paths("data/dice/dice.train.list");
|
||||
char **paths = (char **)list_to_array(plist);
|
||||
printf("%d\n", plist->size);
|
||||
clock_t time;
|
||||
while(1){
|
||||
++i;
|
||||
time=clock();
|
||||
data train = load_data(paths, imgs, plist->size, labels, 6, net.w, net.h);
|
||||
printf("Loaded: %lf seconds\n", sec(clock()-time));
|
||||
|
||||
time=clock();
|
||||
float loss = train_network(net, train);
|
||||
net.seen += imgs;
|
||||
if(avg_loss == -1) avg_loss = loss;
|
||||
avg_loss = avg_loss*.9 + loss*.1;
|
||||
printf("%d: %f, %f avg, %lf seconds, %d images\n", i, loss, avg_loss, sec(clock()-time), net.seen);
|
||||
free_data(train);
|
||||
if((i % 100) == 0) net.learning_rate *= .1;
|
||||
if(i%100==0){
|
||||
char buff[256];
|
||||
sprintf(buff, "%s/%s_%d.weights",backup_directory,base, i);
|
||||
save_weights(net, buff);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void validate_dice(char *filename, char *weightfile)
|
||||
{
|
||||
network net = parse_network_cfg(filename);
|
||||
if(weightfile){
|
||||
load_weights(&net, weightfile);
|
||||
}
|
||||
srand(time(0));
|
||||
|
||||
char **labels = dice_labels;
|
||||
list *plist = get_paths("data/dice/dice.val.list");
|
||||
|
||||
char **paths = (char **)list_to_array(plist);
|
||||
int m = plist->size;
|
||||
free_list(plist);
|
||||
|
||||
data val = load_data(paths, m, 0, labels, 6, net.w, net.h);
|
||||
float *acc = network_accuracies(net, val);
|
||||
printf("Validation Accuracy: %f, %d images\n", acc[0], m);
|
||||
free_data(val);
|
||||
}
|
||||
|
||||
void test_dice(char *cfgfile, char *weightfile, char *filename)
|
||||
{
|
||||
network net = parse_network_cfg(cfgfile);
|
||||
if(weightfile){
|
||||
load_weights(&net, weightfile);
|
||||
}
|
||||
set_batch_network(&net, 1);
|
||||
srand(2222222);
|
||||
int i = 0;
|
||||
char **names = dice_labels;
|
||||
char input[256];
|
||||
int indexes[6];
|
||||
while(1){
|
||||
if(filename){
|
||||
strncpy(input, filename, 256);
|
||||
}else{
|
||||
printf("Enter Image Path: ");
|
||||
fflush(stdout);
|
||||
fgets(input, 256, stdin);
|
||||
strtok(input, "\n");
|
||||
}
|
||||
image im = load_image_color(input, net.w, net.h);
|
||||
float *X = im.data;
|
||||
float *predictions = network_predict(net, X);
|
||||
top_predictions(net, 6, indexes);
|
||||
for(i = 0; i < 6; ++i){
|
||||
int index = indexes[i];
|
||||
printf("%s: %f\n", names[index], predictions[index]);
|
||||
}
|
||||
free_image(im);
|
||||
if (filename) break;
|
||||
}
|
||||
}
|
||||
|
||||
void run_dice(int argc, char **argv)
|
||||
{
|
||||
if(argc < 4){
|
||||
fprintf(stderr, "usage: %s %s [train/test/valid] [cfg] [weights (optional)]\n", argv[0], argv[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
char *cfg = argv[3];
|
||||
char *weights = (argc > 4) ? argv[4] : 0;
|
||||
char *filename = (argc > 5) ? argv[5]: 0;
|
||||
if(0==strcmp(argv[2], "test")) test_dice(cfg, weights, filename);
|
||||
else if(0==strcmp(argv[2], "train")) train_dice(cfg, weights);
|
||||
else if(0==strcmp(argv[2], "valid")) validate_dice(cfg, weights);
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ void train_imagenet(char *cfgfile, char *weightfile)
|
||||
srand(time(0));
|
||||
float avg_loss = -1;
|
||||
char *base = basecfg(cfgfile);
|
||||
char *backup_directory = "/home/pjreddie/backup/";
|
||||
printf("%s\n", base);
|
||||
network net = parse_network_cfg(cfgfile);
|
||||
if(weightfile){
|
||||
@ -50,7 +51,7 @@ void train_imagenet(char *cfgfile, char *weightfile)
|
||||
if((i % 30000) == 0) net.learning_rate *= .1;
|
||||
if(i%1000==0){
|
||||
char buff[256];
|
||||
sprintf(buff, "/home/pjreddie/imagenet_backup/%s_%d.weights",base, i);
|
||||
sprintf(buff, "%s/%s_%d.weights",backup_directory,base, i);
|
||||
save_weights(net, buff);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user