# Upsample3D¶

## Description¶

Info

Parent class: Module

Derived classes: -

Increases the dimension of three-dimensional maps by a specified number of times, filling new cells with values according to the selected mode (see parameters).

In contrast to deconvolution this layer is not trainable.

## Initializing¶

def __init__(self, scale=2, mode="nearest", name=None):


Parameters

Parameter Allowed types Description Default
scale Union[int, tuple] Scale: a number by which the tensor dimensions will be multiplied 2
mode str New cells filling mode "nearest"
name str Layer name None

Explanations

scale - possible to specify either a single scale value in depth, height and width, or a tuple (scale_d, scale_h, scale_w), where scale_d - scale value for the map depth scale_h - scale value for the map height, and scale_w - for the width;

mode - possible options: "nearest" (copies the value of the nearest cell), "linear" (uses linear interpolation according to the values of nearby cells).

## Examples¶

Necessary imports.

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


Info

gpuarray is required to properly place the tensor in the GPU

batchsize, maps, d, h, w = 1, 1, 3, 3, 3
data = gpuarray.to_gpu(np.random.randint(0, 10, (batchsize, maps, d, h, w)).astype(np.float32))
upsample = Upsample3D(scale=2, mode="nearest")
upsample(data)


As mentioned above, the scale can be set different for depth, height and width (in this case, the length of the scale tuple should correspond to the number of map dimensions):

upsample = Upsample3D(scale=(2, 1, 3), mode="nearest")


With linear interpolation, the results will be different:

upsample = Upsample3D(scale=2, mode="linear")