Skip to content

Concat

Description

Info

Parent class: Module

Derived classes: -

This module performs the function of concatenation of input tensors along a given axis. It is similar to the concatenate function in numpy.

Initializing

def __init__(self, axis, name=None):

Parameters

Parameter Allowed types Description Default
axis int The axis along which the tensors are concatenated -
name str Layer name None

Explanations

-

Examples

Necessary imports.

import numpy as np
from PuzzleLib.Backend import gpuarray
from PuzzleLib.Modules import Concat

Info

gpuarray is required to properly place the tensor in the GPU.

Let us generate synthetic 4D tensors:

np.random.seed(123)
data = []
for i in range(3):
...   data.append(gpuarray.to_gpu(np.random.randn(np.random.randint(low=5, high=10), 10, 5, 3).astype(np.float32)))
...   print(data[i].shape)
(7, 10, 5, 3)
(6, 10, 5, 3)
(9, 10, 5, 3)

Let us initialize the operation with concatenation along the axis of the batch (axis=0):

concat = Concat(axis=0)
outdata = concat(data)
print(outdata.shape)
(22, 10, 5, 3)

Let us reinitialize the data for concatenation along the axis of the maps:

data = []
for i in range(3):
...   data.append(gpuarray.to_gpu(np.random.randn(10, np.random.randint(low=4, high=8), 4, 5).astype(np.float32)))
...   print(data[i].shape)
(10, 6, 4, 5)
(10, 6, 4, 5)
(10, 4, 4, 5)
concat = Concat(axis=1)
outdata = concat(data)
print(outdata.shape)
(10, 16, 4, 5)