def testTupleWithEmptyTupleAttr(self): attrs = {"something2": "()"} attr_dict = AttrDictionary(attrs) a, b = attr_dict.tuple("something", int, (2, 3)) self.assertEqual(2, a) self.assertEqual(3, b)
def testIntWithoutAttr(self): attrs = { "something2": "5" } attr_dict = AttrDictionary(attrs) attr = attr_dict.float("something", 1) self.assertEqual(1, attr)
def testFloatAttr(self): attrs = { "something": "0.5" } attr_dict = AttrDictionary(attrs) attr = attr_dict.float("something", 0.1) self.assertEqual(0.5, attr)
def testStrAttrWithoutAttr(self): attrs = { "something2": "Val" } attr_dict = AttrDictionary(attrs) attr = attr_dict.str("something", "Text") self.assertEqual("Text", attr)
def testBoolWithoutAttr(self): attrs = { "something": "1" } attr_dict = AttrDictionary(attrs) global_pool = attr_dict.bool("global_pool", False) self.assertEqual(False, global_pool)
def testBoolAsDigits(self): attrs = { "global_pool": "1" } attr_dict = AttrDictionary(attrs) global_pool = attr_dict.bool("global_pool", False) self.assertEqual(True, global_pool)
def testIntWithAttrNone(self): attrs = { "something": "None" } attr_dict = AttrDictionary(attrs) attr = attr_dict.int("something", None) self.assertEqual(None, attr)
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)
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)
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])
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])
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 = { 'op': '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])
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])