velora.models.backbone¶
Documentation
Architecture backbones for feature extraction.
BasicCNN
¶
A CNN backbone from the DQN Nature paper: Human-level control through deep reinforcement learning [].
Only contains the Convolutional Network with a flattened output.
Useful for connecting with other architectures such as the
LiquidNCPNetwork
.
Source code in velora/models/backbone.py
Python | |
---|---|
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
|
__init__(in_channels)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
in_channels
|
int
|
the number of channels in the input image. E.g.,
|
required |
Source code in velora/models/backbone.py
Python | |
---|---|
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
|
forward(x)
¶
Forward pass through the network.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
torch.Tensor
|
a batch of images in the shape
|
required |
Returns:
Name | Type | Description |
---|---|---|
y_pred |
torch.Tensor
|
the flattened predicted feature maps. |
Source code in velora/models/backbone.py
Python | |
---|---|
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
|
out_size(dim)
¶
Calculates the size of the convolution output using a dummy input.
Often used as the in_features
to linear layers.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dim
|
Tuple[int, int]
|
the |
required |
Returns:
Name | Type | Description |
---|---|---|
output_size |
int
|
the number of feature maps. |
Source code in velora/models/backbone.py
Python | |
---|---|
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
|
MLP
¶
A dynamic multi-layer perceptron architecture for feature extraction.
Warning
The network output (y_pred
) is not passed through an activation function.
This must be applied manually (if required).
Source code in velora/models/backbone.py
Python | |
---|---|
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
|
__init__(in_features, n_hidden, out_features, *, activation='relu', dropout_p=0.0)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
in_features
|
int
|
the number of input features |
required |
n_hidden
|
List[int] | int
|
a |
required |
out_features
|
int
|
the number of output features |
required |
activation
|
str
|
the type of activation function used between layers |
'relu'
|
dropout_p
|
float
|
the dropout probability rate used between layers |
0.0
|
Source code in velora/models/backbone.py
Python | |
---|---|
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
|
forward(x)
¶
Performs a forward pass through the network.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
torch.Tensor
|
the input tensor |
required |
Returns:
Name | Type | Description |
---|---|---|
y_pred |
torch.Tensor
|
network predictions. |
Source code in velora/models/backbone.py
Python | |
---|---|
84 85 86 87 88 89 90 91 92 93 94 |
|