cnn
Bases: rpn
A Convolutional Neural Network (CNN) built on the RPN framework.
This CNN architecture consists of:
- Grid-based interdependence layers for convolution.
- Optional pooling layers for feature map compression.
- Fully connected perceptron layers for classification or regression.
The architecture supports various configurations, including patch-based structures, pooling strategies, and advanced processing features like batch normalization, dropout, and activation functions.
Attributes:
Name | Type | Description |
---|---|---|
h |
int
|
Height of the input grid. |
w |
int
|
Width of the input grid. |
channel_nums |
list[int] | tuple[int]
|
Sequence of channel numbers for each convolutional layer. |
fc_dims |
list[int] | tuple[int]
|
Dimensions of the fully connected layers. |
d |
int
|
Depth of the input grid. Default is 1 (2D input). |
fc_channel_num |
int
|
Number of channels for the fully connected layers. Default is 1. |
width |
int
|
Number of parallel heads for each grid interdependence layer. Default is 1. |
pooling_metric |
str
|
Pooling metric used in pooling layers (e.g., 'batch_max'). Default is 'batch_max'. |
pooling_layer_gaps |
int
|
Number of layers before adding a pooling layer. Default is 2. |
patch_size_half_after_pooling |
bool
|
If True, reduces patch size by half after pooling. Default is False. |
patch_shape |
str
|
Shape of the patches ('cuboid', 'cylinder', or 'sphere'). Default is 'cuboid'. |
with_batch_norm |
bool
|
If True, applies batch normalization. Default is True. |
with_relu |
bool
|
If True, applies ReLU activation. Default is True. |
with_softmax |
bool
|
If True, applies softmax activation to the final output. Default is False. |
with_residual |
bool
|
If True, includes residual connections. Default is False. |
with_dropout |
bool
|
If True, applies dropout. Default is True. |
device |
str
|
Device for computation ('cpu' or 'cuda'). Default is 'cpu'. |
Methods:
Name | Description |
---|---|
__init__ |
Initializes the CNN with grid-based convolutional layers, pooling layers, and fully connected layers. |
Source code in tinybig/model/rpn_cnn.py
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 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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
|
__init__(h, w, channel_nums, fc_dims, d=1, fc_channel_num=1, width=1, pooling_metric='batch_max', pooling_layer_gaps=2, patch_size_half_after_pooling=False, name='rpn_cnn', patch_shape='cuboid', p_h=None, p_h_prime=None, p_w=None, p_w_prime=None, p_d=0, p_d_prime=None, p_r=None, cd_h=None, cd_w=None, cd_d=1, packing_strategy='densest_packing', pooling_patch_shape=None, pooling_p_h=None, pooling_p_h_prime=None, pooling_p_w=None, pooling_p_w_prime=None, pooling_p_d=None, pooling_p_d_prime=None, pooling_p_r=None, pooling_cd_h=None, pooling_cd_w=None, pooling_cd_d=None, pooling_packing_strategy=None, with_batch_norm=True, with_relu=True, with_softmax=False, with_residual=False, with_dropout=True, p_pooling=0.25, p_fc=0.5, with_dual_lphm=False, with_lorr=False, r=3, enable_bias=True, with_perceptron_residual=None, with_perceptron_dual_lphm=None, with_perceptron_lorr=None, perceptron_r=None, enable_perceptron_bias=None, device='cpu', *args, **kwargs)
Initializes the CNN (Convolutional Neural Network) model.
This method constructs the CNN architecture with configurable convolutional layers, optional pooling layers, and fully connected perceptron layers. Various processing features like batch normalization, dropout, and residual connections can also be enabled.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
h
|
int
|
Height of the input grid. |
required |
w
|
int
|
Width of the input grid. |
required |
channel_nums
|
list[int] | tuple[int]
|
Sequence of channel numbers for each convolutional layer. |
required |
fc_dims
|
list[int] | tuple[int]
|
Dimensions of the fully connected layers. |
required |
d
|
int
|
Depth of the input grid. Default is 1 (2D input). |
1
|
fc_channel_num
|
int
|
Number of channels for the fully connected layers. Default is 1. |
1
|
width
|
int
|
Number of parallel heads for each grid interdependence layer. Default is 1. |
1
|
pooling_metric
|
str
|
Pooling metric used in pooling layers (e.g., 'batch_max'). Default is 'batch_max'. |
'batch_max'
|
pooling_layer_gaps
|
int
|
Number of layers before adding a pooling layer. Default is 2. |
2
|
patch_size_half_after_pooling
|
bool
|
If True, reduces patch size by half after pooling. Default is False. |
False
|
name
|
str
|
Name of the CNN model. Default is 'rpn_cnn'. |
'rpn_cnn'
|
patch_shape
|
str
|
Shape of the patches ('cuboid', 'cylinder', or 'sphere'). Default is 'cuboid'. |
'cuboid'
|
p_h
|
int
|
Height and height prime of the patches. Default is None. |
None
|
p_h_prime
|
int
|
Height and height prime of the patches. Default is None. |
None
|
p_w
|
int
|
Width and width prime of the patches. Default is None. |
None
|
p_w_prime
|
int
|
Width and width prime of the patches. Default is None. |
None
|
p_d
|
int
|
Depth and depth prime of the patches. Default is 0 and None, respectively. |
0
|
p_d_prime
|
int
|
Depth and depth prime of the patches. Default is 0 and None, respectively. |
0
|
p_r
|
int
|
Radius of spherical or cylindrical patches. Default is None. |
None
|
cd_h
|
int
|
Compression dimensions for height, width, and depth, respectively. Default is 1. |
None
|
cd_w
|
int
|
Compression dimensions for height, width, and depth, respectively. Default is 1. |
None
|
cd_d
|
int
|
Compression dimensions for height, width, and depth, respectively. Default is 1. |
None
|
packing_strategy
|
str
|
Strategy for patch packing. Default is 'densest_packing'. |
'densest_packing'
|
pooling_patch_shape
|
str
|
Shape of pooling patches. Default is None (same as |
None
|
pooling_p_h
|
int
|
Height and height prime of pooling patches. Default is None. |
None
|
pooling_p_h_prime
|
int
|
Height and height prime of pooling patches. Default is None. |
None
|
pooling_p_w
|
int
|
Width and width prime of pooling patches. Default is None. |
None
|
pooling_p_w_prime
|
int
|
Width and width prime of pooling patches. Default is None. |
None
|
pooling_p_d
|
int
|
Depth and depth prime of pooling patches. Default is None. |
None
|
pooling_p_d_prime
|
int
|
Depth and depth prime of pooling patches. Default is None. |
None
|
pooling_p_r
|
int
|
Radius of pooling patches. Default is None. |
None
|
pooling_cd_h
|
int
|
Compression dimensions for pooling patches. Default is None. |
None
|
pooling_cd_w
|
int
|
Compression dimensions for pooling patches. Default is None. |
None
|
pooling_cd_d
|
int
|
Compression dimensions for pooling patches. Default is None. |
None
|
pooling_packing_strategy
|
str
|
Packing strategy for pooling patches. Default is None (same as |
None
|
with_batch_norm
|
bool
|
If True, applies batch normalization. Default is True. |
True
|
with_relu
|
bool
|
If True, applies ReLU activation. Default is True. |
True
|
with_softmax
|
bool
|
If True, applies softmax activation to the final output. Default is False. |
False
|
with_residual
|
bool
|
If True, includes residual connections. Default is False. |
False
|
with_dropout
|
bool
|
If True, applies dropout. Default is True. |
True
|
p_pooling
|
float
|
Dropout probability for pooling layers. Default is 0.25. |
0.25
|
p_fc
|
float
|
Dropout probability for fully connected layers. Default is 0.5. |
0.5
|
with_dual_lphm
|
bool
|
If True, enables dual low-parametric high-order interdependence. Default is False. |
False
|
with_lorr
|
bool
|
If True, enables low-rank parameterized interdependence. Default is False. |
False
|
r
|
int
|
Rank parameter for low-rank interdependence. Default is 3. |
3
|
enable_bias
|
bool
|
If True, includes bias in the layers. Default is True. |
True
|
with_perceptron_residual
|
bool
|
If True, includes residual connections in perceptron layers. Default is None (inherits from |
None
|
with_perceptron_dual_lphm
|
bool
|
If True, enables dual low-parametric high-order interdependence in perceptron layers. Default is None. |
None
|
with_perceptron_lorr
|
bool
|
If True, enables low-rank parameterized interdependence in perceptron layers. Default is None. |
None
|
perceptron_r
|
int
|
Rank parameter for perceptron layers. Default is None. |
None
|
enable_perceptron_bias
|
bool
|
If True, includes bias in perceptron layers. Default is None. |
None
|
device
|
str
|
Device for computation ('cpu' or 'cuda'). Default is 'cpu'. |
'cpu'
|
*args
|
optional
|
Additional positional arguments for layers. |
()
|
**kwargs
|
optional
|
Additional keyword arguments for layers. |
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
If input dimensions are invalid or improperly configured. |
Source code in tinybig/model/rpn_cnn.py
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 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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
|