ConvertedModel {innsight} | R Documentation |
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, graph, input_nodes, output_nodes, dtype = "float")
Arguments
modules_list |
( |
graph |
(
|
input_nodes |
( |
output_nodes |
( |
dtype |
( |
Method forward()
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, save_input = FALSE, save_preactivation = FALSE, save_output = FAlSE, save_last_layer = FALSE)
Arguments
x
The input torch tensor for this model.
channels_first
If the input tensor
x
is given in the format 'channels first', useTRUE
. Otherwise, if the channels are last, useFALSE
and the input will be transformed into the format 'channels first'. Default:TRUE
.save_input
Logical value whether the inputs from each layer are to be saved or not. Default:
FALSE
.save_preactivation
Logical value whether the preactivations from each layer are to be saved or not. Default:
FALSE
.save_output
Logical value whether the outputs from each layer are to be saved or not. Default:
FALSE
.save_last_layer
Logical value whether the inputs, preactivations and outputs from the last layer are to be saved or not. Default:
FALSE
.
Return
Returns a list of the output values of the model with respect to the given inputs.
Method update_ref()
This method updates the intermediate values in each module from the
list modules_list
for the reference input x_ref
and returns the
output from it in the same way as in the forward
method.
Usage
self$update_ref(x_ref, channels_first = TRUE, save_input = FALSE, save_preactivation = FALSE, save_output = FAlSE, save_last_layer = FALSE)
Arguments
x_ref
Reference input of the model.
channels_first
If the tensor
x_ref
is given in the format 'channels first' useTRUE
. Otherwise, if the channels are last, useFALSE
and the input will be transformed into the format 'channels first'. Default:TRUE
.save_input
Logical value whether the inputs from each layer are to be saved or not. Default:
FALSE
.save_preactivation
Logical value whether the preactivations from each layer are to be saved or not. Default:
FALSE
.save_output
Logical value whether the outputs from each layer are to be saved or not. Default:
FALSE
.save_last_layer
Logical value whether the inputs, preactivations and outputs from the last layer are to be saved or not. Default:
FALSE
.
Return
Returns a list of the output values of the model with respect to the given reference input.
Method set_dtype()
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.