API Reference
SetConv2D
Bases: Layer
Implementation of the SetConv2D layer. For more details see Chinello & Boracchi (2025).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filters
|
int
|
Number of output filters in the convolution. |
required |
kernel_size
|
int | tuple
|
Size of the convolution kernel. |
required |
activation
|
string | None
|
Activation function to use. |
None
|
mhsa_dropout
|
float
|
Dropout rate for the MHSA layer. |
0.0
|
padding
|
string
|
Padding mode for convolution ( |
'same'
|
strides
|
int | tuple
|
Stride size for convolution. |
1
|
**kwargs
|
Additional keyword arguments for the Layer base class. |
{}
|
Source code in src/cstmodels/layers.py
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 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 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
|
build(input_shape)
This method simply marks the layer as built.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_shape
|
shapelike
|
Shape of the input to the layer. |
required |
Source code in src/cstmodels/layers.py
141 142 143 144 145 146 147 148 |
|
call(X, set_size)
Main logic for the SetConv2D layer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
tensor
|
Input tensor of shape |
required |
set_size
|
scalar
|
Size of the set dimension. |
required |
Returns:
Name | Type | Description |
---|---|---|
X |
tensor
|
Output tensor after applying SetConv2D operations. |
Source code in src/cstmodels/layers.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
|
get_config()
Returns the configuration of the layer for serialization.
Returns:
Name | Type | Description |
---|---|---|
config |
dict
|
Configuration of the layer for serialization. |
Source code in src/cstmodels/layers.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
|
SmartReshape2D
Bases: Layer
Reshapes 4D or 5D tensors to handle an explicit set dimension.
This layer is useful when working with data that may or may not have a set dimension
(e.g., (batch * set_size, H, W, C)
vs. (batch, set_size, H, W, C)
).
It automatically infers the correct shape and reshapes the input tensor accordingly.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
Keyword arguments for the Layer base class. |
{}
|
Source code in src/cstmodels/layers.py
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 |
|
build(input_shape)
This method simply marks the layer as built.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_shape
|
shapelike
|
Shape of the input to the layer. |
required |
Source code in src/cstmodels/layers.py
27 28 29 30 31 32 33 34 |
|
call(x, set_size=None)
Main logic for the SmartReshape2D layer.
If the input tensor has 5 dimensions, it is assumed to be in the format
(batch, set_size, H, W, C)
and is reshaped to
(batch * set_size, H, W, C)
.
If the input tensor has 4 dimensions, it is assumed to be in the format
(batch * set_size, H, W, C)
and is reshaped to
(batch, set_size, H, W, C)
, where set_size
is provided as an argument.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
tensor
|
Input tensor of shape |
required |
set_size
|
scalar
|
Size of the set dimension (required if input is 4D, optional if 5D)
or |
None
|
Returns:
Name | Type | Description |
---|---|---|
x |
tensor
|
The reshaped tensor. |
set_size |
scalar
|
The set size. |
Source code in src/cstmodels/layers.py
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 |
|
get_config()
Returns the configuration of the layer for serialization.
Returns:
Name | Type | Description |
---|---|---|
config |
dict
|
Configuration of the layer for serialization. |
Source code in src/cstmodels/layers.py
78 79 80 81 82 83 84 85 86 |
|
CST15(pretrained=True)
Loads or builds the CST15 model. In both cases, the model is compiled with Adam optimizer and Categorical Crossentropy loss.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pretrained
|
bool
|
If |
True
|
Returns:
Name | Type | Description |
---|---|---|
model |
KerasModel
|
The CST15 model instance. |
Source code in src/cstmodels/models.py
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 |
|