Added the option to resize_image to resize images using cv::resize while reading...
authorsguada <sguada@gmail.com>
Sat, 15 Feb 2014 07:26:32 +0000 (23:26 -0800)
committersguada <sguada@gmail.com>
Mon, 17 Feb 2014 18:32:36 +0000 (10:32 -0800)
data/cat.jpg
src/caffe/layers/input_layer.cpp
src/caffe/proto/caffe.proto

index 3a2550b..5303803 100644 (file)
Binary files a/data/cat.jpg and b/data/cat.jpg differ
index d8ed74a..db3d634 100644 (file)
@@ -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<Dtype>::SetUp(const vector<Blob<Dtype>*>& 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) {
index 9894224..dd09b73 100644 (file)
@@ -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 {