Skip to content

Commit

Permalink
new font strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
pjreddie committed Nov 5, 2016
1 parent 352ae7e commit c7a700d
Show file tree
Hide file tree
Showing 113 changed files with 331 additions and 210 deletions.
Binary file removed data/labels/100.png
Binary file not shown.
Binary file removed data/labels/101.png
Binary file not shown.
Binary file removed data/labels/102.png
Binary file not shown.
Binary file removed data/labels/103.png
Binary file not shown.
Binary file removed data/labels/104.png
Binary file not shown.
Binary file removed data/labels/105.png
Binary file not shown.
Binary file removed data/labels/106.png
Binary file not shown.
Binary file removed data/labels/107.png
Binary file not shown.
Binary file removed data/labels/108.png
Binary file not shown.
Binary file removed data/labels/109.png
Binary file not shown.
Binary file removed data/labels/110.png
Binary file not shown.
Binary file removed data/labels/111.png
Binary file not shown.
Binary file removed data/labels/112.png
Binary file not shown.
Binary file removed data/labels/113.png
Binary file not shown.
Binary file removed data/labels/114.png
Binary file not shown.
Binary file removed data/labels/115.png
Binary file not shown.
Binary file removed data/labels/116.png
Binary file not shown.
Binary file removed data/labels/117.png
Binary file not shown.
Binary file removed data/labels/118.png
Binary file not shown.
Binary file removed data/labels/119.png
Binary file not shown.
Binary file removed data/labels/120.png
Binary file not shown.
Binary file removed data/labels/121.png
Binary file not shown.
Binary file removed data/labels/122.png
Binary file not shown.
Binary file removed data/labels/123.png
Binary file not shown.
Binary file removed data/labels/124.png
Binary file not shown.
Binary file removed data/labels/125.png
Diff not rendered.
Binary file removed data/labels/126.png
Diff not rendered.
Binary file removed data/labels/32.png
Diff not rendered.
Binary file removed data/labels/33.png
Diff not rendered.
Binary file removed data/labels/34.png
Diff not rendered.
Binary file removed data/labels/35.png
Diff not rendered.
Binary file removed data/labels/36.png
Diff not rendered.
Binary file removed data/labels/37.png
Diff not rendered.
Binary file removed data/labels/38.png
Diff not rendered.
Binary file removed data/labels/39.png
Diff not rendered.
Binary file removed data/labels/40.png
Diff not rendered.
Binary file removed data/labels/41.png
Diff not rendered.
Binary file removed data/labels/42.png
Diff not rendered.
Binary file removed data/labels/43.png
Diff not rendered.
Binary file removed data/labels/44.png
Diff not rendered.
Binary file removed data/labels/45.png
Diff not rendered.
Binary file removed data/labels/46.png
Diff not rendered.
Binary file removed data/labels/47.png
Diff not rendered.
Binary file removed data/labels/48.png
Diff not rendered.
Binary file removed data/labels/49.png
Diff not rendered.
Binary file removed data/labels/50.png
Diff not rendered.
Binary file removed data/labels/51.png
Diff not rendered.
Binary file removed data/labels/52.png
Diff not rendered.
Binary file removed data/labels/53.png
Diff not rendered.
Binary file removed data/labels/54.png
Diff not rendered.
Binary file removed data/labels/55.png
Diff not rendered.
Binary file removed data/labels/56.png
Diff not rendered.
Binary file removed data/labels/57.png
Diff not rendered.
Binary file removed data/labels/58.png
Diff not rendered.
Binary file removed data/labels/59.png
Diff not rendered.
Binary file removed data/labels/60.png
Diff not rendered.
Binary file removed data/labels/61.png
Diff not rendered.
Binary file removed data/labels/62.png
Diff not rendered.
Binary file removed data/labels/63.png
Diff not rendered.
Binary file removed data/labels/64.png
Diff not rendered.
Binary file removed data/labels/65.png
Diff not rendered.
Binary file removed data/labels/66.png
Diff not rendered.
Binary file removed data/labels/67.png
Diff not rendered.
Binary file removed data/labels/68.png
Diff not rendered.
Binary file removed data/labels/69.png
Diff not rendered.
Binary file removed data/labels/70.png
Diff not rendered.
Binary file removed data/labels/71.png
Diff not rendered.
Binary file removed data/labels/72.png
Diff not rendered.
Binary file removed data/labels/73.png
Diff not rendered.
Binary file removed data/labels/74.png
Diff not rendered.
Binary file removed data/labels/75.png
Diff not rendered.
Binary file removed data/labels/76.png
Diff not rendered.
Binary file removed data/labels/77.png
Diff not rendered.
Binary file removed data/labels/78.png
Diff not rendered.
Binary file removed data/labels/79.png
Diff not rendered.
Binary file removed data/labels/80.png
Diff not rendered.
Binary file removed data/labels/81.png
Diff not rendered.
Binary file removed data/labels/82.png
Diff not rendered.
Binary file removed data/labels/83.png
Diff not rendered.
Binary file removed data/labels/84.png
Diff not rendered.
Binary file removed data/labels/85.png
Diff not rendered.
Binary file removed data/labels/86.png
Diff not rendered.
Binary file removed data/labels/87.png
Diff not rendered.
Binary file removed data/labels/88.png
Diff not rendered.
Binary file removed data/labels/89.png
Diff not rendered.
Binary file removed data/labels/90.png
Diff not rendered.
Binary file removed data/labels/91.png
Diff not rendered.
Binary file removed data/labels/92.png
Diff not rendered.
Binary file removed data/labels/93.png
Diff not rendered.
Binary file removed data/labels/94.png
Diff not rendered.
Binary file removed data/labels/95.png
Diff not rendered.
Binary file removed data/labels/96.png
Diff not rendered.
Binary file removed data/labels/97.png
Diff not rendered.
Binary file removed data/labels/98.png
Diff not rendered.
Binary file removed data/labels/99.png
Diff not rendered.
28 changes: 16 additions & 12 deletions data/labels/make_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@
import string
import pipes

