shortcut_layer resize for random=1

This commit is contained in:
AlexeyAB
2018-03-16 01:49:01 +03:00
parent df076653e0
commit 371f21171a
5 changed files with 32 additions and 5 deletions

View File

@ -269,7 +269,7 @@ void fill_truth_region(char *path, float *truth, int classes, int num_boxes, int
h = boxes[i].h; h = boxes[i].h;
id = boxes[i].id; id = boxes[i].id;
if (w < .01 || h < .01) continue; if (w < .001 || h < .001) continue;
int col = (int)(x*num_boxes); int col = (int)(x*num_boxes);
int row = (int)(y*num_boxes); int row = (int)(y*num_boxes);
@ -326,7 +326,7 @@ void fill_truth_detection(char *path, int num_boxes, float *truth, int classes,
id = boxes[i].id; id = boxes[i].id;
// not detect small objects // not detect small objects
if ((w < 0.001 || h < 0.001)) { printf("small w = %f, h = %f \n", w, h); continue; } if ((w < 0.001 || h < 0.001)) continue;
truth[i*5+0] = x; truth[i*5+0] = x;
truth[i*5+1] = y; truth[i*5+1] = y;

View File

@ -43,6 +43,9 @@ void train_detector(char *datacfg, char *cfgfile, char *weightfile, int *gpus, i
float avg_loss = -1; float avg_loss = -1;
network *nets = calloc(ngpus, sizeof(network)); network *nets = calloc(ngpus, sizeof(network));
int iter_save;
iter_save = 100;
srand(time(0)); srand(time(0));
int seed = rand(); int seed = rand();
int i; int i;
@ -89,7 +92,7 @@ void train_detector(char *datacfg, char *cfgfile, char *weightfile, int *gpus, i
args.small_object = l.small_object; args.small_object = l.small_object;
args.d = &buffer; args.d = &buffer;
args.type = DETECTION_DATA; args.type = DETECTION_DATA;
args.threads = 4;// 8; args.threads = 8; // 64
args.angle = net.angle; args.angle = net.angle;
args.exposure = net.exposure; args.exposure = net.exposure;
@ -113,7 +116,6 @@ void train_detector(char *datacfg, char *cfgfile, char *weightfile, int *gpus, i
if(l.random && count++%10 == 0){ if(l.random && count++%10 == 0){
printf("Resizing\n"); printf("Resizing\n");
int dim = (rand() % 12 + (init_w/32 - 5)) * 32; // +-160 int dim = (rand() % 12 + (init_w/32 - 5)) * 32; // +-160
//int dim = (rand() % 10 + 10) * 32;
//if (get_current_batch(net)+100 > net.max_batches) dim = 544; //if (get_current_batch(net)+100 > net.max_batches) dim = 544;
//int dim = (rand() % 4 + 16) * 32; //int dim = (rand() % 4 + 16) * 32;
printf("%d\n", dim); printf("%d\n", dim);
@ -177,7 +179,9 @@ void train_detector(char *datacfg, char *cfgfile, char *weightfile, int *gpus, i
#endif // OPENCV #endif // OPENCV
//if (i % 1000 == 0 || (i < 1000 && i % 100 == 0)) { //if (i % 1000 == 0 || (i < 1000 && i % 100 == 0)) {
if (i % 100 == 0) { //if (i % 100 == 0) {
if(i >= iter_save) {
iter_save += 100;
#ifdef GPU #ifdef GPU
if (ngpus != 1) sync_nets(nets, ngpus, 0); if (ngpus != 1) sync_nets(nets, ngpus, 0);
#endif #endif

View File

@ -375,6 +375,8 @@ int resize_network(network *net, int w, int h)
resize_region_layer(&l, w, h); resize_region_layer(&l, w, h);
}else if(l.type == ROUTE){ }else if(l.type == ROUTE){
resize_route_layer(&l, net); resize_route_layer(&l, net);
}else if (l.type == SHORTCUT) {
resize_shortcut_layer(&l, w, h);
}else if(l.type == REORG){ }else if(l.type == REORG){
resize_reorg_layer(&l, w, h); resize_reorg_layer(&l, w, h);
}else if(l.type == AVGPOOL){ }else if(l.type == AVGPOOL){

View File

@ -36,6 +36,26 @@ layer make_shortcut_layer(int batch, int index, int w, int h, int c, int w2, int
return l; return l;
} }
void resize_shortcut_layer(layer *l, int w, int h)
{
assert(l->w == l->out_w);
assert(l->h == l->out_h);
l->w = l->out_w = w;
l->h = l->out_h = h;
l->outputs = w*h*l->out_c;
l->inputs = l->outputs;
l->delta = realloc(l->delta, l->outputs*l->batch * sizeof(float));
l->output = realloc(l->output, l->outputs*l->batch * sizeof(float));
#ifdef GPU
cuda_free(l->output_gpu);
cuda_free(l->delta_gpu);
l->output_gpu = cuda_make_array(l->output, l->outputs*l->batch);
l->delta_gpu = cuda_make_array(l->delta, l->outputs*l->batch);
#endif
}
void forward_shortcut_layer(const layer l, network_state state) void forward_shortcut_layer(const layer l, network_state state)
{ {
copy_cpu(l.outputs*l.batch, state.input, 1, l.output, 1); copy_cpu(l.outputs*l.batch, state.input, 1, l.output, 1);

View File

@ -7,6 +7,7 @@
layer make_shortcut_layer(int batch, int index, int w, int h, int c, int w2, int h2, int c2); layer make_shortcut_layer(int batch, int index, int w, int h, int c, int w2, int h2, int c2);
void forward_shortcut_layer(const layer l, network_state state); void forward_shortcut_layer(const layer l, network_state state);
void backward_shortcut_layer(const layer l, network_state state); void backward_shortcut_layer(const layer l, network_state state);
void resize_shortcut_layer(layer *l, int w, int h);
#ifdef GPU #ifdef GPU
void forward_shortcut_layer_gpu(const layer l, network_state state); void forward_shortcut_layer_gpu(const layer l, network_state state);