From a723e1c62a27aeb39aaf7fcdeb3beb4e89fba32d Mon Sep 17 00:00:00 2001
From: Alexey <AlexeyAB@users.noreply.github.com>
Date: Wed, 15 Aug 2018 20:52:09 +0000
Subject: [PATCH] Merge pull request #766 from HotChick91/AlexeyAB-mask
---
src/reorg_layer.c | 66 +++++++++++----------------------
1 files changed, 22 insertions(+), 44 deletions(-)
diff --git a/src/reorg_layer.c b/src/reorg_layer.c
index d93dd97..c298b40 100644
--- a/src/reorg_layer.c
+++ b/src/reorg_layer.c
@@ -4,7 +4,7 @@
#include <stdio.h>
-layer make_reorg_layer(int batch, int h, int w, int c, int stride, int reverse)
+layer make_reorg_layer(int batch, int w, int h, int c, int stride, int reverse)
{
layer l = {0};
l.type = REORG;
@@ -23,7 +23,7 @@
l.out_c = c*(stride*stride);
}
l.reverse = reverse;
- fprintf(stderr, "Reorg Layer: %d x %d x %d image -> %d x %d x %d image, \n", w,h,c,l.out_w, l.out_h, l.out_c);
+ fprintf(stderr, "reorg /%2d %4d x%4d x%4d -> %4d x%4d x%4d\n", stride, w, h, c, l.out_w, l.out_h, l.out_c);
l.outputs = l.out_h * l.out_w * l.out_c;
l.inputs = h*w*c;
int output_size = l.out_h * l.out_w * l.out_c * batch;
@@ -77,64 +77,42 @@
void forward_reorg_layer(const layer l, network_state state)
{
- int b,i,j,k;
-
- for(b = 0; b < l.batch; ++b){
- for(k = 0; k < l.c; ++k){
- for(j = 0; j < l.h; ++j){
- for(i = 0; i < l.w; ++i){
- int in_index = i + l.w*(j + l.h*(k + l.c*b));
-
- int c2 = k % l.out_c;
- int offset = k / l.out_c;
- int w2 = i*l.stride + offset % l.stride;
- int h2 = j*l.stride + offset / l.stride;
- int out_index = w2 + l.out_w*(h2 + l.out_h*(c2 + l.out_c*b));
- l.output[out_index] = state.input[in_index];
- }
- }
- }
+ if (l.reverse) {
+ reorg_cpu(state.input, l.out_w, l.out_h, l.out_c, l.batch, l.stride, 1, l.output);
+ }
+ else {
+ reorg_cpu(state.input, l.out_w, l.out_h, l.out_c, l.batch, l.stride, 0, l.output);
}
}
void backward_reorg_layer(const layer l, network_state state)
{
- int b,i,j,k;
-
- for(b = 0; b < l.batch; ++b){
- for(k = 0; k < l.c; ++k){
- for(j = 0; j < l.h; ++j){
- for(i = 0; i < l.w; ++i){
- int in_index = i + l.w*(j + l.h*(k + l.c*b));
-
- int c2 = k % l.out_c;
- int offset = k / l.out_c;
- int w2 = i*l.stride + offset % l.stride;
- int h2 = j*l.stride + offset / l.stride;
- int out_index = w2 + l.out_w*(h2 + l.out_h*(c2 + l.out_c*b));
- state.delta[in_index] = l.delta[out_index];
- }
- }
- }
+ if (l.reverse) {
+ reorg_cpu(l.delta, l.out_w, l.out_h, l.out_c, l.batch, l.stride, 0, state.delta);
+ }
+ else {
+ reorg_cpu(l.delta, l.out_w, l.out_h, l.out_c, l.batch, l.stride, 1, state.delta);
}
}
#ifdef GPU
void forward_reorg_layer_gpu(layer l, network_state state)
{
- if(l.reverse){
- reorg_ongpu(state.input, l.w, l.h, l.c, l.batch, l.stride, 1, l.output_gpu);
- }else {
- reorg_ongpu(state.input, l.w, l.h, l.c, l.batch, l.stride, 0, l.output_gpu);
+ if (l.reverse) {
+ reorg_ongpu(state.input, l.out_w, l.out_h, l.out_c, l.batch, l.stride, 1, l.output_gpu);
+ }
+ else {
+ reorg_ongpu(state.input, l.out_w, l.out_h, l.out_c, l.batch, l.stride, 0, l.output_gpu);
}
}
void backward_reorg_layer_gpu(layer l, network_state state)
{
- if(l.reverse){
- reorg_ongpu(l.delta_gpu, l.w, l.h, l.c, l.batch, l.stride, 0, state.delta);
- }else{
- reorg_ongpu(l.delta_gpu, l.w, l.h, l.c, l.batch, l.stride, 1, state.delta);
+ if (l.reverse) {
+ reorg_ongpu(l.delta_gpu, l.out_w, l.out_h, l.out_c, l.batch, l.stride, 0, state.delta);
+ }
+ else {
+ reorg_ongpu(l.delta_gpu, l.out_w, l.out_h, l.out_c, l.batch, l.stride, 1, state.delta);
}
}
#endif
--
Gitblit v1.10.0