Skip to content
This repository has been archived by the owner on May 24, 2018. It is now read-only.

Commit

Permalink
Merge pull request #197 from superzrx/fix_aug
Browse files Browse the repository at this point in the history
fix rand_crop
  • Loading branch information
antinucleon committed Jul 14, 2015
2 parents dc59948 + a4d0c86 commit 4c1570a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,12 @@ ps-lite
dmlc-core
bin
rabit
*.opensdf
*.sdf
*.pdb
*.user
*.suo
*.deps
*.cache
*state
*build
40 changes: 31 additions & 9 deletions src/io/image_augmenter-inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<mshadow::index_t>(res.cols) >= shape_[1] && static_cast<mshadow::index_t>(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;
}
/*!
Expand Down

1 comment on commit 4c1570a

@supengyu
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请问 ImageNet.conf 中 image_net_mean.bin是怎么来的,如何生存

Please sign in to comment.