Skip to contents

Reshape a tensor to the given shape.

nn_module

Calls nn_reshape() when trained. This internally calls torch::torch_reshape() with the given shape.

Parameters

  • shape :: integer() | function()
    The desired output shape. One dimension at most can be -1, which torch infers from the number of elements. The first dimension is the batch dimension.

    It can also be a function(shape) that is called on the input shape and returns the output shape, e.g. \(shape) c(shape[1:2], 10). This expresses a reshape for inputs whose sizes are not known in advance, because the function is called again on the shape of the actual tensor when the network runs. Note that it is called with a shape that can contain NAs during shape inference. This is e.g. useful when there are multiple unknown dimensions such as (batch, sequence, ...).

Input and Output Channels

One input channel called "input" and one output channel called "output". For an explanation see PipeOpTorch.

State

The state is the value calculated by the public method $shapes_out().

Super classes

mlr3pipelines::PipeOp -> PipeOpTorch -> PipeOpTorchReshape

Methods

Inherited methods


PipeOpTorchReshape$new()

Creates a new instance of this R6 class.

Usage

PipeOpTorchReshape$new(id = "nn_reshape", param_vals = list())

Arguments

id

(character(1))
Identifier of the resulting object.

param_vals

(list())
List of hyperparameter settings, overwriting the hyperparameter settings that would otherwise be set during construction.


PipeOpTorchReshape$clone()

The objects of this class are cloneable with this method.

Usage

PipeOpTorchReshape$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

# Construct the PipeOp
pipeop = nn("reshape")
pipeop
#> 
#> ── PipeOp <reshape>: not trained ───────────────────────────────────────────────
#> Values: list()
#> 
#> ── Input channels: 
#>    name           train predict
#>  <char>          <char>  <char>
#>   input ModelDescriptor    Task
#> 
#> ── Output channels: 
#>    name           train predict
#>  <char>          <char>  <char>
#>  output ModelDescriptor    Task
# The available parameters
pipeop$param_set
#> <ParamSet(1)>
#>        id    class lower upper nlevels        default  value
#>    <char>   <char> <num> <num>   <num>         <list> <list>
#> 1:  shape ParamUty    NA    NA     Inf <NoDefault[0]> [NULL]