Fixed classifier for AlexNet and Resnet50

This commit is contained in:
AlexeyAB 2017-09-15 20:31:48 +03:00
parent c48f8c1573
commit 2baa7bde54
4 changed files with 53 additions and 2 deletions

View File

@ -706,8 +706,9 @@ void predict_classifier(char *datacfg, char *cfgfile, char *weightfile, char *fi
strtok(input, "\n");
}
image im = load_image_color(input, 0, 0);
image r = resize_min(im, size);
resize_network(&net, r.w, r.h);
image r = letterbox_image(im, net.w, net.h);
//image r = resize_min(im, size);
//resize_network(&net, r.w, r.h);
printf("%d %d\n", r.w, r.h);
float *X = r.data;

View File

@ -883,6 +883,51 @@ void composite_3d(char *f1, char *f2, char *out, int delta)
#endif
}
void fill_image(image m, float s)
{
int i;
for (i = 0; i < m.h*m.w*m.c; ++i) m.data[i] = s;
}
void letterbox_image_into(image im, int w, int h, image boxed)
{
int new_w = im.w;
int new_h = im.h;
if (((float)w / im.w) < ((float)h / im.h)) {
new_w = w;
new_h = (im.h * w) / im.w;
}
else {
new_h = h;
new_w = (im.w * h) / im.h;
}
image resized = resize_image(im, new_w, new_h);
embed_image(resized, boxed, (w - new_w) / 2, (h - new_h) / 2);
free_image(resized);
}
image letterbox_image(image im, int w, int h)
{
int new_w = im.w;
int new_h = im.h;
if (((float)w / im.w) < ((float)h / im.h)) {
new_w = w;
new_h = (im.h * w) / im.w;
}
else {
new_h = h;
new_w = (im.w * h) / im.h;
}
image resized = resize_image(im, new_w, new_h);
image boxed = make_image(w, h, im.c);
fill_image(boxed, .5);
//int i;
//for(i = 0; i < boxed.w*boxed.h*boxed.c; ++i) boxed.data[i] = 0;
embed_image(resized, boxed, (w - new_w) / 2, (h - new_h) / 2);
free_image(resized);
return boxed;
}
image resize_max(image im, int max)
{
int w = im.w;
@ -1312,6 +1357,7 @@ image load_image(char *filename, int w, int h, int c)
#ifndef CV_VERSION_EPOCH
image out = load_image_stb(filename, c); // OpenCV 3.x
//image out = load_image_cv(filename, c);
#else
image out = load_image_cv(filename, c); // OpenCV 2.4.x
#endif

View File

@ -30,6 +30,9 @@ image random_crop_image(image im, int w, int h);
image random_augment_image(image im, float angle, float aspect, int low, int high, int size);
void random_distort_image(image im, float hue, float saturation, float exposure);
image resize_image(image im, int w, int h);
void fill_image(image m, float s);
void letterbox_image_into(image im, int w, int h, image boxed);
image letterbox_image(image im, int w, int h);
image resize_min(image im, int min);
image resize_max(image im, int max);
void translate_image(image m, float s);

View File

@ -356,6 +356,7 @@ int resize_network(network *net, int w, int h)
}else if(l.type == COST){
resize_cost_layer(&l, inputs);
}else{
fprintf(stderr, "Resizing type %d \n", (int)l.type);
error("Cannot resize this type of layer");
}
if(l.workspace_size > workspace_size) workspace_size = l.workspace_size;