Replicate¶
Description¶
This module replicates the output of the previous layer and is used to branch the neural network when it is built using Sequential.
Initializing¶
def __init__(self, times, name=None):
Parameters
Parameter | Allowed types | Description | Default |
---|---|---|---|
name | str | Layer name | None |
times | int | How many times to copy the output of the previous layer | – |
Explanations
-
Examples¶
Necessary imports.
>>> import numpy as np
>>> from PuzzleLib.Backend import gpuarray
>>> from PuzzleLib.Modules import Replicate
Info
gpuarray
is required to properly place the tensor in the GPU
>>> np.random.seed(1234)
>>> batchsize, maps, h, w = 1, 1, 5, 5
>>> data = gpuarray.to_gpu(np.random.randint(0, 9, (batchsize, maps, h, w)).astype(np.float32))
>>> print(data)
[[[[6. 6. 2. 1. 5.]
[2. 4. 3. 3. 7.]
[3. 1. 4. 4. 5.]
[7. 2. 2. 7. 5.]
[0. 2. 7. 8. 8.]]]]
>>> repl = Replicate(times=3)
>>> repl(data)
[[[[[6. 6. 2. 1. 5.]
[2. 4. 3. 3. 7.]
[3. 1. 4. 4. 5.]
[7. 2. 2. 7. 5.]
[0. 2. 7. 8. 8.]]]],
[[[[6. 6. 2. 1. 5.]
[2. 4. 3. 3. 7.]
[3. 1. 4. 4. 5.]
[7. 2. 2. 7. 5.]
[0. 2. 7. 8. 8.]]]],
[[[[6. 6. 2. 1. 5.]
[2. 4. 3. 3. 7.]
[3. 1. 4. 4. 5.]
[7. 2. 2. 7. 5.]
[0. 2. 7. 8. 8.]]]]]