#l = ["person","bicycle","car","motorcycle","airplane","bus","train","truck","boat","traffic light","fire hydrant","stop sign","parking meter","bench","bird","cat","dog","horse","sheep","cow","elephant","bear","zebra","giraffe","backpack","umbrella","handbag","tie","suitcase","frisbee","skis","snowboard","sports ball","kite","baseball bat","baseball glove","skateboard","surfboard","tennis racket","bottle","wine glass","cup","fork","knife","spoon","bowl","banana","apple","sandwich","orange","broccoli","carrot","hot dog","pizza","donut","cake","chair","couch","potted plant","bed","dining table","toilet","tv","laptop","mouse","remote","keyboard","cell phone","microwave","oven","toaster","sink","refrigerator","book","clock","vase","scissors","teddy bear","hair drier","toothbrush", "aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair", "cow", "diningtable", "dog", "horse", "motorbike", "person", "pottedplant", "sheep", "sofa", "train", "tvmonitor"]
font = 'futura-normal'

l = string.printable
def make_labels(s):
l = string.printable
for word in l:
if word == ' ':
os.system('convert -fill black -background white -bordercolor white -font %s -pointsize %d label:"\ " 32_%d.png'%(font,s,s/12-1))
if word == '@':
os.system('convert -fill black -background white -bordercolor white -font %s -pointsize %d label:"\@" 64_%d.png'%(font,s,s/12-1))
elif word == '\\':
os.system('convert -fill black -background white -bordercolor white -font %s -pointsize %d label:"\\\\\\\\" 92_%d.png'%(font,s,s/12-1))
elif ord(word) in [9,10,11,12,13,14]:
pass
else:
os.system("convert -fill black -background white -bordercolor white -font %s -pointsize %d label:%s \"%d_%d.png\""%(font,s,pipes.quote(word), ord(word),s/12-1))

for word in l:
#os.system("convert -fill black -background white -bordercolor white -border 4 -font futura-normal -pointsize 18 label:\"%s\" \"%s.png\""%(word, word))
if word == ' ':
os.system('convert -fill black -background white -bordercolor white -font futura-normal -pointsize 64 label:"\ " 32.png')
elif word == '\\':
os.system('convert -fill black -background white -bordercolor white -font futura-normal -pointsize 64 label:"\\\\\\\\" 92.png')
elif ord(word) in [9,10,11,12,13,14]:
pass
else:
os.system("convert -fill black -background white -bordercolor white -font futura-normal -pointsize 64 label:%s \"%d.png\""%(pipes.quote(word), ord(word)))
for i in [12,24,36,48,60,72,84,96]:
make_labels(i)

