def test_case_3(self, update_parameter_shape_mock):
        # test for case #3 described in the ObjectDetectionAPIPreprocessor2Replacement
        update_parameter_shape_mock.return_value = (None, None)

        edges = [
            *connect_front('input', self.start_node_name),
            *connect_front(self.start_node_name, 'resize'),
            *connect_front('resize', self.end_node_name),
            *connect_front(self.end_node_name, 'result'),
        ]
        graph = build_graph(self.nodes, edges)
        graph.stage = 'front'
        graph.graph['cmd_params'] = Namespace(
            tensorflow_object_detection_api_pipeline_config=__file__)

        with unittest.mock.patch(
                'builtins.open',
                unittest.mock.mock_open(read_data=file_content)):
            ObjectDetectionAPIPreprocessor2Replacement().transform_graph(
                graph, self.replacement_desc)

        (flag, resp) = compare_graphs(graph,
                                      self.build_ref_graph(False),
                                      'result',
                                      check_op_attrs=True)
        self.assertTrue(flag, resp)
    def test_case_1_no_pad_to_max_dim(self, update_parameter_shape_mock):
        # test for case #1 described in the ObjectDetectionAPIPreprocessor2Replacement
        # sub/mul should be kept even though they are applied before prep-processing and pad_to_max_dimension is False
        update_parameter_shape_mock.return_value = (None, None)
        edges = [
            *connect_front('input', '0:mul'),
            *connect_front('mul_const', '1:mul'),
            *connect_front('sub_const', '0:sub'),
            *connect_front('mul', '1:sub'),
            *connect_front('sub', self.start_node_name),
            *connect_front(self.start_node_name, 'resize'),
            *connect_front('resize', self.end_node_name),
            *connect_front(self.end_node_name, 'result'),
        ]
        graph = build_graph(self.nodes, edges)
        graph.stage = 'front'
        graph.graph['cmd_params'] = Namespace(
            tensorflow_object_detection_api_pipeline_config=__file__)

        updated_pipeline_config_content = file_content.replace(
            'pad_to_max_dimension: true', 'pad_to_max_dimension: false')
        with unittest.mock.patch(
                'builtins.open',
                unittest.mock.mock_open(
                    read_data=updated_pipeline_config_content)):
            ObjectDetectionAPIPreprocessor2Replacement().transform_graph(
                graph, self.replacement_desc)

        (flag, resp) = compare_graphs(graph,
                                      self.build_ref_graph(True),
                                      'result',
                                      check_op_attrs=True)
        self.assertTrue(flag, resp)
    def test_case_6(self, update_parameter_shape_mock):
        # test for case #6 described in the ObjectDetectionAPIPreprocessor2Replacement
        update_parameter_shape_mock.return_value = (None, None)

        graph = self.build_main_graph('no')
        graph.graph['cmd_params'] = Namespace(tensorflow_object_detection_api_pipeline_config=__file__)

        with unittest.mock.patch('builtins.open', unittest.mock.mock_open(read_data=file_content)):
            ObjectDetectionAPIPreprocessor2Replacement().transform_graph(graph, self.replacement_desc)

        (flag, resp) = compare_graphs(graph, self.build_ref_graph(False), 'result', check_op_attrs=True)
        self.assertTrue(flag, resp)