Example #1
0
    def testTupleWithEmptyListAttr(self):
        attrs = {"something2": "[]"}

        attr_dict = AttrDictionary(attrs)
        a, b = attr_dict.tuple("something", int, (2, 3))
        self.assertEqual(2, a)
        self.assertEqual(3, b)
Example #2
0
    def testTupleWithoutAttr(self):
        attrs = {"something2": "(5,6,7)"}

        attr_dict = AttrDictionary(attrs)
        a, b, c = attr_dict.tuple("something", int, (1, 2, 3))
        self.assertEqual(1, a)
        self.assertEqual(2, b)
        self.assertEqual(3, c)
Example #3
0
    def testTupleAttr(self):
        attrs = {"something": "(5,6,7)"}

        attr_dict = AttrDictionary(attrs)
        a, b, c = attr_dict.tuple("something", int, (1, 2, 3))
        self.assertEqual(5, a)
        self.assertEqual(6, b)
        self.assertEqual(7, c)
Example #4
0
    def testListWithoutAttr(self):
        attrs = {"something2": "5,6,7"}

        attr_dict = AttrDictionary(attrs)
        l = attr_dict.list("something", int, [1, 2, 3])
        self.assertEqual(1, l[0])
        self.assertEqual(2, l[1])
        self.assertEqual(3, l[2])
Example #5
0
    def testListAttr(self):
        attrs = {"something": "5,6,7"}

        attr_dict = AttrDictionary(attrs)
        l = attr_dict.list("something", int, [1, 2, 3])
        self.assertEqual(5, l[0])
        self.assertEqual(6, l[1])
        self.assertEqual(7, l[2])
Example #6
0
    def testIntWithoutAttr(self):
        attrs = {
            "something2": "5"
        }

        attr_dict = AttrDictionary(attrs)
        attr = attr_dict.float("something", 1)
        self.assertEqual(1, attr)
Example #7
0
    def testStrAttrWithoutAttr(self):
        attrs = {
            "something2": "Val"
        }

        attr_dict = AttrDictionary(attrs)
        attr = attr_dict.str("something", "Text")
        self.assertEqual("Text", attr)
Example #8
0
    def testFloatAttr(self):
        attrs = {
            "something": "0.5"
        }

        attr_dict = AttrDictionary(attrs)
        attr = attr_dict.float("something", 0.1)
        self.assertEqual(0.5, attr)
Example #9
0
    def testBoolWithoutAttr(self):
        attrs = {
            "something": "1"
        }

        attr_dict = AttrDictionary(attrs)
        global_pool = attr_dict.bool("global_pool", False)
        self.assertEqual(False, global_pool)
Example #10
0
    def testBoolAsDigits(self):
        attrs = {
            "global_pool": "1"
        }

        attr_dict = AttrDictionary(attrs)
        global_pool = attr_dict.bool("global_pool", False)
        self.assertEqual(True, global_pool)
Example #11
0
    def testIntWithAttrNone(self):
        attrs = {
            "something": "None"
        }

        attr_dict = AttrDictionary(attrs)
        attr = attr_dict.int("something", None)
        self.assertEqual(None, attr)
Example #12
0
    def test_extract_slice_axis_layer(self):
        graph = build_graph(
            {'node_1': {'type': 'Identity', 'value': None, 'kind': 'op', 'op': 'Parameter'},
             'slice_axis_node': {'type': 'sigmoid', 'kind': 'op', 'op': 'slice_axis', },
             'node_3': {'type': 'Identity', 'value': None, 'kind': 'op'},
             },
            [
                ('node_1', 'slice_axis_node'),
                ('slice_axis_node', 'node_3'),
            ],
            {
                'slice_axis_node': {'symbol_dict': {'attrs': {'axis': 0, 'begin': 10, 'end': 25}}},
            })

        exp_attrs = {
            'type': 'Crop',
            'axis': 0,
            'offset': 10,
            'dim': 25
        }

        slice_axis_node = Node(graph, 'slice_axis_node')
        res = slice_axis_ext(AttrDictionary(slice_axis_node['symbol_dict']['attrs']))

        for key in exp_attrs.keys():
            self.assertEqual(res[key], exp_attrs[key])
Example #13
0
    def test_multi_box_prior_check_attrs(self):
        attrs = {
            'ratios': '(1,2,0.5)',
            'steps': '(0.02666666666666667, 0.02666666666666667)',
            'clip': 'False',
            'sizes': '(0.1,0.141)'
        }

        res = multi_box_prior_ext(AttrDictionary(attrs))
        exp_attrs = {
            'type': 'PriorBox',
            'step': 0.02666666666666667,
            'offset': 0.5,
            'variance': '0.100000,0.100000,0.200000,0.200000',
            'flip': 0,
            'clip': 0,
            'min_size': [0.1, 0.141],
            'max_size': '',
            'aspect_ratio': [1, 2, 0.5],
        }

        for key in exp_attrs.keys():
            if key in ['aspect_ratio', 'variance']:
                np.testing.assert_equal(res[key], exp_attrs[key])
            else:
                self.assertEqual(res[key], exp_attrs[key])
Example #14
0
    def test_multi_box_detection_check_attrs_without_top_k(self):
        attrs = {
            "force_suppress": "True",
            "nms_threshold": "0.2",
            "threshold": "0.02",
            "variances": "(0.1, 0.1, 0.2, 0.2)"
        }

        res = multi_box_detection_ext(AttrDictionary(attrs))

        exp_attrs = {
            'type': 'DetectionOutput',
            'num_classes': 21,
            'keep_top_k': -1,
            'variance_encoded_in_target': 0,
            'code_type': "caffe.PriorBoxParameter.CENTER_SIZE",
            'share_location': 1,
            'confidence_threshold': 0.02,
            'background_label_id': 0,
            'nms_threshold': 0.2,
            'top_k': -1,
            'decrease_label_id': 1,
            'clip': 1,
            'normalized': 1,
        }

        for key in exp_attrs.keys():
            self.assertEqual(res[key], exp_attrs[key])
Example #15
0
    def test_eltwise_mul(self):
        attrs = {}
        res = eltwise_ext(AttrDictionary(attrs),
                          infer=lambda a, b: a * b,
                          op_type="mul")
        exp_attrs = {'type': 'Eltwise', 'operation': 'mul'}

        for key in exp_attrs.keys():
            self.assertEqual(res[key], exp_attrs[key])
Example #16
0
 def test_crop_ext(self):
     params = {'offset': '(5, 5)', 'num_args': 2}
     res = crop_ext(AttrDictionary(params))
     exp_res = {
         'axis': 2,
         'offset': [5, 5],
         'dim': None,
         'infer': crop_infer,
         'type': 'Crop'
     }
     for key in exp_res.keys():
         self.assertEqual(res[key], exp_res[key])