From a4d0c8634fc3ddea4c5f076c6120ca10dad37420 Mon Sep 17 00:00:00 2001 From: superzrx Date: Tue, 14 Jul 2015 23:36:49 +0800 Subject: [PATCH 1/2] fix rand_crop fix max_crop_size and min_crop_size --- .gitignore | 9 ++++++++ src/io/image_augmenter-inl.hpp | 40 ++++++++++++++++++++++++++-------- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index f4351c04..a63ba6f4 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,12 @@ ps-lite dmlc-core bin rabit +*.opensdf +*.sdf +*.pdb +*.user +*.suo +*.deps +*.cache +*state +*build \ No newline at end of file diff --git a/src/io/image_augmenter-inl.hpp b/src/io/image_augmenter-inl.hpp index 88487294..c90bc0d9 100644 --- a/src/io/image_augmenter-inl.hpp +++ b/src/io/image_augmenter-inl.hpp @@ -107,16 +107,38 @@ class ImageAugmenter { cv::BORDER_CONSTANT, cv::Scalar(fill_value_, fill_value_, fill_value_)); cv::Mat res = temp; - mshadow::index_t y = res.rows - shape_[2]; - mshadow::index_t x = res.cols - shape_[1]; - if (rand_crop_ != 0) { - y = prnd->NextUInt32(y + 1); - x = prnd->NextUInt32(x + 1); - } else { - y /= 2; x /= 2; + if (max_crop_size_ != -1 || min_crop_size_ != -1){ + utils::Check(res.cols >= max_crop_size_ && res.rows >= max_crop_size_&&max_crop_size_ >= min_crop_size_, + "input image size smaller than max_crop_size"); + mshadow::index_t rand_crop_size = prnd->NextUInt32(max_crop_size_-min_crop_size_+1)+min_crop_size_; + mshadow::index_t y = res.rows - rand_crop_size; + mshadow::index_t x = res.cols - rand_crop_size; + if (rand_crop_ != 0) { + y = prnd->NextUInt32(y + 1); + x = prnd->NextUInt32(x + 1); + } + else { + y /= 2; x /= 2; + } + cv::Rect roi(x, y, rand_crop_size, rand_crop_size); + res = res(roi); + cv::resize(res(roi), res, cv::Size(shape_[1], shape_[2])); + } + else{ + utils::Check(static_cast(res.cols) >= shape_[1] && static_cast(res.rows) >= shape_[2], + "input image size smaller than input shape"); + mshadow::index_t y = res.rows - shape_[2]; + mshadow::index_t x = res.cols - shape_[1]; + if (rand_crop_ != 0) { + y = prnd->NextUInt32(y + 1); + x = prnd->NextUInt32(x + 1); + } + else { + y /= 2; x /= 2; + } + cv::Rect roi(x, y, shape_[1], shape_[2]); + res = res(roi); } - cv::Rect roi(x, y, shape_[1], shape_[2]); - res = res(roi); return res; } /*! From 7dc89e64bb65e39b341448d4ce29c431bc1f39ff Mon Sep 17 00:00:00 2001 From: superzrx Date: Sat, 25 Jul 2015 00:08:06 +0800 Subject: [PATCH 2/2] fix fix rand_crop remove duplicate roi --- src/io/image_augmenter-inl.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/io/image_augmenter-inl.hpp b/src/io/image_augmenter-inl.hpp index c90bc0d9..f5e31733 100644 --- a/src/io/image_augmenter-inl.hpp +++ b/src/io/image_augmenter-inl.hpp @@ -121,7 +121,6 @@ class ImageAugmenter { y /= 2; x /= 2; } cv::Rect roi(x, y, rand_crop_size, rand_crop_size); - res = res(roi); cv::resize(res(roi), res, cv::Size(shape_[1], shape_[2])); } else{