Beispiel #1
0
    def test_accum_ext(self, collect_attributes_mock):
        params = {
            'top_height': 200,
            'top_width': 300,
            'size_divisible_by': 3,
            'have_reference': 'False',
        }
        collect_attributes_mock.return_value = {**params, 'have_reference': 0}

        fake_pl = FakeAccumProtoLayer(FakeMultiParam(params))
        fake_node = FakeNode(fake_pl, None)

        AccumFrontExtractor.extract(fake_node)

        exp_res = {
            'type': "Accum",
            'top_height': 200,
            'top_width': 300,
            'size_divisible_by': 3,
            'have_reference': 0,
            'infer': AccumOp.accum_infer
        }

        for key in exp_res.keys():
            self.assertEqual(fake_node[key], exp_res[key])
Beispiel #2
0
    def test_proposal_ext_ideal_numbers(self, merge_attrs):
        params = {
            'feat_stride': 1,
            'base_size': 16,
            'min_size': 16,
            'ratio': 1,
            'scale': 2,
            'pre_nms_topn': 6000,
            'post_nms_topn': 300,
            'nms_thresh': 0.7
        }
        merge_attrs.return_value = {
            **params
        }

        fake_pl = FakeProposalProtoLayer(FakeMultiParam(params))
        fake_node = FakeNode(fake_pl, None)

        ProposalFrontExtractor.extract(fake_node)

        exp_res = {
            'type': "Proposal",
            'feat_stride': 1,
            'base_size': 16,
            'min_size': 16,
            'ratio': 1,
            'scale': 2,
            'pre_nms_topn': 6000,
            'post_nms_topn': 300,
            'nms_thresh': 0.7,
            'infer': ProposalOp.proposal_infer
        }

        for key in exp_res.keys():
            self.assertEqual(fake_node[key], exp_res[key])
    def test_reogyolo_ext_ideal_numbers(self, merge_attrs_mock):
        params = {
            'coords': 4,
            'classes': 20,
            'num': 5,
            'do_softmax': 1,
            'anchors': 5,
            'mask': 5,
        }
        params_flatten = {'axis': 1, 'end_axis': -1}
        merge_attrs_mock.return_value = {**params, **params_flatten}

        fake_pl = FakeRegionYoloProtoLayer(FakeMultiParam(params),
                                           FakeMultiParam(params_flatten))
        fake_node = FakeNode(fake_pl, None)

        RegionYoloFrontExtractor.extract(fake_node)

        exp_res = {
            'type': "RegionYolo",
            'coords': 4,
            'classes': 20,
            'num': 5,
            'axis': 1,
            'end_axis': -1,
            'do_softmax': 1,
            'anchors': 5,
            'mask': 5,
            'infer': RegionYoloOp.regionyolo_infer
        }

        for key in exp_res.keys():
            self.assertEqual(fake_node[key], exp_res[key])
Beispiel #4
0
    def test_simplernms_ext_ideal_numbers(self, merge_attrs_mock):
        params = {
            'cls_threshold': 0.5,
            'max_num_proposals': 300,
            'iou_threshold': 0.7,
            'min_bbox_size': 16,
            'feat_stride': 16,
            'pre_nms_topn': 6000,
            'post_nms_topn': 150,
            'scale': [1, 2, 3]
        }
        merge_attrs_mock.return_value = {**params}

        fake_pl = FakeSimplerNMSProtoLayer(FakeMultiParam(params))
        fake_node = FakeNode(fake_pl, None)

        SimplerNMSFrontExtractor.extract(fake_node)

        exp_res = {
            'cls_threshold': 0.5,
            'max_num_proposals': 300,
            'iou_threshold': 0.7,
            'min_bbox_size': 16,
            'feat_stride': 16,
            'pre_nms_topn': 6000,
            'post_nms_topn': 150,
            'scale': [1, 2, 3],
            'infer': SimplerNMSOp.simplernms_infer
        }

        for key in exp_res.keys():
            self.assertEqual(fake_node[key], exp_res[key])
    def test_proposal_ext_scale(self):
        params = {
            'param_str':
            "'feat_stride': 16, 'scale': [1,2,3], 'ratio':[5, 6,7]"
        }
        fake_pl = FakeProposalPythonProtoLayer(FakeMultiParam(params))
        fake_node = FakeNode(fake_pl, None)

        ProposalPythonFrontExtractor.extract(fake_node)

        exp_res = {
            'type': "Proposal",
            'feat_stride': 16,
            'base_size': 16,
            'min_size': 16,
            'ratio': [5, 6, 7],
            'scale': [1, 2, 3],
            'pre_nms_topn': 6000,
            'post_nms_topn': 300,
            'nms_thresh': 0.7,
            'infer': ProposalOp.proposal_infer
        }

        for key in exp_res.keys():
            self.assertEqual(fake_node[key], exp_res[key])
