groom #1416
authorEvan Shelhamer <shelhamer@imaginarynumber.net>
Sat, 7 Feb 2015 05:37:54 +0000 (21:37 -0800)
committerEvan Shelhamer <shelhamer@imaginarynumber.net>
Sat, 7 Feb 2015 05:55:35 +0000 (21:55 -0800)
- keep current `DataTransformer` check so that datums can be transformed
  into a blob incrementally
- standardize check messages
- include opencv where needed, drop unneeded OS X guards

TODO these tests need to be de-duped

include/caffe/data_transformer.hpp
src/caffe/data_transformer.cpp
src/caffe/layers/memory_data_layer.cpp
src/caffe/test/test_memory_data_layer.cpp

index 95062d4..60696c9 100644 (file)
@@ -60,10 +60,8 @@ class DataTransformer {
    *    This is destination blob. It can be part of top blob's data if
    *    set_cpu_data() is used. See memory_layer.cpp for an example.
    */
-#ifndef OSX
   void Transform(const vector<cv::Mat> & mat_vector,
                 Blob<Dtype>* transformed_blob);
-#endif
   /**
    * @brief Applies the transformation defined in the data layer's
    * transform_param block to a cv::Mat
@@ -92,7 +90,7 @@ class DataTransformer {
  protected:
    /**
    * @brief Generates a random integer from Uniform({0, 1, ..., n-1}).
-   * 
+   *
    * @param n
    *    The upperbound (exclusive) value of the random number.
    * @return
index 3e11085..c0ad72e 100644 (file)
@@ -163,8 +163,8 @@ void DataTransformer<Dtype>::Transform(const vector<Datum> & datum_vector,
   const int width = transformed_blob->width();
 
   CHECK_GT(datum_num, 0) << "There is no datum to add";
-  CHECK_EQ(datum_num, num) <<
-    "The size of datum_vector must be equals to transformed_blob->num()";
+  CHECK_LE(datum_num, num) <<
+    "The size of datum_vector must be no greater than transformed_blob->num()";
   Blob<Dtype> uni_blob(1, channels, height, width);
   for (int item_id = 0; item_id < datum_num; ++item_id) {
     int offset = transformed_blob->offset(item_id);
@@ -173,7 +173,6 @@ void DataTransformer<Dtype>::Transform(const vector<Datum> & datum_vector,
   }
 }
 
-#ifndef OSX
 template<typename Dtype>
 void DataTransformer<Dtype>::Transform(const vector<cv::Mat> & mat_vector,
                                        Blob<Dtype>* transformed_blob) {
@@ -193,7 +192,6 @@ void DataTransformer<Dtype>::Transform(const vector<cv::Mat> & mat_vector,
     Transform(mat_vector[item_id], &uni_blob);
   }
 }
-#endif
 
 template<typename Dtype>
 void DataTransformer<Dtype>::Transform(const cv::Mat& cv_img,
index 1669db3..7cb5eaf 100644 (file)
@@ -1,3 +1,5 @@
+#include <opencv2/core/core.hpp>
+
 #include <vector>
 
 #include "caffe/data_layers.hpp"
@@ -30,12 +32,11 @@ void MemoryDataLayer<Dtype>::DataLayerSetUp(const vector<Blob<Dtype>*>& bottom,
 template <typename Dtype>
 void MemoryDataLayer<Dtype>::AddDatumVector(const vector<Datum>& datum_vector) {
   CHECK(!has_new_data_) <<
-      "Can't add Datum when earlier ones haven't been consumed"
-      << " by the upper layers";
+      "Can't add data until current data has been consumed.";
   size_t num = datum_vector.size();
-  CHECK_GT(num, 0) << "There is no datum to add";
+  CHECK_GT(num, 0) << "There is no datum to add.";
   CHECK_EQ(num % batch_size_, 0) <<
-      "The number of added datum must be multiple of the batch size";
+      "The added data must be a multiple of the batch size.";
   added_data_.Reshape(num, channels_, height_, width_);
   added_label_.Reshape(num, 1, 1, 1);
   // Apply data transformations (mirror, scale, crop...)
@@ -56,11 +57,10 @@ void MemoryDataLayer<Dtype>::AddMatVector(const vector<cv::Mat>& mat_vector,
     const vector<int>& labels) {
   size_t num = mat_vector.size();
   CHECK(!has_new_data_) <<
-      "Can't add Mat when earlier ones haven't been consumed"
-      << " by the upper layers";
-  CHECK_EQ(num % batch_size_, 0) <<
-      "The number of added datum must be multiple of the batch size";
+      "Can't add mat until current data has been consumed.";
   CHECK_GT(num, 0) << "There is no mat to add";
+  CHECK_EQ(num % batch_size_, 0) <<
+      "The added data must be a multiple of the batch size.";
   added_data_.Reshape(num, channels_, height_, width_);
   added_label_.Reshape(num, 1, 1, 1);
   // Apply data transformations (mirror, scale, crop...)
@@ -90,8 +90,7 @@ void MemoryDataLayer<Dtype>::Reset(Dtype* data, Dtype* labels, int n) {
 template <typename Dtype>
 void MemoryDataLayer<Dtype>::set_batch_size(int new_size) {
   CHECK(!has_new_data_) <<
-      "Can't change batch_size before all data haven't been consumed"
-      << " by the upper layers";
+      "Can't change batch_size until current data has been consumed.";
   batch_size_ = new_size;
   added_data_.Reshape(batch_size_, channels_, height_, width_);
   added_label_.Reshape(batch_size_, 1, 1, 1);
index 6a7bf04..a79033f 100644 (file)
@@ -1,3 +1,5 @@
+#include <opencv2/core/core.hpp>
+
 #include <string>
 #include <vector>