64 changes: 0 additions & 64 deletions src/classifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,50 +13,6 @@
image get_image_from_stream(CvCapture *cap);
#endif

list *read_data_cfg(char *filename)
{
FILE *file = fopen(filename, "r");
if(file == 0) file_error(filename);
char *line;
int nu = 0;
list *options = make_list();
while((line=fgetl(file)) != 0){
++ nu;
strip(line);
switch(line[0]){
case '\0':
case '#':
case ';':
free(line);
break;
default:
if(!read_option(line, options)){
fprintf(stderr, "Config file error line %d, could parse: %s\n", nu, line);
free(line);
}
break;
}
}
fclose(file);
return options;
}

void hierarchy_predictions(float *predictions, int n, tree *hier, int only_leaves)
{
int j;
for(j = 0; j < n; ++j){
int parent = hier->parent[j];
if(parent >= 0){
predictions[j] *= predictions[parent];
}
}
if(only_leaves){
for(j = 0; j < n; ++j){
if(!hier->leaf[j]) predictions[j] = 0;
}
}
}

float *get_regression_values(char **labels, int n)
{
float *v = calloc(n, sizeof(float));
Expand Down Expand Up @@ -488,26 +444,6 @@ void validate_classifier_full(char *datacfg, char *filename, char *weightfile)
}
}

void change_leaves(tree *t, char *leaf_list)
{
list *llist = get_paths(leaf_list);
char **leaves = (char **)list_to_array(llist);
int n = llist->size;
int i,j;
int found = 0;
for(i = 0; i < t->n; ++i){
t->leaf[i] = 0;
for(j = 0; j < n; ++j){
if (0==strcmp(t->name[i], leaves[j])){
t->leaf[i] = 1;
++found;
break;
}
}
}
fprintf(stderr, "Found %d leaves.\n", found);
}


void validate_classifier_single(char *datacfg, char *filename, char *weightfile)
{
Expand Down
2 changes: 1 addition & 1 deletion src/coco.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ void validate_coco_recall(char *cfgfile, char *weightfile)

void test_coco(char *cfgfile, char *weightfile, char *filename, float thresh)
{
image *alphabet = load_alphabet();
image **alphabet = load_alphabet();
network net = parse_network_cfg(cfgfile);
if(weightfile){
load_weights(&net, weightfile);
Expand Down
8 changes: 8 additions & 0 deletions src/convolutional_kernels.cu
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ void pull_convolutional_layer(convolutional_layer layer)
cuda_pull_array(layer.rolling_mean_gpu, layer.rolling_mean, layer.n);
cuda_pull_array(layer.rolling_variance_gpu, layer.rolling_variance, layer.n);
}
if (layer.adam){
cuda_pull_array(layer.m_gpu, layer.m, layer.c*layer.n*layer.size*layer.size);
cuda_pull_array(layer.v_gpu, layer.v, layer.c*layer.n*layer.size*layer.size);
}
}

void push_convolutional_layer(convolutional_layer layer)
Expand All @@ -228,6 +232,10 @@ void push_convolutional_layer(convolutional_layer layer)
cuda_push_array(layer.rolling_mean_gpu, layer.rolling_mean, layer.n);
cuda_push_array(layer.rolling_variance_gpu, layer.rolling_variance, layer.n);
}
if (layer.adam){
cuda_push_array(layer.m_gpu, layer.m, layer.c*layer.n*layer.size*layer.size);
cuda_push_array(layer.v_gpu, layer.v, layer.c*layer.n*layer.size*layer.size);
}
}

void update_convolutional_layer_gpu(convolutional_layer layer, int batch, float learning_rate, float momentum, float decay)
Expand Down
10 changes: 7 additions & 3 deletions src/convolutional_layer.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ convolutional_layer make_convolutional_layer(int batch, int h, int w, int c, int
l.rolling_mean = calloc(n, sizeof(float));
l.rolling_variance = calloc(n, sizeof(float));
}
if(adam){
l.adam = 1;
l.m = calloc(c*n*size*size, sizeof(float));
l.v = calloc(c*n*size*size, sizeof(float));
}

