From 1b5afb45838e603fa6780762eb8cc59246dc2d81 Mon Sep 17 00:00:00 2001
From: IlyaOvodov <b@ovdv.ru>
Date: Tue, 08 May 2018 11:09:35 +0000
Subject: [PATCH] Output improvements for detector results: When printing detector results, output was done in random order, obfuscating results for interpreting. Now: 1. Text output includes coordinates of rects in (left,right,top,bottom in pixels) along with label and score 2. Text output is sorted by rect lefts to simplify finding appropriate rects on image 3. If several class probs are > thresh for some detection, the most probable is written first and coordinates for others are not repeated 4. Rects are imprinted in image in order by their best class prob, so most probable rects are always on top and not overlayed by less probable ones 5. Most probable label for rect is always written first Also: 6. Message about low GPU memory include required amount
---
src/crop_layer.c | 106 +++++++++++++++++++++++++++++++++++++----------------
1 files changed, 74 insertions(+), 32 deletions(-)
diff --git a/src/crop_layer.c b/src/crop_layer.c
index 3f0011d..11c59b4 100644
--- a/src/crop_layer.c
+++ b/src/crop_layer.c
@@ -2,57 +2,99 @@
#include "cuda.h"
#include <stdio.h>
-image get_crop_image(crop_layer layer)
+image get_crop_image(crop_layer l)
{
- int h = layer.crop_height;
- int w = layer.crop_width;
- int c = layer.c;
- return float_to_image(h,w,c,layer.output);
+ int h = l.out_h;
+ int w = l.out_w;
+ int c = l.out_c;
+ return float_to_image(w,h,c,l.output);
}
-crop_layer *make_crop_layer(int batch, int h, int w, int c, int crop_height, int crop_width, int flip)
+void backward_crop_layer(const crop_layer l, network_state state){}
+void backward_crop_layer_gpu(const crop_layer l, network_state state){}
+
+crop_layer make_crop_layer(int batch, int h, int w, int c, int crop_height, int crop_width, int flip, float angle, float saturation, float exposure)
{
fprintf(stderr, "Crop Layer: %d x %d -> %d x %d x %d image\n", h,w,crop_height,crop_width,c);
- crop_layer *layer = calloc(1, sizeof(crop_layer));
- layer->batch = batch;
- layer->h = h;
- layer->w = w;
- layer->c = c;
- layer->flip = flip;
- layer->crop_width = crop_width;
- layer->crop_height = crop_height;
- layer->output = calloc(crop_width*crop_height * c*batch, sizeof(float));
+ crop_layer l = {0};
+ l.type = CROP;
+ l.batch = batch;
+ l.h = h;
+ l.w = w;
+ l.c = c;
+ l.scale = (float)crop_height / h;
+ l.flip = flip;
+ l.angle = angle;
+ l.saturation = saturation;
+ l.exposure = exposure;
+ l.out_w = crop_width;
+ l.out_h = crop_height;
+ l.out_c = c;
+ l.inputs = l.w * l.h * l.c;
+ l.outputs = l.out_w * l.out_h * l.out_c;
+ l.output = calloc(l.outputs*batch, sizeof(float));
+ l.forward = forward_crop_layer;
+ l.backward = backward_crop_layer;
+
#ifdef GPU
- layer->output_gpu = cuda_make_array(layer->output, crop_width*crop_height*c*batch);
+ l.forward_gpu = forward_crop_layer_gpu;
+ l.backward_gpu = backward_crop_layer_gpu;
+ l.output_gpu = cuda_make_array(l.output, l.outputs*batch);
+ l.rand_gpu = cuda_make_array(0, l.batch*8);
#endif
- return layer;
+ return l;
}
-void forward_crop_layer(const crop_layer layer, int train, float *input)
+void resize_crop_layer(layer *l, int w, int h)
+{
+ l->w = w;
+ l->h = h;
+
+ l->out_w = l->scale*w;
+ l->out_h = l->scale*h;
+
+ l->inputs = l->w * l->h * l->c;
+ l->outputs = l->out_h * l->out_w * l->out_c;
+
+ l->output = realloc(l->output, l->batch*l->outputs*sizeof(float));
+ #ifdef GPU
+ cuda_free(l->output_gpu);
+ l->output_gpu = cuda_make_array(l->output, l->outputs*l->batch);
+ #endif
+}
+
+
+void forward_crop_layer(const crop_layer l, network_state state)
{
int i,j,c,b,row,col;
int index;
int count = 0;
- int flip = (layer.flip && rand()%2);
- int dh = rand()%(layer.h - layer.crop_height + 1);
- int dw = rand()%(layer.w - layer.crop_width + 1);
- if(!train){
- flip = 0;
- dh = (layer.h - layer.crop_height)/2;
- dw = (layer.w - layer.crop_width)/2;
+ int flip = (l.flip && rand()%2);
+ int dh = rand()%(l.h - l.out_h + 1);
+ int dw = rand()%(l.w - l.out_w + 1);
+ float scale = 2;
+ float trans = -1;
+ if(l.noadjust){
+ scale = 1;
+ trans = 0;
}
- for(b = 0; b < layer.batch; ++b){
- for(c = 0; c < layer.c; ++c){
- for(i = 0; i < layer.crop_height; ++i){
- for(j = 0; j < layer.crop_width; ++j){
+ if(!state.train){
+ flip = 0;
+ dh = (l.h - l.out_h)/2;
+ dw = (l.w - l.out_w)/2;
+ }
+ for(b = 0; b < l.batch; ++b){
+ for(c = 0; c < l.c; ++c){
+ for(i = 0; i < l.out_h; ++i){
+ for(j = 0; j < l.out_w; ++j){
if(flip){
- col = layer.w - dw - j - 1;
+ col = l.w - dw - j - 1;
}else{
col = j + dw;
}
row = i + dh;
- index = col+layer.w*(row+layer.h*(c + layer.c*b));
- layer.output[count++] = input[index];
+ index = col+l.w*(row+l.h*(c + l.c*b));
+ l.output[count++] = state.input[index]*scale + trans;
}
}
}
--
Gitblit v1.10.0