From: sguada Date: Sat, 15 Feb 2014 07:26:32 +0000 (-0800) Subject: Added the option to resize_image to resize images using cv::resize while reading... X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8b65e5174068489c044773217340494ab8fedd39;p=platform%2Fupstream%2Fcaffe.git Added the option to resize_image to resize images using cv::resize while reading them --- diff --git a/data/cat.jpg b/data/cat.jpg index 3a2550b..5303803 100644 Binary files a/data/cat.jpg and b/data/cat.jpg differ diff --git a/src/caffe/layers/input_layer.cpp b/src/caffe/layers/input_layer.cpp index d8ed74a..db3d634 100644 --- a/src/caffe/layers/input_layer.cpp +++ b/src/caffe/layers/input_layer.cpp @@ -31,6 +31,7 @@ void* InputLayerPrefetch(void* layer_pointer) { const int batchsize = layer->layer_param_.batchsize(); const int cropsize = layer->layer_param_.cropsize(); const bool mirror = layer->layer_param_.mirror(); + const int resize_image = layer->layer_param_.resize_image(); if (mirror && cropsize == 0) { LOG(FATAL) << "Current implementation requires mirror and cropsize to be " @@ -46,8 +47,8 @@ void* InputLayerPrefetch(void* layer_pointer) { for (int itemid = 0; itemid < batchsize; ++itemid) { // get a blob CHECK_GT(lines_size,layer->lines_id_); - if (!ReadImageToDatum(layer->lines_[layer->lines_id_].first, - layer->lines_[layer->lines_id_].second, &datum)) { + if (!ReadImageToDatum(layer->lines_[layer->lines_id_].first, layer->lines_[layer->lines_id_].second, + resize_image, resize_image, &datum)) { continue; }; const string& data = datum.data(); @@ -114,6 +115,9 @@ void* InputLayerPrefetch(void* layer_pointer) { // We have reached the end. Restart from the first. DLOG(INFO) << "Restarting data prefetching from start."; layer->lines_id_=0; + if (layer->layer_param_.shuffle_data()) { + std::random_shuffle(layer->lines_.begin(), layer->lines_.end()); + } } } @@ -157,8 +161,9 @@ void InputLayer::SetUp(const vector*>& bottom, } // Read a data point, and use it to initialize the top blob. Datum datum; + const int resize_image = this->layer_param_.resize_image(); CHECK(ReadImageToDatum(lines_[lines_id_].first, lines_[lines_id_].second, - &datum)); + resize_image,resize_image,&datum)); // image int cropsize = this->layer_param_.cropsize(); if (cropsize > 0) { diff --git a/src/caffe/proto/caffe.proto b/src/caffe/proto/caffe.proto index 9894224..dd09b73 100644 --- a/src/caffe/proto/caffe.proto +++ b/src/caffe/proto/caffe.proto @@ -92,7 +92,10 @@ message LayerParameter { // be larger than the number of keys in the leveldb. optional uint32 rand_skip = 53 [ default = 0 ]; - optional bool shuffle_data = 61 [default = true]; + // Used by Input_layer to shuffle the list of files at every epoch + optional bool shuffle_data = 61 [default = false]; + // If >0 then it will resize input images to size given by resize_image using cv::resize + optional int32 resize_image = 62 [default = 0 ]; } message LayerConnection {