Beispiel #6
0
 def test_python_extractor_for_extractors(self):
     module = 'test_module'
     layer = 'test_layer'
     CaffePythonFrontExtractorOp.registered_ops['{}.{}'.format(module, layer)] = FakePythonExtractor
     params = FakeMultiParam({
         'module': module,
         'layer': layer,
         'param_str': "'feat_stride': 16"
     })
     self.assertTrue(PythonFrontExtractorOp.extract(FakeNode(FakePythonProtoLayer(params), None)))
    def test_bias(self, embed_input_mock):
        embed_input_mock.return_value = {}
        params = {'axis': 1}
        add_node = FakeNode(FakeBiasProtoLayer(FakeMultiParam(params)),
                            FakeModelLayer([1, 2, 3, 4, 5]))
        BiasToAdd.extract(add_node)

        exp_res = {'type': "Add", 'axis': 1}

        for key in exp_res.keys():
            self.assertEqual(add_node[key], exp_res[key])
Beispiel #8
0
 def test_python_extractor_for_op(self):
     module = 'test_module'
     layer = 'test_layer'
     CaffePythonFrontExtractorOp.registered_ops['{}.{}'.format(module, layer)] = \
         lambda node: CaffePythonFrontExtractorOp.parse_param_str(node.pb.python_param.param_str)
     params = FakeMultiParam({
         'module': module,
         'layer': layer,
         'param_str': "'feat_stride': 16"
     })
     ext = PythonFrontExtractorOp.extract(FakeNode(FakePythonProtoLayer(params), None))
     self.assertEqual({'feat_stride': 16}, ext)
Beispiel #9
0
    def test_da_ext_ideal_numbers(self, merge_attrs_mock):
        params = {
            'crop_width': 0,
            'crop_height': 0,
            'write_augmented': "",
            'max_multiplier': 255.0,
            'augment_during_test': True,
            'recompute_mean': 0,
            'write_mean': "",
            'mean_per_pixel': False,
            'mean': 0,
            'mode': "add",
            'bottomwidth': 0,
            'bottomheight': 0,
            'num': 0,
            'chromatic_eigvec': [0.0]

        }
        merge_attrs_mock.return_value = {
            **params,
            'test': 54,
            'test2': 'test3'
        }
        fake_pl = FakeDAProtoLayer(FakeMultiParam(params))
        fake_node = FakeNode(fake_pl, None)

        DataAugmentationFrontExtractor.extract(fake_node)
        exp_res = {
            'type': 'DataAugmentation',
            'op': 'DataAugmentation',
            'crop_width': 0,
            'crop_height': 0,
            'write_augmented': "",
            'max_multiplier': 255.0,
            'augment_during_test': 1,
            'recompute_mean': 0,
            'write_mean': "",
            'mean_per_pixel': 0,
            'mean': 0,
            'mode': "add",
            'bottomwidth': 0,
            'bottomheight': 0,
            'num': 0,
            'chromatic_eigvec': [0.0],
            'infer': DataAugmentationOp.data_augmentation_infer
        }

        for key in exp_res.keys():
            if key in ('chromatic_eigvec',):
                np.testing.assert_equal(exp_res[key], fake_node[key])
            else:
                self.assertEqual(exp_res[key], fake_node[key])
