Browse Source

fix crop on channel dim only, fix #797, fix #831

tags/20190320
nihuini 7 years ago
parent
commit
6f9ffca7e3
1 changed files with 34 additions and 4 deletions
  1. +34
    -4
      src/layer/crop.cpp

+ 34
- 4
src/layer/crop.cpp View File

@@ -79,7 +79,22 @@ int Crop::forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) cons
else
_outc = std::min(outc, channels - coffset);

const Mat bottom_blob_sliced(w, h, _outc, (void*)(const float*)bottom_blob.channel(coffset));
if (_outw == w && _outh == h && _outc == channels)
{
top_blob = bottom_blob;
return 0;
}

const Mat bottom_blob_sliced = bottom_blob.channel_range(coffset, _outc);

if (_outw == w && _outh == h)
{
top_blob = bottom_blob_sliced.clone();
if (top_blob.empty())
return -100;

return 0;
}

int top = hoffset;
int bottom = h - _outh - hoffset;
@@ -102,19 +117,34 @@ int Crop::forward(const std::vector<Mat>& bottom_blobs, std::vector<Mat>& top_bl
int h = bottom_blob.h;
int channels = bottom_blob.c;

Mat& top_blob = top_blobs[0];

int _outw = reference_blob.w;
int _outh = reference_blob.h;
int _outc = reference_blob.dims == 3 ? reference_blob.c : channels;

const Mat bottom_blob_sliced(w, h, _outc, (void*)(const float*)bottom_blob.channel(coffset));
if (_outw == w && _outh == h && _outc == channels)
{
top_blob = bottom_blob;
return 0;
}

const Mat bottom_blob_sliced = bottom_blob.channel_range(coffset, _outc);

if (_outw == w && _outh == h)
{
top_blob = bottom_blob_sliced.clone();
if (top_blob.empty())
return -100;

return 0;
}

int top = hoffset;
int bottom = h - _outh - hoffset;
int left = woffset;
int right = w - _outw - woffset;

Mat& top_blob = top_blobs[0];

copy_cut_border(bottom_blob_sliced, top_blob, top, bottom, left, right, opt.blob_allocator, opt.num_threads);
if (top_blob.empty())
return -100;


Loading…
Cancel
Save