2 Copyright (c) 2018-2019 Intel Corporation
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
21 from mo.utils.error import Error
22 from mo.utils.pipeline_config import PipelineConfig
24 file_content = """model {
28 keep_aspect_ratio_resizer {
34 type: "faster_rcnn_inception_v2"
35 first_stage_features_stride: 16
37 first_stage_anchor_generator {
38 grid_anchor_generator {
50 first_stage_box_predictor_conv_hyperparams {
58 truncated_normal_initializer {
59 stddev: 0.00999999977648
63 first_stage_nms_score_threshold: 0.0
64 first_stage_nms_iou_threshold: 0.699999988079
65 first_stage_max_proposals: 100
66 first_stage_localization_loss_weight: 2.0
67 first_stage_objectness_loss_weight: 1.0
69 maxpool_kernel_size: 2
71 second_stage_box_predictor {
72 mask_rcnn_box_predictor {
81 variance_scaling_initializer {
91 dropout_keep_probability: 1.0
94 second_stage_post_processing {
95 batch_non_max_suppression {
96 score_threshold: 0.300000011921
97 iou_threshold: 0.600000023842
98 max_detections_per_class: 100
99 max_total_detections: 100
101 score_converter: SOFTMAX
103 second_stage_localization_loss_weight: 2.0
104 second_stage_classification_loss_weight: 1.0
110 class TestingSimpleProtoParser(unittest.TestCase):
111 def test_pipeline_config_not_existing_file(self):
112 self.assertRaises(Error, PipelineConfig, "/abc/def")
114 def test_pipeline_config_non_model_file(self):
115 file = tempfile.NamedTemporaryFile('wt', delete=False)
116 file.write("non_model {}")
117 file_name = file.name
120 self.assertRaises(Error, PipelineConfig, file_name)
122 def test_pipeline_config_existing_file(self):
123 file = tempfile.NamedTemporaryFile('wt', delete=False)
124 file.write(file_content)
125 file_name = file.name
128 pipeline_config = PipelineConfig(file_name)
129 expected_result = {'resizer_min_dimension': 600,
130 'first_stage_nms_score_threshold': 0.0,
131 'anchor_generator_aspect_ratios': [0.5, 1.0, 2.0],
133 'anchor_generator_scales': [0.25, 0.5, 1.0, 2.0],
134 'first_stage_max_proposals': 100,
135 'first_stage_nms_iou_threshold': 0.699999988079,
136 'resizer_max_dimension': 1024,
137 'initial_crop_size': 14,
138 'frcnn_variance_height': 5.0,
139 'frcnn_variance_width': 5.0,
140 'frcnn_variance_x': 10.0,
141 'frcnn_variance_y': 10.0,
142 'ssd_anchor_generator_base_anchor_width': 1.0,
143 'ssd_anchor_generator_base_anchor_height': 1.0,
144 'anchor_generator_height': 256,
145 'anchor_generator_width': 256,
146 'anchor_generator_height_stride': 16,
147 'anchor_generator_width_stride': 16,
150 self.assertDictEqual(pipeline_config._model_params, expected_result)