Beispiel #10
0
    def test_grn_ext_ideal_numbers(self, merge_attrs_mock):
        params = {'bias': 0.7}
        merge_attrs_mock.return_value = {**params}

        fake_pl = FakeGRNProtoLayer(FakeMultiParam(params))
        fake_node = FakeNode(fake_pl, None)

        GRNFrontExtractor.extract(fake_node)

        exp_res = {'type': "GRN", 'bias': 0.7, 'infer': copy_shape_infer}

        for key in exp_res.keys():
            self.assertEqual(fake_node[key], exp_res[key])
    def test_priorbox_ext_ideal_numbers_density(self, merge_attrs_mock):
        params = {
            'clip': False,
            'flip': True,
            'min_size': np.array([]),
            'max_size': np.array([]),
            'aspect_ratio': np.array([2, 3]),
            'variance': np.array(['0.2', '0.3', '0.2', '0.3']),
            'img_size': '300',
            'img_h': '0',
            'img_w': '0',
            'step': '0,5',
            'step_h': '0',
            'step_w': '0',
            'offset': '0.6',
            'fixed_size': np.array(['1', '32']),
            'fixed_ratio': np.array(['0.2', '0.5']),
            'density': np.array(['0.3', '0.6'])
        }
        merge_attrs_mock.return_value = {**params}

        fake_pl = FakePriorBoxProtoLayer(FakeMultiParamListFields(params))
        fake_node = FakeNode(fake_pl, None)

        PriorBoxFrontExtractor.extract(fake_node)

        exp_res = {
            'op': 'PriorBox',
            'type': 'PriorBox',
            'clip': 0,
            'variance': np.array(['0.2', '0.3', '0.2', '0.3']),
            'img_size': '300',
            'img_h': '0',
            'img_w': '0',
            'step': '0,5',
            'step_h': '0',
            'step_w': '0',
            'offset': '0.6',
            'fixed_size': np.array(['1', '32']),
            'fixed_ratio': np.array(['0.2', '0.5']),
            'density': np.array(['0.3', '0.6'])
        }

        for key in exp_res.keys():
            if key in [
                    'width', 'height', 'variance', 'fixed_size', 'fixed_ratio',
                    'density'
            ]:
                np.testing.assert_equal(fake_node[key], exp_res[key])
            else:
                self.assertEqual(fake_node[key], exp_res[key])
Beispiel #12
0
    def test_elu_ext(self, collect_attrs_mock):
        params = {'alpha': 4}
        collect_attrs_mock.return_value = {
            **params, 'test': 54,
            'test2': 'test3'
        }

        fn = FakeNode(FakeProtoLayer(FakeMultiParam(params)), None)
        ELUFrontExtractor.extract(fn)

        exp_res = {'type': 'Elu', 'alpha': 4}

        for i in exp_res:
            self.assertEqual(fn[i], exp_res[i])
    def test_ctcgreedydecoder_ext_ideal_numbers(self, merge_attrs_mock):
        params = {'ctc_merge_repeated': True}
        merge_attrs_mock.return_value = {**params}

        fake_pl = FakeCTCGreedyDecoderProtoLayer(FakeMultiParam(params))
        fake_node = FakeNode(fake_pl, None)

        CTCGreedyDecoderFrontExtractor.extract(fake_node)

        exp_res = {
            'type': "CTCGreedyDecoder",
            'ctc_merge_repeated': 1,
            'infer': CTCGreedyDecoderOp.infer
        }

        for key in exp_res.keys():
            self.assertEqual(fake_node[key], exp_res[key])
    def test_elu_ext_ideal_numbers(self, merge_attrs_mock):
        params = {'stride': 2}
        merge_attrs_mock.return_value = {**params}

        fake_pl = FakeReorgYoloProtoLayer(FakeMultiParam(params))
        fake_node = FakeNode(fake_pl, None)

        ReorgYoloFrontExtractor.extract(fake_node)

        exp_res = {
            'type': "ReorgYolo",
            'stride': 2,
            'infer': ReorgYoloOp.reorgyolo_infer
        }

        for key in exp_res.keys():
            self.assertEqual(fake_node[key], exp_res[key])
    def test_normalize_ext_ideal_numbers(self, collect_attributes_mock):
        params = {'across_spatial': 1, 'channel_shared': 0, 'eps': 0.00001}
        collect_attributes_mock.return_value = {**params}

        fake_pl = FakeNormalizeProtoLayer(FakeMultiParam(params))
        fake_node = FakeNode(fake_pl, None)

        NormalizeFrontExtractor.extract(fake_node)

        exp_res = {
            'type': "Normalize",
            'across_spatial': 1,
            'channel_shared': 0,
            'eps': 0.00001,
        }

        for key in exp_res.keys():
            self.assertEqual(fake_node[key], exp_res[key])
