habana_frameworks.mediapipe.fn.Concat

Class:
  • habana_frameworks.mediapipe.fn.Concat(**kwargs)

Define graph call:
  • __call__(input1, input2)

Parameter:
  • input1 - First input tensor to operator. Supported dimensions: minimum = 1, maximum = 5. Supported data types: INT8, UINT8, BFLOAT16, FLOAT32.

  • input2 - Second input tensor to operator with the same dimensionality as input1 tensor. Supported dimensions: minimum = 1, maximum = 5. Supported data types: INT8, UINT8, BFLOAT16, FLOAT32.

Description:

Concatenates tensors along given axis.

Supported backend:
  • HPU

Keyword Arguments

kwargs

Description

axis

Axis along which tensors to be concatenated.

  • Type: int

  • Default: 0

  • Optional: no

dtype

Output data type.

  • Type: habana_frameworks.mediapipe.media_types.dtype

  • Default: UINT8

  • Optional: yes

  • Supported data types:

    • INT8

    • UINT8

    • BFLOAT16

    • FLOAT32

Note

  1. All input and output tensors are expected to have the same number of dimensions and the same shape except on the given concatenation dimension.

  2. Currently supports two inputs.

Example: Concat Operator

The following code snippet shows usage of Concat operator:

from habana_frameworks.mediapipe import fn
from habana_frameworks.mediapipe.mediapipe import MediaPipe
from habana_frameworks.mediapipe.media_types import imgtype as it
from habana_frameworks.mediapipe.media_types import dtype as dt

# Create media pipeline derived class
class myMediaPipe(MediaPipe):
    def __init__(self, device, dir, queue_depth, batch_size):
        super(
            myMediaPipe,
            self).__init__(
            device,
            queue_depth,
            batch_size,
            self.__class__.__name__)

        self.input0 = fn.ReadNumpyDatasetFromDir(num_outputs=1,
                                                 shuffle=False,
                                                 dir=dir,
                                                 pattern='x_0_concat_inp.npy',
                                                 dense=True,
                                                 dtype=dt.FLOAT32)

        self.input1 = fn.ReadNumpyDatasetFromDir(num_outputs=1,
                                                 shuffle=False,
                                                 dir=dir,
                                                 pattern='x_1_concat_inp.npy',
                                                 dense=True,
                                                 dtype=dt.FLOAT32)

        self.concat = fn.Concat(axis=2, dtype=dt.FLOAT32)

    def definegraph(self):
        input0 = self.input0()
        input1 = self.input1()
        output = self.concat(input0, input1)
        return output, input0, input1

def main():
    batch_size = 1
    img_dir = '/path/to/numpyfiles'
    queue_depth = 2

    # Create media pipeline object
    pipe = myMediaPipe('hpu', img_dir, queue_depth, batch_size)

    # Build media pipeline
    pipe.build()

    # Initialize media pipeline iterator
    pipe.iter_init()

    # Run media pipeline
    output, input0, input1 = pipe.run()

    # Copy data to host from device as numpy array
    output = output.as_cpu().as_nparray()
    input0 = input0.as_cpu().as_nparray()
    input1 = input1.as_cpu().as_nparray()

    # Display shapes
    print('input0 tensor shape:', input0.shape)
    print('input1 tensor shape:', input1.shape)
    print('output tensor shape:', output.shape)

if __name__ == "__main__":
    main()

The following is the output of Concat operator:

input0 tensor shape: (1, 128, 128)
input1 tensor shape: (1, 128, 128)
output tensor shape: (2, 128, 128)