#ifdef GPU
l.forward_gpu = forward_convolutional_layer_gpu;
Expand All @@ -243,9 +248,8 @@ convolutional_layer make_convolutional_layer(int batch, int h, int w, int c, int

if(gpu_index >= 0){
if (adam) {
l.adam = 1;
l.m_gpu = cuda_make_array(l.weight_updates, c*n*size*size);
l.v_gpu = cuda_make_array(l.weight_updates, c*n*size*size);
l.m_gpu = cuda_make_array(l.m, c*n*size*size);
l.v_gpu = cuda_make_array(l.v, c*n*size*size);
}

l.weights_gpu = cuda_make_array(l.weights, c*n*size*size);
Expand Down
4 changes: 2 additions & 2 deletions src/demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
image get_image_from_stream(CvCapture *cap);

static char **demo_names;
static image *demo_alphabet;
static image **demo_alphabet;
static int demo_classes;

static float **probs;
Expand Down Expand Up @@ -94,7 +94,7 @@ double get_wall_time()
void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const char *filename, char **names, int classes, int frame_skip, char *prefix)
{
//skip = frame_skip;
image *alphabet = load_alphabet();
image **alphabet = load_alphabet();
int delay = frame_skip;
demo_names = names;
demo_alphabet = alphabet;
Expand Down
67 changes: 38 additions & 29 deletions src/detector.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
#include "parser.h"
#include "box.h"
#include "demo.h"
#include "option_list.h"

#ifdef OPENCV
#include "opencv2/highgui/highgui_c.h"
#endif

static char *voc_names[] = {"aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair", "cow", "diningtable", "dog", "horse", "motorbike", "person", "pottedplant", "sheep", "sofa", "train", "tvmonitor"};

void train_detector(char *cfgfile, char *weightfile)
void train_detector(char *datacfg, char *cfgfile, char *weightfile, int clear)
{
char *train_images = "/data/voc/train.txt";
char *backup_directory = "/home/pjreddie/backup/";
list *options = read_data_cfg(datacfg);
char *train_images = option_find_str(options, "train", "data/train.list");
char *backup_directory = option_find_str(options, "backup", "/backup/");

srand(time(0));
char *base = basecfg(cfgfile);
printf("%s\n", base);
Expand All @@ -24,6 +25,7 @@ void train_detector(char *cfgfile, char *weightfile)
if(weightfile){
load_weights(&net, weightfile);
}
if(clear) *net.seen = 0;
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;
Expand Down Expand Up @@ -124,8 +126,13 @@ void print_detector_detections(FILE **fps, char *id, box *boxes, float **probs,
}
}

void validate_detector(char *cfgfile, char *weightfile)
void validate_detector(char *datacfg, char *cfgfile, char *weightfile)
{
list *options = read_data_cfg(datacfg);
char *valid_images = option_find_str(options, "valid", "data/train.list");
char *name_list = option_find_str(options, "names", "data/names.list");
char **names = get_labels(name_list);

network net = parse_network_cfg(cfgfile);
if(weightfile){
load_weights(&net, weightfile);
Expand All @@ -135,9 +142,7 @@ void validate_detector(char *cfgfile, char *weightfile)
srand(time(0));

char *base = "results/comp4_det_test_";
//list *plist = get_paths("data/voc.2007.test");
list *plist = get_paths("/home/pjreddie/data/voc/2007_test.txt");
//list *plist = get_paths("data/voc.2012.test");
list *plist = get_paths(valid_images);
char **paths = (char **)list_to_array(plist);

layer l = net.layers[net.n-1];
Expand All @@ -147,7 +152,7 @@ void validate_detector(char *cfgfile, char *weightfile)
FILE **fps = calloc(classes, sizeof(FILE *));
for(j = 0; j < classes; ++j){
char buff[1024];
snprintf(buff, 1024, "%s%s.txt", base, voc_names[j]);
snprintf(buff, 1024, "%s%s.txt", base, names[j]);
fps[j] = fopen(buff, "w");
}
box *boxes = calloc(l.w*l.h*l.n, sizeof(box));
Expand Down Expand Up @@ -224,20 +229,13 @@ void validate_detector_recall(char *cfgfile, char *weightfile)
fprintf(stderr, "Learning Rate: %g, Momentum: %g, Decay: %g\n", net.learning_rate, net.momentum, net.decay);
srand(time(0));

char *base = "results/comp4_det_test_";
list *plist = get_paths("data/voc.2007.test");
char **paths = (char **)list_to_array(plist);

layer l = net.layers[net.n-1];
int classes = l.classes;

int j, k;
FILE **fps = calloc(classes, sizeof(FILE *));
for(j = 0; j < classes; ++j){
char buff[1024];
snprintf(buff, 1024, "%s%s.txt", base, voc_names[j]);
fps[j] = fopen(buff, "w");
}
box *boxes = calloc(l.w*l.h*l.n, sizeof(box));
float **probs = calloc(l.w*l.h*l.n, sizeof(float *));
for(j = 0; j < l.w*l.h*l.n; ++j) probs[j] = calloc(classes, sizeof(float *));
Expand Down Expand Up @@ -299,9 +297,13 @@ void validate_detector_recall(char *cfgfile, char *weightfile)
}
}

void test_detector(char *cfgfile, char *weightfile, char *filename, float thresh)
void test_detector(char *datacfg, char *cfgfile, char *weightfile, char *filename, float thresh)
{
image *alphabet = load_alphabet();
list *options = read_data_cfg(datacfg);
char *name_list = option_find_str(options, "names", "data/names.list");
char **names = get_labels(name_list);

image **alphabet = load_alphabet();
network net = parse_network_cfg(cfgfile);
if(weightfile){
load_weights(&net, weightfile);
Expand Down Expand Up @@ -335,8 +337,7 @@ void test_detector(char *cfgfile, char *weightfile, char *filename, float thresh
printf("%s: Predicted in %f seconds.\n", input, sec(clock()-time));
get_region_boxes(l, 1, 1, thresh, probs, boxes, 0);
if (nms) do_nms_sort(boxes, probs, l.w*l.h*l.n, l.classes, nms);
//draw_detections(im, l.w*l.h*l.n, thresh, boxes, probs, voc_names, voc_labels, 20);
draw_detections(im, l.w*l.h*l.n, thresh, boxes, probs, voc_names, alphabet, 20);
draw_detections(im, l.w*l.h*l.n, thresh, boxes, probs, names, alphabet, l.classes);
save_image(im, "predictions");
show_image(im, "predictions");

Expand All @@ -360,13 +361,21 @@ void run_detector(int argc, char **argv)
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_detector(cfg, weights, filename, thresh);
else if(0==strcmp(argv[2], "train")) train_detector(cfg, weights);
else if(0==strcmp(argv[2], "valid")) validate_detector(cfg, weights);
int clear = find_arg(argc, argv, "-clear");

char *datacfg = argv[3];
char *cfg = argv[4];
char *weights = (argc > 5) ? argv[5] : 0;
char *filename = (argc > 6) ? argv[6]: 0;
if(0==strcmp(argv[2], "test")) test_detector(datacfg, cfg, weights, filename, thresh);
else if(0==strcmp(argv[2], "train")) train_detector(datacfg, cfg, weights, clear);
else if(0==strcmp(argv[2], "valid")) validate_detector(datacfg, cfg, weights);
else if(0==strcmp(argv[2], "recall")) validate_detector_recall(cfg, weights);
else if(0==strcmp(argv[2], "demo")) demo(cfg, weights, thresh, cam_index, filename, voc_names, 20, frame_skip, prefix);
else if(0==strcmp(argv[2], "demo")) {
list *options = read_data_cfg(datacfg);
int classes = option_find_int(options, "classes", 20);
char *name_list = option_find_str(options, "names", "data/names.list");
char **names = get_labels(name_list);
demo(cfg, weights, thresh, cam_index, filename, names, classes, frame_skip, prefix);
}
}
Loading

0 comments on commit c7a700d

Please sign in to comment.