def test_input_user_data_repack_dict_with_shapes_and_ports(self): graph = build_graph(self.nodes, self.edges) shape_1 = np.array([1, 160, 160, 3]) shape_2 = np.array([1, 127, 127, 3]) input, freeze_placeholder = input_user_data_repack(graph, {'Aa:0': shape_1, 'Bb:0': shape_2}, None) self.assertDictEqual(input, {'A': [{'shape': shape_1, 'out': 0}], 'B': [{'shape': shape_2, 'out': 0}]}) self.assertEqual(freeze_placeholder, None)
def test_freeze_new_placeholder_2(self): # create a new placeholder Ee by cutting input port with shape_2 = [2, 2] and freeze a value [[1.0, 1.0], [2.0, 3.0]] graph = build_graph(self.nodes, self.edges) shape_1 = np.array([1, 160, 160, 3]) shape_2 = np.array([2, 2]) input, freeze_placeholder = input_user_data_repack( graph, { 'Aa:0': shape_1, 'Ee': shape_2 }, { 'Bb': False, 'Ee': [[1.0, 1.0], [2.0, 3.0]] }) self.assertDictEqual( input, { 'A': [{ 'shape': shape_1, 'out': 0 }], 'B': [{ 'shape': None, 'port': None }], 'E': [{ 'shape': shape_2, 'port': None }] }) self.assertEqual(freeze_placeholder, { 'B': False, 'E/placeholder_port_None': [[1.0, 1.0], [2.0, 3.0]] })
def test_freeze_new_placeholder_1(self): # create a new placeholder Cc:0 by cutting output port with shape_2 = [5] and freeze a value [1.0 1.0 2.0 3.0 5.0] graph = build_graph(self.nodes, self.edges) shape_1 = np.array([1, 160, 160, 3]) shape_2 = np.array([5]) input, freeze_placeholder = input_user_data_repack( graph, { 'Aa:0': shape_1, 'Cc:0': shape_2 }, { 'Bb': False, 'Cc:0': [1.0, 1.0, 2.0, 3.0, 5.0] }) self.assertDictEqual( input, { 'A': [{ 'shape': shape_1, 'out': 0 }], 'B': [{ 'shape': None, 'port': None }], 'C': [{ 'shape': shape_2, 'out': 0 }] }) self.assertEqual(freeze_placeholder, { 'B': False, 'C/placeholder_out_port_0': [1.0, 1.0, 2.0, 3.0, 5.0] })
def test_input_user_data_repack_names_ports_in_out(self): graph = build_graph(self.nodes, self.edges) input, freeze_placeholder = input_user_data_repack( graph, ['Aa:0', '1:Cc'], None) self.assertDictEqual(input, { 'A': [{ 'shape': None, 'out': 0 }], 'C': [{ 'shape': None, 'in': 1 }] }) self.assertEqual(freeze_placeholder, None)
def test_input_user_data_repack_names_to_ids_list(self): graph = build_graph(self.nodes, self.edges) input, freeze_placeholder = input_user_data_repack( graph, ['Aa', 'Bb'], None) self.assertDictEqual( input, { 'A': [{ 'shape': None, 'port': None }], 'B': [{ 'shape': None, 'port': None }] }) self.assertEqual(freeze_placeholder, None)
def test_input_and_freeze(self): graph = build_graph(self.nodes, self.edges) shape_1 = tuple([1, 160, 160, 3]) input, freeze_placeholder = input_user_data_repack( graph, shape_1, {'Bb': True}) self.assertDictEqual( input, { 'A': [{ 'shape': shape_1, 'port': None }], 'B': [{ 'shape': None, 'port': None }] }) self.assertDictEqual(freeze_placeholder, {'B': True})
def test_freeze_placeholder_and_input(self): graph = build_graph(self.nodes, self.edges) shape_1 = np.array([1, 160, 160, 3]) input, freeze_placeholder = input_user_data_repack( graph, {'Aa:0': shape_1}, {'Bb': False}) self.assertDictEqual( input, { 'A': [{ 'shape': shape_1, 'out': 0 }], 'B': [{ 'shape': None, 'port': None }] }) self.assertEqual(freeze_placeholder, {'B': False})
def test_input_user_data_repack_none(self): graph = build_graph(self.nodes, self.edges) input, freeze_placeholder = input_user_data_repack(graph, None, None) self.assertEqual(input, None) self.assertEqual(freeze_placeholder, None)