Skip to content

Commit 8b65e51

Browse files
committed
Added the option to resize_image to resize images using cv::resize while reading them
1 parent e8e3a1b commit 8b65e51

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

data/cat.jpg

600 KB
Loading

src/caffe/layers/input_layer.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ void* InputLayerPrefetch(void* layer_pointer) {
3131
const int batchsize = layer->layer_param_.batchsize();
3232
const int cropsize = layer->layer_param_.cropsize();
3333
const bool mirror = layer->layer_param_.mirror();
34+
const int resize_image = layer->layer_param_.resize_image();
3435

3536
if (mirror && cropsize == 0) {
3637
LOG(FATAL) << "Current implementation requires mirror and cropsize to be "
@@ -46,8 +47,8 @@ void* InputLayerPrefetch(void* layer_pointer) {
4647
for (int itemid = 0; itemid < batchsize; ++itemid) {
4748
// get a blob
4849
CHECK_GT(lines_size,layer->lines_id_);
49-
if (!ReadImageToDatum(layer->lines_[layer->lines_id_].first,
50-
layer->lines_[layer->lines_id_].second, &datum)) {
50+
if (!ReadImageToDatum(layer->lines_[layer->lines_id_].first, layer->lines_[layer->lines_id_].second,
51+
resize_image, resize_image, &datum)) {
5152
continue;
5253
};
5354
const string& data = datum.data();
@@ -114,6 +115,9 @@ void* InputLayerPrefetch(void* layer_pointer) {
114115
// We have reached the end. Restart from the first.
115116
DLOG(INFO) << "Restarting data prefetching from start.";
116117
layer->lines_id_=0;
118+
if (layer->layer_param_.shuffle_data()) {
119+
std::random_shuffle(layer->lines_.begin(), layer->lines_.end());
120+
}
117121
}
118122
}
119123

@@ -157,8 +161,9 @@ void InputLayer<Dtype>::SetUp(const vector<Blob<Dtype>*>& bottom,
157161
}
158162
// Read a data point, and use it to initialize the top blob.
159163
Datum datum;
164+
const int resize_image = this->layer_param_.resize_image();
160165
CHECK(ReadImageToDatum(lines_[lines_id_].first, lines_[lines_id_].second,
161-
&datum));
166+
resize_image,resize_image,&datum));
162167
// image
163168
int cropsize = this->layer_param_.cropsize();
164169
if (cropsize > 0) {

src/caffe/proto/caffe.proto

+4-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ message LayerParameter {
9292
// be larger than the number of keys in the leveldb.
9393
optional uint32 rand_skip = 53 [ default = 0 ];
9494

95-
optional bool shuffle_data = 61 [default = true];
95+
// Used by Input_layer to shuffle the list of files at every epoch
96+
optional bool shuffle_data = 61 [default = false];
97+
// If >0 then it will resize input images to size given by resize_image using cv::resize
98+
optional int32 resize_image = 62 [default = 0 ];
9699
}
97100

98101
message LayerConnection {

0 commit comments

Comments
 (0)