DepthConcat

Description

Info

Parent class: Module

Derived classes: -

This module works with tensors of shape (N, C, H, W), where N - batch size, C - number of maps (channels), H - map height, W - map width. The difference from Concat is that the module concatenates tensors only along the channel axis, but does so even for tensors with different map sizes (see example).

Initializing

def __init__(self, name=None):

Parameters

Parameter Allowed types Description Default
name str Layer name None

Explanations

-

Examples

Necessary imports.

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

Info

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

For convenience, we shall limit ourselves to the batch size and the number of maps of 1.

np.random.seed(123)
data1 = gpuarray.to_gpu(np.random.randint(0, 9, (1, 1, 2, 2)).astype(np.float32))
data2 = gpuarray.to_gpu(np.random.randint(0, 9, (1, 1, 6, 6)).astype(np.float32))
data3 = gpuarray.to_gpu(np.random.randint(0, 9, (1, 1, 4, 3)).astype(np.float32))
print(data1)
[[[[2. 2.]
   [6. 1.]]]]
print(data2)
[[[[3. 6. 1. 0. 1. 0.]
   [0. 3. 4. 0. 0. 4.]
   [1. 7. 3. 2. 4. 7.]
   [2. 4. 8. 0. 7. 3.]
   [4. 6. 1. 5. 6. 2.]
   [1. 8. 3. 5. 0. 2.]]]]
print(data3)
[[[[6. 2. 4.]
   [4. 6. 3.]
   [0. 6. 4.]
   [7. 6. 7.]]]]
concat = DepthConcat()
data = concat([data1, data2, data3])
print(data)
[[[[0. 0. 0. 0. 0. 0.]
   [0. 0. 0. 0. 0. 0.]
   [0. 0. 2. 2. 0. 0.]
   [0. 0. 6. 1. 0. 0.]
   [0. 0. 0. 0. 0. 0.]
   [0. 0. 0. 0. 0. 0.]]

  [[3. 6. 1. 0. 1. 0.]
   [0. 3. 4. 0. 0. 4.]
   [1. 7. 3. 2. 4. 7.]
   [2. 4. 8. 0. 7. 3.]
   [4. 6. 1. 5. 6. 2.]
   [1. 8. 3. 5. 0. 2.]]

  [[0. 0. 0. 0. 0. 0.]
   [0. 6. 2. 4. 0. 0.]
   [0. 4. 6. 3. 0. 0.]
   [0. 0. 6. 4. 0. 0.]
   [0. 7. 6. 7. 0. 0.]
   [0. 0. 0. 0. 0. 0.]]]]
print(data.shape)
<div class="output">
(1, 3, 6, 6) ```