def test_caffe_interp_infer_wh(self): graph = build_graph( nodes_attributes, [('node_1', 'interp'), ('interp', 'node_3'), ('node_3', 'op_output')], { 'node_3': { 'shape': None }, 'node_1': { 'shape': np.array([1, 1024, 1, 1]) }, 'interp': { 'width': 65, 'height': 33, 'zoom_factor': 1, 'shrink_factor': 1, 'pad_beg': 0, 'pad_end': 0 } }) graph.graph['layout'] = 'NCHW' interp_node = Node(graph, 'interp') InterpOp.interp_infer(interp_node) exp_shape = np.array([1, 1024, 33, 65]) res_shape = graph.node['node_3']['shape'] for i in range(0, len(exp_shape)): self.assertEqual(exp_shape[i], res_shape[i])
def test_caffe_interp_2_blobs(self): graph = build_graph( nodes_attributes, [('node_1', 'interp'), ('node_2', 'interp'), ('interp', 'node_3'), ('node_3', 'op_output')], { 'node_3': { 'shape': None }, 'node_1': { 'shape': np.array([1, 256, 33, 66]) }, 'node_2': { 'shape': np.array([1, 1, 3, 6]) }, 'interp': { 'zoom_factor': 1, 'shrink_factor': 1, 'pad_beg': 0, 'pad_end': 0, 'parse_2nd_input': 'shape', } }) graph.graph['layout'] = 'NCHW' interp_node = Node(graph, 'interp') InterpOp.interp_infer(interp_node) exp_shape = np.array([1, 256, 3, 6]) res_shape = graph.node['node_3']['shape'] for i in range(0, len(exp_shape)): self.assertEqual(exp_shape[i], res_shape[i])
def test_tf_interp_infer_two_inputs(self): graph = build_graph( nodes_attributes, [('node_1', 'interp'), ('node_2', 'interp'), ('interp', 'node_3')], { 'node_1': { 'shape': np.array([1, 20, 30, 100]) }, 'node_2': { 'shape': np.array([2]), 'value': np.array([2, 3]) } }) graph.graph['layout'] = 'NHWC' interp_node = Node(graph, 'interp') InterpOp.interp_infer(interp_node) exp_shape = np.array([1, 2, 3, 100]) res_shape = graph.node['node_3']['shape'] for i in range(0, len(exp_shape)): self.assertEqual(exp_shape[i], res_shape[i])
def test_tf_interp_infer_one_input_hw(self): graph = build_graph( nodes_attributes, [('node_1', 'interp'), ('interp', 'node_3')], { 'node_1': { 'shape': np.array([1, 20, 30, 100]) }, 'interp': { 'height': 4, 'width': 6, 'pad_beg': 0, 'pad_end': 0, 'zoom_factor': None, 'shrink_factor': None } }) graph.graph['layout'] = 'NHWC' interp_node = Node(graph, 'interp') InterpOp.interp_infer(interp_node) exp_shape = np.array([1, 4, 6, 100]) res_shape = graph.node['node_3']['shape'] for i in range(0, len(exp_shape)): self.assertEqual(exp_shape[i], res_shape[i])
def test_caffe_interp_infer_zoom_shrink_error(self): graph = build_graph( nodes_attributes, [('node_1', 'interp'), ('interp', 'node_3'), ('node_3', 'op_output')], { 'node_3': { 'shape': None }, 'node_1': { 'shape': np.array([1, 256, 33, 65]) }, 'interp': { 'zoom_factor': 0, 'height': 0, 'width': 0, 'shrink_factor': 0, 'pad_beg': 0, 'pad_end': 0 } }) graph.graph['layout'] = 'NCHW' interp_node = Node(graph, 'interp') InterpOp.interp_infer(interp_node) self.assertIsNone(graph.node['node_3']['shape'])