Evolvable ResNet¶
An evolvable version of the ResNet architecture for image observation spaces.
Parameters¶
- class agilerl.modules.resnet.EvolvableResNet(*args, **kwargs)¶
Evolvable module that implements the architecture presented in ‘Deep Residual Learning for Image Recognition’. Designed to train CNN’s more successfully by introducing residual connections that skip one or more layers.
Paper: https://arxiv.org/abs/1512.03385
- Parameters:
input_shape (List[int]) – Input shape of the neural network
num_outputs (int) – Output layer dimension
channel_size (int) – A list of integers representing the number of channels in each convolutional layer
kernel_size (int) – A list of integers representing the kernel size of each convolutional layer
stride_size (int) – A list of integers representing the stride size of each convolutional layer
num_blocks (int) – Number of residual blocks that compose the network
output_activation (str, optional) – Output activation layer, defaults to None
scale_factor (int) – Scale factor for the network, defaults to 4
min_blocks (int) – Minimum number of residual blocks that compose the network, defaults to 1
max_blocks (int) – Maximum number of residual blocks that compose the network, defaults to 4
min_channel_size (int) – Minimum number of channels in each convolutional layer, defaults to 32
max_channel_size (int) – Maximum number of channels in each convolutional layer, defaults to 256
device (str, optional) – Device for accelerated computing, ‘cpu’ or ‘cuda’, defaults to ‘cpu’
name (str, optional) – Name of the network, defaults to ‘resnet’
- add_block() None ¶
Adds a hidden layer to neural network. Falls back on
add_channel()
if max hidden layers reached.
- add_channel(numb_new_channels: int | None = None) Dict[str, int] ¶
Remove channel from hidden layer of convolutional neural network.
- change_activation(activation: str, output: bool = False) None ¶
We currently do not support changing the activation function of the ResNet.
- create_resnet(input_shape: List[int], channel_size: int, kernel_size: int, stride_size: int, num_blocks: int, scale_factor: int) Sequential ¶
Creates and returns a convolutional neural network.
- Parameters:
in_channels (int) – The number of input channels.
channel_size (List[int]) – A list of integers representing the number of channels in each convolutional layer.
kernel_size (List[int]) – A list of integers representing the kernel size of each convolutional layer.
stride_size (List[int]) – A list of integers representing the stride size of each convolutional layer.
num_blocks (int) – The number of residual blocks in the CNN.
scale_factor (int) – The scale factor for the CNN.
- Returns:
The created convolutional neural network.
- Return type:
nn.Sequential
- forward(x: ndarray | Dict[str, ndarray] | Tuple[_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], ...] | Tensor | Dict[str, Tensor] | Tuple[Tensor, ...]) Tensor ¶
Returns output of neural network.
- Parameters:
x (torch.Tensor) – Neural network input
- Returns:
Neural network output
- Return type:
torch.Tensor
- recreate_network(shrink_params: bool = False) None ¶
Recreates neural networks.
- Parameters:
shrink_params (bool, optional) – Flag indicating whether to shrink the parameters, defaults to False
- remove_block() None ¶
Removes a hidden layer from neural network. Falls back on
add_channel()
if min hidden layers reached.