summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYangqing Jia <jiayq84@gmail.com>2013-10-30 14:30:54 -0700
committerYangqing Jia <jiayq84@gmail.com>2013-10-30 14:30:54 -0700
commita332b4d13f25e082f5b49e513ee54b418fcf2665 (patch)
treef1f85cbf95d7815df83d027469b4f49510677647 /src
parentacc673bb88517455e0f9e86ddeb2de7bd4948a48 (diff)
downloadcaffe-a332b4d13f25e082f5b49e513ee54b418fcf2665.tar.gz
caffe-a332b4d13f25e082f5b49e513ee54b418fcf2665.tar.bz2
caffe-a332b4d13f25e082f5b49e513ee54b418fcf2665.zip
data_layer: do center cropping when testing
Diffstat (limited to 'src')
-rw-r--r--src/caffe/layers/data_layer.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/caffe/layers/data_layer.cpp b/src/caffe/layers/data_layer.cpp
index 9ed95165..5b127a48 100644
--- a/src/caffe/layers/data_layer.cpp
+++ b/src/caffe/layers/data_layer.cpp
@@ -42,8 +42,15 @@ void* DataLayerPrefetch(void* layer_pointer) {
const string& data = datum.data();
if (cropsize) {
CHECK(data.size()) << "Image cropping only support uint8 data";
- int h_off = rand() % (height - cropsize);
- int w_off = rand() % (width - cropsize);
+ int h_off, w_off;
+ // We only do random crop when we do training.
+ if (Caffe::phase() == Caffe::TRAIN) {
+ h_off = rand() % (height - cropsize);
+ w_off = rand() % (width - cropsize);
+ } else {
+ h_off = (height - cropsize) / 2;
+ w_off = (width - cropsize) / 2;
+ }
if (mirror && rand() % 2) {
// Copy mirrored version
for (int c = 0; c < channels; ++c) {