Learn R Programming

innsight (version 0.1.0)

ConvertedModel: Converted torch-based model

Description

This class stores all layers converted to torch in a module which can be used like the original model (but torch-based). In addition, it provides other functions that are useful for interpreting individual predictions or explaining the entire model. This model is part of the class Converter and is the core for all the necessary calculations in the methods provided in this package.

Usage

ConvertedModel(modules_list, dtype = "float")

Arguments

modules_list

A list of all accepted layers created by the 'Converter' class during initialization.

dtype

The data type for all the calculations and defined tensors. Use either 'float' for torch::torch_float or 'double' for torch::torch_double.

Public fields

modules_list

A list of all accepted layers created by the 'Converter' class during initialization.

dtype

The datatype for all the calculations and defined tensors. Either 'float' for torch::torch_float or 'double' for torch::torch_double

.

Method <code>forward()</code>

The forward method of the whole model, i.e. it calculates the output \(y=f(x)\) of a given input \(x\). In doing so, all intermediate values are stored in the individual torch modules from modules_list.

Usage

self(x, channels_first = TRUE)

Arguments

x

The input torch tensor of dimensions (batch_size, dim_in).

channels_first

If the input tensor x is given in the format 'channels first' use TRUE. Otherwise, if the channels are last, use FALSE and the input will be transformed into the format 'channels first'. Default: TRUE.

Return

Returns the output of the model with respect to the given inputs with dimensions (batch_size, dim_out).

Method <code>update_ref()</code>

This method updates the stored intermediate values in each module from the list modules_list when the reference input x_ref has changed.

Usage

self$update_ref(x_ref, channels_first = TRUE)

Arguments

x_ref

Reference input of the model of dimensions (1, dim_in).

channels_first

If the reference input tensor x is given in the format 'channels first' use TRUE. Otherwise, if the channels are last, use FALSE and the input will be transformed into the format 'channels first'. Default: TRUE.

Return

Returns the output of the reference input with dimension (1, dim_out) after passing through the model.

Method <code>set_dtype()</code>

This method changes the data type for all the layers in modules_list. Use either 'float' for torch::torch_float or 'double' for torch::torch_double.

Usage

self$set_dtype(dtype)

Arguments

dtype

The data type for all the calculations and defined tensors.