Beispiel #16
0
    def test_priorboxclustered_ext_ideal_numbers(self, merge_attrs_mock):
        params = {
            'width': '30.0',
            'height': '60.0',
            'clip': False,
            'flip': True,
            'variance': np.array(['0.2', '0.3', '0.2', '0.3']),
            'img_size': '300',
            'img_h': '0',
            'img_w': '0',
            'step': '0,5',
            'step_h': '0',
            'step_w': '0',
            'offset': '0.6'
        }
        merge_attrs_mock.return_value = {**params}

        fake_pl = FakePriorBoxClusteredProtoLayer(FakeMultiParam(params))
        fake_node = FakeNode(fake_pl, None)

        PriorBoxClusteredFrontExtractor.extract(fake_node)

        exp_res = {
            'op': 'PriorBoxClustered',
            'type': 'PriorBoxClustered',
            'width': '30.0',
            'height': '60.0',
            'clip': 0,
            'flip': 1,
            'variance': np.array(['0.2', '0.3', '0.2', '0.3']),
            'img_size': '300',
            'img_h': '0',
            'img_w': '0',
            'step': '0,5',
            'step_h': '0',
            'step_w': '0',
            'offset': '0.6'
        }

        for key in exp_res.keys():
            if key in ['width', 'height', 'variance']:
                np.testing.assert_equal(fake_node[key], exp_res[key])
            else:
                self.assertEqual(fake_node[key], exp_res[key])
Beispiel #17
0
    def test_argmax_ext_ideal_numbers(self, merge_attrs_mock):
        params = {'out_max_val': True, 'top_k': 100, 'axis': 2}
        merge_attrs_mock.return_value = {**params}

        fake_pl = FakeArgMaxProtoLayer(FakeMultiParam(params))
        fake_node = FakeNode(fake_pl, None)

        ArgMaxFrontExtractor.extract(fake_node)

        exp_res = {
            'out_max_val': True,
            'top_k': 100,
            'axis': 2,
            'infer': arg_ops_infer,
            'remove_values_output': True,
        }

        for key in exp_res.keys():
            self.assertEqual(fake_node[key], exp_res[key])
Beispiel #18
0
    def test_reogyolo_ext_ideal_numbers(self, merge_attrs_mock):
        params = {'channel_shared': False}

        merge_attrs_mock.return_value = {**params}

        fake_pl = FakePReLUProtoLayer(FakeMultiParam(params))
        fake_node = FakeNode(fake_pl, None)

        PreluFrontExtractor.extract(fake_node)

        exp_res = {
            'type': 'PReLU',
            'op': 'PReLU',
            'channel_shared': 0,
            'infer': PReLU.infer,
        }

        for key in exp_res.keys():
            self.assertEqual(fake_node[key], exp_res[key])
