this->RunPaddingUpgradeTest(input_proto, expected_output_proto);
}
-class V0UpgradeTest : public ::testing::Test {
+class NetUpgradeTest : public ::testing::Test {
protected:
void RunV0UpgradeTest(
const string& input_param_string, const string& output_param_string) {
EXPECT_EQ(expected_output_param.DebugString(),
actual_output_param.DebugString());
}
+
+ void RunV1UpgradeTest(
+ const string& input_param_string, const string& output_param_string) {
+ // Test that UpgradeV0Net called on the NetParameter proto specified by
+ // input_param_string results in the NetParameter proto specified by
+ // output_param_string.
+ NetParameter input_param;
+ CHECK(google::protobuf::TextFormat::ParseFromString(
+ input_param_string, &input_param));
+ NetParameter expected_output_param;
+ CHECK(google::protobuf::TextFormat::ParseFromString(
+ output_param_string, &expected_output_param));
+ NetParameter actual_output_param;
+ UpgradeV1Net(input_param, &actual_output_param);
+ EXPECT_EQ(expected_output_param.DebugString(),
+ actual_output_param.DebugString());
+ }
};
-TEST_F(V0UpgradeTest, TestSimple) {
- const string& input_proto =
+TEST_F(NetUpgradeTest, TestSimple) {
+ const string& v0_proto =
"name: 'CaffeNet' "
"layers { "
" layer { "
" bottom: 'fc8' "
" bottom: 'label' "
"} ";
- const string& expected_output_proto =
+ const string& expected_v1_proto =
"name: 'CaffeNet' "
"layers { "
" name: 'data' "
" bottom: 'fc8' "
" bottom: 'label' "
"} ";
- this->RunV0UpgradeTest(input_proto, expected_output_proto);
+ this->RunV0UpgradeTest(v0_proto, expected_v1_proto);
+
+ const string& expected_v2_proto =
+ "name: 'CaffeNet' "
+ "layer { "
+ " name: 'data' "
+ " type: 'Data' "
+ " data_param { "
+ " source: '/home/jiayq/Data/ILSVRC12/train-leveldb' "
+ " batch_size: 256 "
+ " } "
+ " transform_param { "
+ " crop_size: 227 "
+ " mirror: true "
+ " mean_file: '/home/jiayq/Data/ILSVRC12/image_mean.binaryproto' "
+ " } "
+ " top: 'data' "
+ " top: 'label' "
+ "} "
+ "layer { "
+ " name: 'conv1' "
+ " type: 'Convolution' "
+ " convolution_param { "
+ " num_output: 96 "
+ " kernel_size: 11 "
+ " stride: 4 "
+ " pad: 2 "
+ " weight_filler { "
+ " type: 'gaussian' "
+ " std: 0.01 "
+ " } "
+ " bias_filler { "
+ " type: 'constant' "
+ " value: 0. "
+ " } "
+ " } "
+ " blobs_lr: 1. "
+ " blobs_lr: 2. "
+ " weight_decay: 1. "
+ " weight_decay: 0. "
+ " bottom: 'data' "
+ " top: 'conv1' "
+ "} "
+ "layer { "
+ " name: 'fc8' "
+ " type: 'InnerProduct' "
+ " inner_product_param { "
+ " num_output: 1000 "
+ " weight_filler { "
+ " type: 'gaussian' "
+ " std: 0.01 "
+ " } "
+ " bias_filler { "
+ " type: 'constant' "
+ " value: 0 "
+ " } "
+ " } "
+ " blobs_lr: 1. "
+ " blobs_lr: 2. "
+ " weight_decay: 1. "
+ " weight_decay: 0. "
+ " bottom: 'conv1' "
+ " top: 'fc8' "
+ "} "
+ "layer { "
+ " name: 'loss' "
+ " type: 'SoftmaxWithLoss' "
+ " bottom: 'fc8' "
+ " bottom: 'label' "
+ "} ";
+ this->RunV1UpgradeTest(expected_v1_proto, expected_v2_proto);
}
// Test any layer or parameter upgrades not covered by other tests.
-TEST_F(V0UpgradeTest, TestAllParams) {
+TEST_F(NetUpgradeTest, TestAllParams) {
const string& input_proto =
"name: 'CaffeNet' "
"input: 'input_data' "
this->RunV0UpgradeTest(input_proto, expected_output_proto);
}
-TEST_F(V0UpgradeTest, TestImageNet) {
- const string& input_proto =
+TEST_F(NetUpgradeTest, TestImageNet) {
+ const string& v0_proto =
"name: 'CaffeNet' "
"layers { "
" layer { "
" bottom: 'fc8' "
" bottom: 'label' "
"} ";
- const string& expected_output_proto =
+ const string& expected_v1_proto =
"name: 'CaffeNet' "
"layers { "
" name: 'data' "
" bottom: 'fc8' "
" bottom: 'label' "
"} ";
- this->RunV0UpgradeTest(input_proto, expected_output_proto);
-}
+ this->RunV0UpgradeTest(v0_proto, expected_v1_proto);
+
+ const string& expected_v2_proto =
+ "name: 'CaffeNet' "
+ "layer { "
+ " name: 'data' "
+ " type: 'Data' "
+ " data_param { "
+ " source: '/home/jiayq/Data/ILSVRC12/train-leveldb' "
+ " batch_size: 256 "
+ " } "
+ " transform_param { "
+ " crop_size: 227 "
+ " mirror: true "
+ " mean_file: '/home/jiayq/Data/ILSVRC12/image_mean.binaryproto' "
+ " } "
+ " top: 'data' "
+ " top: 'label' "
+ "} "
+ "layer { "
+ " name: 'conv1' "
+ " type: 'Convolution' "
+ " convolution_param { "
+ " num_output: 96 "
+ " kernel_size: 11 "
+ " stride: 4 "
+ " weight_filler { "
+ " type: 'gaussian' "
+ " std: 0.01 "
+ " } "
+ " bias_filler { "
+ " type: 'constant' "
+ " value: 0. "
+ " } "
+ " } "
+ " blobs_lr: 1. "
+ " blobs_lr: 2. "
+ " weight_decay: 1. "
+ " weight_decay: 0. "
+ " bottom: 'data' "
+ " top: 'conv1' "
+ "} "
+ "layer { "
+ " name: 'relu1' "
+ " type: 'ReLU' "
+ " bottom: 'conv1' "
+ " top: 'conv1' "
+ "} "
+ "layer { "
+ " name: 'pool1' "
+ " type: 'Pooling' "
+ " pooling_param { "
+ " pool: MAX "
+ " kernel_size: 3 "
+ " stride: 2 "
+ " } "
+ " bottom: 'conv1' "
+ " top: 'pool1' "
+ "} "
+ "layer { "
+ " name: 'norm1' "
+ " type: 'LRN' "
+ " lrn_param { "
+ " local_size: 5 "
+ " alpha: 0.0001 "
+ " beta: 0.75 "
+ " } "
+ " bottom: 'pool1' "
+ " top: 'norm1' "
+ "} "
+ "layer { "
+ " name: 'conv2' "
+ " type: 'Convolution' "
+ " convolution_param { "
+ " num_output: 256 "
+ " group: 2 "
+ " kernel_size: 5 "
+ " pad: 2 "
+ " weight_filler { "
+ " type: 'gaussian' "
+ " std: 0.01 "
+ " } "
+ " bias_filler { "
+ " type: 'constant' "
+ " value: 1. "
+ " } "
+ " } "
+ " blobs_lr: 1. "
+ " blobs_lr: 2. "
+ " weight_decay: 1. "
+ " weight_decay: 0. "
+ " bottom: 'norm1' "
+ " top: 'conv2' "
+ "} "
+ "layer { "
+ " name: 'relu2' "
+ " type: 'ReLU' "
+ " bottom: 'conv2' "
+ " top: 'conv2' "
+ "} "
+ "layer { "
+ " name: 'pool2' "
+ " type: 'Pooling' "
+ " pooling_param { "
+ " pool: MAX "
+ " kernel_size: 3 "
+ " stride: 2 "
+ " } "
+ " bottom: 'conv2' "
+ " top: 'pool2' "
+ "} "
+ "layer { "
+ " name: 'norm2' "
+ " type: 'LRN' "
+ " lrn_param { "
+ " local_size: 5 "
+ " alpha: 0.0001 "
+ " beta: 0.75 "
+ " } "
+ " bottom: 'pool2' "
+ " top: 'norm2' "
+ "} "
+ "layer { "
+ " name: 'conv3' "
+ " type: 'Convolution' "
+ " convolution_param { "
+ " num_output: 384 "
+ " kernel_size: 3 "
+ " pad: 1 "
+ " weight_filler { "
+ " type: 'gaussian' "
+ " std: 0.01 "
+ " } "
+ " bias_filler { "
+ " type: 'constant' "
+ " value: 0. "
+ " } "
+ " } "
+ " blobs_lr: 1. "
+ " blobs_lr: 2. "
+ " weight_decay: 1. "
+ " weight_decay: 0. "
+ " bottom: 'norm2' "
+ " top: 'conv3' "
+ "} "
+ "layer { "
+ " name: 'relu3' "
+ " type: 'ReLU' "
+ " bottom: 'conv3' "
+ " top: 'conv3' "
+ "} "
+ "layer { "
+ " name: 'conv4' "
+ " type: 'Convolution' "
+ " convolution_param { "
+ " num_output: 384 "
+ " group: 2 "
+ " kernel_size: 3 "
+ " pad: 1 "
+ " weight_filler { "
+ " type: 'gaussian' "
+ " std: 0.01 "
+ " } "
+ " bias_filler { "
+ " type: 'constant' "
+ " value: 1. "
+ " } "
+ " } "
+ " blobs_lr: 1. "
+ " blobs_lr: 2. "
+ " weight_decay: 1. "
+ " weight_decay: 0. "
+ " bottom: 'conv3' "
+ " top: 'conv4' "
+ "} "
+ "layer { "
+ " name: 'relu4' "
+ " type: 'ReLU' "
+ " bottom: 'conv4' "
+ " top: 'conv4' "
+ "} "
+ "layer { "
+ " name: 'conv5' "
+ " type: 'Convolution' "
+ " convolution_param { "
+ " num_output: 256 "
+ " group: 2 "
+ " kernel_size: 3 "
+ " pad: 1 "
+ " weight_filler { "
+ " type: 'gaussian' "
+ " std: 0.01 "
+ " } "
+ " bias_filler { "
+ " type: 'constant' "
+ " value: 1. "
+ " } "
+ " } "
+ " blobs_lr: 1. "
+ " blobs_lr: 2. "
+ " weight_decay: 1. "
+ " weight_decay: 0. "
+ " bottom: 'conv4' "
+ " top: 'conv5' "
+ "} "
+ "layer { "
+ " name: 'relu5' "
+ " type: 'ReLU' "
+ " bottom: 'conv5' "
+ " top: 'conv5' "
+ "} "
+ "layer { "
+ " name: 'pool5' "
+ " type: 'Pooling' "
+ " pooling_param { "
+ " kernel_size: 3 "
+ " pool: MAX "
+ " stride: 2 "
+ " } "
+ " bottom: 'conv5' "
+ " top: 'pool5' "
+ "} "
+ "layer { "
+ " name: 'fc6' "
+ " type: 'InnerProduct' "
+ " inner_product_param { "
+ " num_output: 4096 "
+ " weight_filler { "
+ " type: 'gaussian' "
+ " std: 0.005 "
+ " } "
+ " bias_filler { "
+ " type: 'constant' "
+ " value: 1. "
+ " } "
+ " } "
+ " blobs_lr: 1. "
+ " blobs_lr: 2. "
+ " weight_decay: 1. "
+ " weight_decay: 0. "
+ " bottom: 'pool5' "
+ " top: 'fc6' "
+ "} "
+ "layer { "
+ " name: 'relu6' "
+ " type: 'ReLU' "
+ " bottom: 'fc6' "
+ " top: 'fc6' "
+ "} "
+ "layer { "
+ " name: 'drop6' "
+ " type: 'Dropout' "
+ " dropout_param { "
+ " dropout_ratio: 0.5 "
+ " } "
+ " bottom: 'fc6' "
+ " top: 'fc6' "
+ "} "
+ "layer { "
+ " name: 'fc7' "
+ " type: 'InnerProduct' "
+ " inner_product_param { "
+ " num_output: 4096 "
+ " weight_filler { "
+ " type: 'gaussian' "
+ " std: 0.005 "
+ " } "
+ " bias_filler { "
+ " type: 'constant' "
+ " value: 1. "
+ " } "
+ " } "
+ " blobs_lr: 1. "
+ " blobs_lr: 2. "
+ " weight_decay: 1. "
+ " weight_decay: 0. "
+ " bottom: 'fc6' "
+ " top: 'fc7' "
+ "} "
+ "layer { "
+ " name: 'relu7' "
+ " type: 'ReLU' "
+ " bottom: 'fc7' "
+ " top: 'fc7' "
+ "} "
+ "layer { "
+ " name: 'drop7' "
+ " type: 'Dropout' "
+ " dropout_param { "
+ " dropout_ratio: 0.5 "
+ " } "
+ " bottom: 'fc7' "
+ " top: 'fc7' "
+ "} "
+ "layer { "
+ " name: 'fc8' "
+ " type: 'InnerProduct' "
+ " inner_product_param { "
+ " num_output: 1000 "
+ " weight_filler { "
+ " type: 'gaussian' "
+ " std: 0.01 "
+ " } "
+ " bias_filler { "
+ " type: 'constant' "
+ " value: 0 "
+ " } "
+ " } "
+ " blobs_lr: 1. "
+ " blobs_lr: 2. "
+ " weight_decay: 1. "
+ " weight_decay: 0. "
+ " bottom: 'fc7' "
+ " top: 'fc8' "
+ "} "
+ "layer { "
+ " name: 'loss' "
+ " type: 'SoftmaxWithLoss' "
+ " bottom: 'fc8' "
+ " bottom: 'label' "
+ "} ";
+ this->RunV1UpgradeTest(expected_v1_proto, expected_v2_proto);
+} // NOLINT(readability/fn_size)
-} // namespace caffe
+} // NOLINT(readability/fn_size) // namespace caffe