CNN
CNN
Bases: BaseBackbone
Source code in sequel/backbones/pytorch/cnn.py
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 95 96 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 |
|
__init__(channels, linear_layers=None, num_classes=10, multiplier=1, kernel_size=3, activation='relu', stride=2, use_maxpool=False)
Inits the CNN backbone.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
channels |
int
|
The number if in channels. |
required |
linear_layers |
Optional[Union[List, int]]
|
The linear layers' widths. These linear layers suceed
the convolutional layers. If set to None, no linear layers are used except the output layer, whose
width is defined by |
None
|
num_classes |
int
|
The number of output logits. Defaults to 10. |
10
|
multiplier |
int
|
Multiplies the number of channels for all layers, making the model wider. Defaults to 1. |
1
|
kernel_size |
int
|
The kernel size of the convolutions. Currenrly all convolutions have the share kernel size. Defaults to 3. |
3
|
activation |
str
|
The type of activation used. Defaults to "relu". |
'relu'
|
stride |
int
|
The convolutional stride. Defaults to 2. |
2
|
use_maxpool |
bool
|
If set, the model uses maxpool layers. Defaults to False. |
False
|
Raises:
Type | Description |
---|---|
ValueError
|
If stride is not equal to 1 or 2. |
ValueError
|
If maxpool and stride of 2 are used at the same time. |
ValueError
|
If |
Source code in sequel/backbones/pytorch/cnn.py
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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
|
get_model_output_features(config, model)
Calculates the output dimension of a model. This method is used to infer he number of out features of an
encoder, which serve as in_features
of the decoders (task-specific layers).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
omegaconf.ListConfig
|
The hydra config for the current experiment. |
required |
model |
torch.nn.Module
|
The PyTorch model (the encoder of the Shared-Bottom architecture.) |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
The number of out_features of the model. |
Source code in sequel/backbones/pytorch/cnn.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|