mirror of
https://github.com/pjreddie/darknet.git
synced 2023-08-10 21:13:14 +03:00
testing on one image
This commit is contained in:
parent
d41fbf638e
commit
11c72b1132
4
Makefile
4
Makefile
@ -1,5 +1,5 @@
|
|||||||
GPU=1
|
GPU=0
|
||||||
OPENCV=1
|
OPENCV=0
|
||||||
DEBUG=0
|
DEBUG=0
|
||||||
|
|
||||||
ARCH= -arch=sm_52
|
ARCH= -arch=sm_52
|
||||||
|
1000
data/shortnames.txt
Normal file
1000
data/shortnames.txt
Normal file
File diff suppressed because it is too large
Load Diff
@ -232,7 +232,9 @@ void rgbgr_filters(convolutional_layer l)
|
|||||||
int i;
|
int i;
|
||||||
for(i = 0; i < l.n; ++i){
|
for(i = 0; i < l.n; ++i){
|
||||||
image im = get_convolutional_filter(l, i);
|
image im = get_convolutional_filter(l, i);
|
||||||
if (im.c == 3) rgbgr_image(im);
|
if (im.c == 3) {
|
||||||
|
rgbgr_image(im);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,6 +77,7 @@ void partial(char *cfgfile, char *weightfile, char *outfile, int max)
|
|||||||
void rgbgr_filters(convolutional_layer l);
|
void rgbgr_filters(convolutional_layer l);
|
||||||
void rgbgr_net(char *cfgfile, char *weightfile, char *outfile)
|
void rgbgr_net(char *cfgfile, char *weightfile, char *outfile)
|
||||||
{
|
{
|
||||||
|
gpu_index = -1;
|
||||||
network net = parse_network_cfg(cfgfile);
|
network net = parse_network_cfg(cfgfile);
|
||||||
if(weightfile){
|
if(weightfile){
|
||||||
load_weights(&net, weightfile);
|
load_weights(&net, weightfile);
|
||||||
|
@ -18,7 +18,7 @@ void draw_detection(image im, float *box, int side, char *label)
|
|||||||
for(c = 0; c < side; ++c){
|
for(c = 0; c < side; ++c){
|
||||||
j = (r*side + c) * elems;
|
j = (r*side + c) * elems;
|
||||||
int class = max_index(box+j, classes);
|
int class = max_index(box+j, classes);
|
||||||
if(box[j+class] > 0){
|
if(box[j+class] > 0.2){
|
||||||
printf("%f %s\n", box[j+class], class_names[class]);
|
printf("%f %s\n", box[j+class], class_names[class]);
|
||||||
float red = get_color(0,class,classes);
|
float red = get_color(0,class,classes);
|
||||||
float green = get_color(1,class,classes);
|
float green = get_color(1,class,classes);
|
||||||
@ -67,6 +67,7 @@ void train_detection(char *cfgfile, char *weightfile)
|
|||||||
|
|
||||||
int classes = layer.classes;
|
int classes = layer.classes;
|
||||||
int background = (layer.background || layer.objectness);
|
int background = (layer.background || layer.objectness);
|
||||||
|
printf("%d\n", background);
|
||||||
int side = sqrt(get_detection_layer_locations(layer));
|
int side = sqrt(get_detection_layer_locations(layer));
|
||||||
|
|
||||||
char **paths;
|
char **paths;
|
||||||
@ -205,8 +206,9 @@ void validate_detection(char *cfgfile, char *weightfile)
|
|||||||
fprintf(stderr, "Total Detection Time: %f Seconds\n", (double)(time(0) - start));
|
fprintf(stderr, "Total Detection Time: %f Seconds\n", (double)(time(0) - start));
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_detection(char *cfgfile, char *weightfile)
|
void test_detection(char *cfgfile, char *weightfile, char *filename)
|
||||||
{
|
{
|
||||||
|
|
||||||
network net = parse_network_cfg(cfgfile);
|
network net = parse_network_cfg(cfgfile);
|
||||||
if(weightfile){
|
if(weightfile){
|
||||||
load_weights(&net, weightfile);
|
load_weights(&net, weightfile);
|
||||||
@ -217,24 +219,30 @@ void test_detection(char *cfgfile, char *weightfile)
|
|||||||
set_batch_network(&net, 1);
|
set_batch_network(&net, 1);
|
||||||
srand(2222222);
|
srand(2222222);
|
||||||
clock_t time;
|
clock_t time;
|
||||||
char filename[256];
|
char input[256];
|
||||||
while(1){
|
while(1){
|
||||||
printf("Image Path: ");
|
if(filename){
|
||||||
fflush(stdout);
|
strncpy(input, filename, 256);
|
||||||
fgets(filename, 256, stdin);
|
} else {
|
||||||
strtok(filename, "\n");
|
printf("Enter Image Path: ");
|
||||||
image im = load_image_color(filename,0,0);
|
fflush(stdout);
|
||||||
|
fgets(input, 256, stdin);
|
||||||
|
strtok(input, "\n");
|
||||||
|
}
|
||||||
|
image im = load_image_color(input,0,0);
|
||||||
image sized = resize_image(im, im_size, im_size);
|
image sized = resize_image(im, im_size, im_size);
|
||||||
float *X = sized.data;
|
float *X = sized.data;
|
||||||
time=clock();
|
time=clock();
|
||||||
float *predictions = network_predict(net, X);
|
float *predictions = network_predict(net, X);
|
||||||
printf("%s: Predicted in %f seconds.\n", filename, sec(clock()-time));
|
printf("%s: Predicted in %f seconds.\n", input, sec(clock()-time));
|
||||||
draw_detection(im, predictions, 7, "predictions");
|
draw_detection(im, predictions, 7, "predictions");
|
||||||
free_image(im);
|
free_image(im);
|
||||||
free_image(sized);
|
free_image(sized);
|
||||||
#ifdef OPENCV
|
#ifdef OPENCV
|
||||||
cvWaitKey(0);
|
cvWaitKey(0);
|
||||||
#endif
|
cvDestroyAllWindows();
|
||||||
|
#endif
|
||||||
|
if (filename) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,7 +255,8 @@ void run_detection(int argc, char **argv)
|
|||||||
|
|
||||||
char *cfg = argv[3];
|
char *cfg = argv[3];
|
||||||
char *weights = (argc > 4) ? argv[4] : 0;
|
char *weights = (argc > 4) ? argv[4] : 0;
|
||||||
if(0==strcmp(argv[2], "test")) test_detection(cfg, weights);
|
char *filename = (argc > 5) ? argv[5]: 0;
|
||||||
|
if(0==strcmp(argv[2], "test")) test_detection(cfg, weights, filename);
|
||||||
else if(0==strcmp(argv[2], "train")) train_detection(cfg, weights);
|
else if(0==strcmp(argv[2], "train")) train_detection(cfg, weights);
|
||||||
else if(0==strcmp(argv[2], "valid")) validate_detection(cfg, weights);
|
else if(0==strcmp(argv[2], "valid")) validate_detection(cfg, weights);
|
||||||
}
|
}
|
||||||
|
@ -29,10 +29,10 @@ detection_layer make_detection_layer(int batch, int inputs, int classes, int coo
|
|||||||
l.coords = coords;
|
l.coords = coords;
|
||||||
l.rescore = rescore;
|
l.rescore = rescore;
|
||||||
l.objectness = objectness;
|
l.objectness = objectness;
|
||||||
|
l.background = background;
|
||||||
l.joint = joint;
|
l.joint = joint;
|
||||||
l.cost = calloc(1, sizeof(float));
|
l.cost = calloc(1, sizeof(float));
|
||||||
l.does_cost=1;
|
l.does_cost=1;
|
||||||
l.background = background;
|
|
||||||
int outputs = get_detection_layer_output_size(l);
|
int outputs = get_detection_layer_output_size(l);
|
||||||
l.outputs = outputs;
|
l.outputs = outputs;
|
||||||
l.output = calloc(batch*outputs, sizeof(float));
|
l.output = calloc(batch*outputs, sizeof(float));
|
||||||
|
@ -101,37 +101,40 @@ void validate_imagenet(char *filename, char *weightfile)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_imagenet(char *cfgfile, char *weightfile)
|
void test_imagenet(char *cfgfile, char *weightfile, char *filename)
|
||||||
{
|
{
|
||||||
network net = parse_network_cfg(cfgfile);
|
network net = parse_network_cfg(cfgfile);
|
||||||
if(weightfile){
|
if(weightfile){
|
||||||
load_weights(&net, weightfile);
|
load_weights(&net, weightfile);
|
||||||
}
|
}
|
||||||
set_batch_network(&net, 1);
|
set_batch_network(&net, 1);
|
||||||
//imgs=1;
|
|
||||||
srand(2222222);
|
srand(2222222);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
char **names = get_labels("cfg/shortnames.txt");
|
char **names = get_labels("data/shortnames.txt");
|
||||||
clock_t time;
|
clock_t time;
|
||||||
char filename[256];
|
char input[256];
|
||||||
int indexes[10];
|
int indexes[10];
|
||||||
while(1){
|
while(1){
|
||||||
fgets(filename, 256, stdin);
|
if(filename){
|
||||||
strtok(filename, "\n");
|
strncpy(input, filename, 256);
|
||||||
image im = load_image_color(filename, 256, 256);
|
}else{
|
||||||
scale_image(im, 2.);
|
printf("Enter Image Path: ");
|
||||||
translate_image(im, -1.);
|
fflush(stdout);
|
||||||
printf("%d %d %d\n", im.h, im.w, im.c);
|
fgets(input, 256, stdin);
|
||||||
|
strtok(input, "\n");
|
||||||
|
}
|
||||||
|
image im = load_image_color(input, 256, 256);
|
||||||
float *X = im.data;
|
float *X = im.data;
|
||||||
time=clock();
|
time=clock();
|
||||||
float *predictions = network_predict(net, X);
|
float *predictions = network_predict(net, X);
|
||||||
top_predictions(net, 10, indexes);
|
top_predictions(net, 10, indexes);
|
||||||
printf("%s: Predicted in %f seconds.\n", filename, sec(clock()-time));
|
printf("%s: Predicted in %f seconds.\n", input, sec(clock()-time));
|
||||||
for(i = 0; i < 10; ++i){
|
for(i = 0; i < 10; ++i){
|
||||||
int index = indexes[i];
|
int index = indexes[i];
|
||||||
printf("%s: %f\n", names[index], predictions[index]);
|
printf("%s: %f\n", names[index], predictions[index]);
|
||||||
}
|
}
|
||||||
free_image(im);
|
free_image(im);
|
||||||
|
if (filename) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,7 +147,8 @@ void run_imagenet(int argc, char **argv)
|
|||||||
|
|
||||||
char *cfg = argv[3];
|
char *cfg = argv[3];
|
||||||
char *weights = (argc > 4) ? argv[4] : 0;
|
char *weights = (argc > 4) ? argv[4] : 0;
|
||||||
if(0==strcmp(argv[2], "test")) test_imagenet(cfg, weights);
|
char *filename = (argc > 5) ? argv[5]: 0;
|
||||||
|
if(0==strcmp(argv[2], "test")) test_imagenet(cfg, weights, filename);
|
||||||
else if(0==strcmp(argv[2], "train")) train_imagenet(cfg, weights);
|
else if(0==strcmp(argv[2], "train")) train_imagenet(cfg, weights);
|
||||||
else if(0==strcmp(argv[2], "valid")) validate_imagenet(cfg, weights);
|
else if(0==strcmp(argv[2], "valid")) validate_imagenet(cfg, weights);
|
||||||
}
|
}
|
||||||
|
@ -73,11 +73,11 @@ float sec(clock_t clocks)
|
|||||||
void top_k(float *a, int n, int k, int *index)
|
void top_k(float *a, int n, int k, int *index)
|
||||||
{
|
{
|
||||||
int i,j;
|
int i,j;
|
||||||
for(j = 0; j < k; ++j) index[j] = 0;
|
for(j = 0; j < k; ++j) index[j] = -1;
|
||||||
for(i = 0; i < n; ++i){
|
for(i = 0; i < n; ++i){
|
||||||
int curr = i;
|
int curr = i;
|
||||||
for(j = 0; j < k; ++j){
|
for(j = 0; j < k; ++j){
|
||||||
if(a[curr] > a[index[j]]){
|
if((index[j] < 0) || a[curr] > a[index[j]]){
|
||||||
int swap = curr;
|
int swap = curr;
|
||||||
curr = index[j];
|
curr = index[j];
|
||||||
index[j] = swap;
|
index[j] = swap;
|
||||||
|
Loading…
Reference in New Issue
Block a user