Beispiel #19
0
    def test_mvn_ext_ideal_numbers(self, collect_attributes_mock):
        params = {
            'normalize_variance': 'True',
            'across_channels': 'False',
            'eps': 1e-9
        }
        collect_attributes_mock.return_value = {'shift_file': 'some_file_path'}

        fake_pl = FakePowerFileProtoLayer(FakeMultiParam(params))
        fake_node = FakeNode(fake_pl, None)

        PowerFileFrontExtractor.extract(fake_node)

        exp_res = {
            'type': "PowerFile",
            'shift_file': 'some_file_path',
            'infer': copy_shape_infer
        }

        for key in exp_res.keys():
            self.assertEqual(fake_node[key], exp_res[key])
Beispiel #20
0
    def test_st_ext_ideal_numbers(self, merge_attrs_mock):
        params = {
            'transform_type': "ffff",
            'sampler_type': "gggg",
            'output_H': 56,
            'output_W': 78,
            'to_compute_dU': True,
            'theta_1_1': 0.1,
            'theta_1_2': 0.2,
            'theta_1_3': 0.3,
            'theta_2_1': 0.4,
            'theta_2_2': 0.5,
            'theta_2_3': 0.6
        }
        merge_attrs_mock.return_value = {**params}

        fake_pl = FakeSpatialTransformProtoLayer(FakeMultiParam(params))
        fake_node = FakeNode(fake_pl, None)

        SpatialTransformFrontExtractor.extract(fake_node)

        exp_res = {
            'type': "SpatialTransformer",
            'transform_type': "ffff",
            'sampler_type': "gggg",
            'output_H': 56,
            'output_W': 78,
            'to_compute_dU': 1,
            'theta_1_1': 0.1,
            'theta_1_2': 0.2,
            'theta_1_3': 0.3,
            'theta_2_1': 0.4,
            'theta_2_2': 0.5,
            'theta_2_3': 0.6,
            'infer': SpatialTransformOp.sp_infer
        }

        for key in exp_res.keys():
            self.assertEqual(fake_node[key], exp_res[key])
Beispiel #21
0
    def test_resample_ext_ideal_numbers(self, merge_attrs_mock):
        params = {
            'pad': 20,
            'kernel_size': 1,
            'max_displacement': 20,
            'stride_1': 1,
            'stride_2': 2,
            'single_direction': 0,
            'do_abs': False,
            'correlation_type': 'caffe.CorrelationParameter.MULTIPLY'
        }
        merge_attrs_mock.return_value = {
            **params,
            'test': 54,
            'test2': 'test3'
        }

        fake_pl = FakeCorrProtoLayer(FakeMultiParam(params))
        fake_node = FakeNode(fake_pl, None)

        CorrelationFrontExtractor.extract(fake_node)

        exp_res = {
            'type': "Correlation",
            'pad': 20,
            'kernel_size': 1,
            'max_displacement': 20,
            'stride_1': 1,
            'stride_2': 2,
            'single_direction': 0,
            'do_abs': False,
            'correlation_type': 'caffe.CorrelationParameter.MULTIPLY',
            'infer': CorrelationOp.corr_infer
        }

        for key in exp_res.keys():
            self.assertEqual(fake_node[key], exp_res[key])
Beispiel #22
0
    def test_crop_ext(self, collect_attributes_mock):
        params = {
            'axis': 0,
            'offset': 0,
        }
        collect_attributes_mock.return_value = {
            **params, 'test': 54,
            'test2': 'test3'
        }
        fake_pl = FakeCropProtoLayer(FakeMultiParam(params))
        fake_node = FakeNode(fake_pl, None)

        CropFrontExtractor.extract(fake_node)

        exp_res = {
            'type': 'Crop',
            'axis': 0,
            'offset': 0,
            'dim': None,  # set in infer
            'infer': crop_infer
        }

        for key in exp_res.keys():
            self.assertEqual(exp_res[key], fake_node[key])