incorporate WindowDataLayer into V0Upgrade and add tests
authorJeff Donahue <jeff.donahue@gmail.com>
Fri, 21 Mar 2014 22:53:35 +0000 (15:53 -0700)
committerJeff Donahue <jeff.donahue@gmail.com>
Fri, 28 Mar 2014 06:42:28 +0000 (23:42 -0700)
src/caffe/test/test_upgrade_proto.cpp
src/caffe/util/upgrade_proto.cpp

index 07c67bf..f8cb07c 100644 (file)
@@ -1261,6 +1261,7 @@ TYPED_TEST(V0UpgradeTest, TestSimple) {
   this->RunV0UpgradeTest(input_proto, expected_output_proto);
 }
 
+// Test any layer or parameter upgrades not covered by other tests.
 TYPED_TEST(V0UpgradeTest, TestAllParams) {
   const string& input_proto =
       "name: 'CaffeNet' "
@@ -1286,6 +1287,24 @@ TYPED_TEST(V0UpgradeTest, TestAllParams) {
       "} "
       "layers { "
       "  layer { "
+      "    name: 'window_data' "
+      "    type: 'window_data' "
+      "    source: '/home/jiayq/Data/ILSVRC12/train-leveldb' "
+      "    meanfile: '/home/jiayq/Data/ILSVRC12/image_mean.binaryproto' "
+      "    batchsize: 256 "
+      "    cropsize: 227 "
+      "    mirror: true "
+      "    det_fg_threshold: 0.25 "
+      "    det_bg_threshold: 0.75 "
+      "    det_fg_fraction: 0.5 "
+      "    det_context_pad: 16 "
+      "    det_crop_mode: 'square' "
+      "  } "
+      "  top: 'window_data' "
+      "  top: 'window_label' "
+      "} "
+      "layers { "
+      "  layer { "
       "    name: 'hdf5data' "
       "    type: 'hdf5_data' "
       "    source: '/my/hdf5/data' "
@@ -1423,6 +1442,12 @@ TYPED_TEST(V0UpgradeTest, TestAllParams) {
       "} "
       "layers { "
       "  layer { "
+      "    name: 'euclidean_loss' "
+      "    type: 'euclidean_loss' "
+      "  } "
+      "} "
+      "layers { "
+      "  layer { "
       "    name: 'flatten' "
       "    type: 'flatten' "
       "  } "
@@ -1435,6 +1460,12 @@ TYPED_TEST(V0UpgradeTest, TestAllParams) {
       "} "
       "layers { "
       "  layer { "
+      "    name: 'images' "
+      "    type: 'images' "
+      "  } "
+      "} "
+      "layers { "
+      "  layer { "
       "    name: 'multinomial_logistic_loss' "
       "    type: 'multinomial_logistic_loss' "
       "  } "
@@ -1486,6 +1517,24 @@ TYPED_TEST(V0UpgradeTest, TestAllParams) {
       "  top: 'label' "
       "} "
       "layers { "
+      "  name: 'window_data' "
+      "  type: WINDOW_DATA "
+      "  window_data_param { "
+      "    source: '/home/jiayq/Data/ILSVRC12/train-leveldb' "
+      "    mean_file: '/home/jiayq/Data/ILSVRC12/image_mean.binaryproto' "
+      "    batch_size: 256 "
+      "    crop_size: 227 "
+      "    mirror: true "
+      "    fg_threshold: 0.25 "
+      "    bg_threshold: 0.75 "
+      "    fg_fraction: 0.5 "
+      "    context_pad: 16 "
+      "    crop_mode: 'square' "
+      "  } "
+      "  top: 'window_data' "
+      "  top: 'window_label' "
+      "} "
+      "layers { "
       "  name: 'hdf5data' "
       "  type: HDF5_DATA "
       "  hdf5_data_param { "
@@ -1617,6 +1666,10 @@ TYPED_TEST(V0UpgradeTest, TestAllParams) {
       "  type: BNLL "
       "} "
       "layers { "
+      "  name: 'euclidean_loss' "
+      "  type: EUCLIDEAN_LOSS "
+      "} "
+      "layers { "
       "  name: 'flatten' "
       "  type: FLATTEN "
       "} "
@@ -1625,6 +1678,10 @@ TYPED_TEST(V0UpgradeTest, TestAllParams) {
       "  type: IM2COL "
       "} "
       "layers { "
+      "  name: 'images' "
+      "  type: IMAGE_DATA "
+      "} "
+      "layers { "
       "  name: 'multinomial_logistic_loss' "
       "  type: MULTINOMIAL_LOGISTIC_LOSS "
       "} "
index ef24a60..cb9fd7a 100644 (file)
@@ -274,6 +274,9 @@ bool UpgradeV0LayerConnection(const V0LayerConnection& v0_layer_connection,
       } else if (type == "hdf5_data") {
         layer_param->mutable_hdf5_data_param()->set_source(
             v0_layer_param.source());
+      } else if (type == "window_data") {
+        layer_param->mutable_window_data_param()->set_source(
+            v0_layer_param.source());
       } else if (type == "infogain_loss") {
         layer_param->mutable_infogain_loss_param()->set_source(
             v0_layer_param.source());
@@ -294,6 +297,9 @@ bool UpgradeV0LayerConnection(const V0LayerConnection& v0_layer_connection,
       if (type == "data") {
         layer_param->mutable_data_param()->set_mean_file(
             v0_layer_param.meanfile());
+      } else if (type == "window_data") {
+        layer_param->mutable_window_data_param()->set_mean_file(
+            v0_layer_param.meanfile());
       } else {
         LOG(ERROR) << "Unknown parameter meanfile for layer type " << type;
         is_fully_compatible = false;
@@ -306,6 +312,9 @@ bool UpgradeV0LayerConnection(const V0LayerConnection& v0_layer_connection,
       } else if (type == "hdf5_data") {
         layer_param->mutable_hdf5_data_param()->set_batch_size(
             v0_layer_param.batchsize());
+      } else if (type == "window_data") {
+        layer_param->mutable_window_data_param()->set_batch_size(
+            v0_layer_param.batchsize());
       } else {
         LOG(ERROR) << "Unknown parameter batchsize for layer type " << type;
         is_fully_compatible = false;
@@ -315,6 +324,9 @@ bool UpgradeV0LayerConnection(const V0LayerConnection& v0_layer_connection,
       if (type == "data") {
         layer_param->mutable_data_param()->set_crop_size(
             v0_layer_param.cropsize());
+      } else if (type == "window_data") {
+        layer_param->mutable_window_data_param()->set_crop_size(
+            v0_layer_param.cropsize());
       } else {
         LOG(ERROR) << "Unknown parameter cropsize for layer type " << type;
         is_fully_compatible = false;
@@ -323,6 +335,9 @@ bool UpgradeV0LayerConnection(const V0LayerConnection& v0_layer_connection,
     if (v0_layer_param.has_mirror()) {
       if (type == "data") {
         layer_param->mutable_data_param()->set_mirror(v0_layer_param.mirror());
+      } else if (type == "window_data") {
+        layer_param->mutable_window_data_param()->set_mirror(
+            v0_layer_param.mirror());
       } else {
         LOG(ERROR) << "Unknown parameter mirror for layer type " << type;
         is_fully_compatible = false;
@@ -355,6 +370,56 @@ bool UpgradeV0LayerConnection(const V0LayerConnection& v0_layer_connection,
         is_fully_compatible = false;
       }
     }
+    if (v0_layer_param.has_det_fg_threshold()) {
+      if (type == "window_data") {
+        layer_param->mutable_window_data_param()->set_fg_threshold(
+            v0_layer_param.det_fg_threshold());
+      } else {
+        LOG(ERROR) << "Unknown parameter det_fg_threshold for layer type "
+                   << type;
+        is_fully_compatible = false;
+      }
+    }
+    if (v0_layer_param.has_det_bg_threshold()) {
+      if (type == "window_data") {
+        layer_param->mutable_window_data_param()->set_bg_threshold(
+            v0_layer_param.det_bg_threshold());
+      } else {
+        LOG(ERROR) << "Unknown parameter det_bg_threshold for layer type "
+                   << type;
+        is_fully_compatible = false;
+      }
+    }
+    if (v0_layer_param.has_det_fg_fraction()) {
+      if (type == "window_data") {
+        layer_param->mutable_window_data_param()->set_fg_fraction(
+            v0_layer_param.det_fg_fraction());
+      } else {
+        LOG(ERROR) << "Unknown parameter det_fg_fraction for layer type "
+                   << type;
+        is_fully_compatible = false;
+      }
+    }
+    if (v0_layer_param.has_det_context_pad()) {
+      if (type == "window_data") {
+        layer_param->mutable_window_data_param()->set_context_pad(
+            v0_layer_param.det_context_pad());
+      } else {
+        LOG(ERROR) << "Unknown parameter det_context_pad for layer type "
+                   << type;
+        is_fully_compatible = false;
+      }
+    }
+    if (v0_layer_param.has_det_crop_mode()) {
+      if (type == "window_data") {
+        layer_param->mutable_window_data_param()->set_crop_mode(
+            v0_layer_param.det_crop_mode());
+      } else {
+        LOG(ERROR) << "Unknown parameter det_crop_mode for layer type "
+                   << type;
+        is_fully_compatible = false;
+      }
+    }
   }
   return is_fully_compatible;
 }
@@ -380,6 +445,8 @@ LayerParameter_LayerType UpgradeV0LayerType(const string& type) {
     return LayerParameter_LayerType_HDF5_DATA;
   } else if (type == "im2col") {
     return LayerParameter_LayerType_IM2COL;
+  } else if (type == "images") {
+    return LayerParameter_LayerType_IMAGE_DATA;
   } else if (type == "infogain_loss") {
     return LayerParameter_LayerType_INFOGAIN_LOSS;
   } else if (type == "innerproduct") {
@@ -402,9 +469,11 @@ LayerParameter_LayerType UpgradeV0LayerType(const string& type) {
     return LayerParameter_LayerType_SPLIT;
   } else if (type == "tanh") {
     return LayerParameter_LayerType_TANH;
+  } else if (type == "window_data") {
+    return LayerParameter_LayerType_WINDOW_DATA;
   } else {
     LOG(FATAL) << "Unknown layer name: " << type;
-    return LayerParameter_LayerType(-1);
+    return LayerParameter_LayerType_NONE;
   }
 }