2D Models
k3im.cait.CAiTModel
Create a Class-Attention in Image Transformer (CaiT) model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
`image_size` |
tuple of (height, width) of the image |
required | |
`patch_size` |
tuple of (height, width) of the patch |
required | |
`num_classes` |
output classes for classification |
required | |
`dim` |
dimension of the model |
required | |
`depth` |
depth of the model |
required | |
`heads` |
number of heads in the model |
required | |
`mlp_dim` |
dimension of the mlp |
required | |
`cls_depth` |
depth of the cls token |
required | |
`channels` |
number of channels in the image |
required | |
`dim_head` |
dimension of the head |
required | |
`aug` |
augmentation layer |
required |
Source code in k3im/cait.py
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 |
|
k3im.cct.CCT
Instantiates the Compact Convolutional Transformer architecture.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_shape |
tuple of (height, width, channels) |
required | |
num_heads |
number of attention heads |
required | |
projection_dim |
projection dimension |
required | |
kernel_size |
kernel size for the first convolutional layer |
required | |
stride |
stride for the first convolutional layer |
required | |
padding |
padding for the first convolutional layer |
required | |
transformer_units |
list of units for the transformer blocks |
required | |
stochastic_depth_rate |
dropout rate for the stochastic depth |
required | |
transformer_layers |
number of transformer blocks |
required | |
num_classes |
number of output classes |
required | |
positional_emb |
boolean, whether to use positional embeddings |
False
|
|
aug |
data augmentation |
None
|
Source code in k3im/cct.py
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 |
|
k3im.convmixer.ConvMixer
Instantiates the ConvMixer architecture.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image_size |
Input image size. |
32
|
|
filters |
Number of filters. |
256
|
|
depth |
Depth of the network. |
8
|
|
kernel_size |
Kernel size. |
5
|
|
patch_size |
Patch size. |
2
|
|
num_classes |
Number of classes. |
10
|
|
num_channels |
Number of input channels. |
3
|
|
aug |
Augmentation layer. |
None
|
Source code in k3im/convmixer.py
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 |
|
k3im.eanet.EANet
Instantiates the EANet architecture.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_shape |
tuple of (height, width, channels) |
required | |
patch_size |
size of the patch |
required | |
embedding_dim |
dimension of the embedding |
required | |
num_transformer_blocks |
number of transformer blocks |
required | |
mlp_dim |
dimension of the mlp |
required | |
num_heads |
number of heads |
required | |
dim_coefficient |
dimension coefficient |
required | |
attention_dropout |
dropout rate for attention |
required | |
projection_dropout |
dropout rate for projection |
required | |
num_classes |
number of classes |
required | |
aug |
augmentation layer |
None
|
Source code in k3im/eanet.py
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 |
|
k3im.fnet.FNet
Instantiates the FNet architecture.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image_size |
Image size. |
required | |
patch_size |
Patch size. |
required | |
embedding_dim |
Size of the embedding dimension. |
required | |
num_blocks |
Number of blocks. |
required | |
dropout_rate |
Dropout rate. |
required | |
num_classes |
Number of classes to classify images into. |
required | |
positional_encoding |
Whether to include positional encoding. |
False
|
|
num_channels |
Number of image channels. |
3
|
|
aug |
Image augmentation. |
None
|
Source code in k3im/fnet.py
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 |
|
k3im.focalnet.FNet
Instantiates the FocalNet architecture.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img_size |
Image size. |
224
|
|
patch_size |
Patch size. |
4
|
|
num_classes |
Number of classes. |
1000
|
|
embed_dim |
Embedding dimension. |
128
|
|
depths |
Depths of each stage. |
[2, 2, 6, 2]
|
|
mlp_ratio |
Ratio of mlp hidden dim to embedding dim. |
4.0
|
|
drop_rate |
Dropout rate. |
0.0
|
|
drop_path_rate |
Stochastic depth rate. |
0.1
|
|
norm_layer |
Normalization layer. |
LayerNormalization
|
|
patch_norm |
Whether to use patch norm. |
True
|
|
focal_levels |
Number of focal levels. |
[2, 2, 3, 2]
|
|
focal_windows |
Focal window sizes. |
[3, 2, 3, 2]
|
|
use_conv_embed |
Whether to use conv embed. |
False
|
|
use_layerscale |
Whether to use layer scale. |
False
|
|
layerscale_value |
Value for layer scale. |
0.0001
|
|
use_postln |
Whether to use post layer norm. |
False
|
|
use_postln_in_modulation |
Whether to use post layer norm in modulation. |
False
|
|
normalize_modulator |
Whether to normalize modulator. |
False
|
Source code in k3im/focalnet.py
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 |
|
k3im.focalnet.FocalNetModel
Instantiates the FocalNet architecture.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img_size |
Image size. |
required | |
in_channels |
Number of input channels. |
3
|
|
aug |
Augmentation layer. |
None
|
|
**kw |
Other keyword arguments. |
{}
|
Source code in k3im/focalnet.py
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 |
|
k3im.focalnet.focalnet_tiny_srf
FocalNet-Tiny-SRF model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img_size |
Image size. |
224
|
|
**kwargs |
Other keyword arguments. |
{}
|
Source code in k3im/focalnet.py
500 501 502 503 504 505 506 507 508 |
|
k3im.focalnet.focalnet_small_srf
FocalNet-Small-SRF model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img_size |
Image size. |
224
|
|
**kwargs |
Other keyword arguments. |
{}
|
Source code in k3im/focalnet.py
511 512 513 514 515 516 517 518 519 |
|
k3im.focalnet.focalnet_base_srf
FocalNet-Base-SRF model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img_size |
Image size. |
224
|
|
**kwargs |
Other keyword arguments. |
{}
|
Source code in k3im/focalnet.py
522 523 524 525 526 527 528 529 530 |
|
k3im.focalnet.focalnet_tiny_lrf
FocalNet-Tiny-LRF model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img_size |
Image size. |
224
|
|
**kwargs |
Other keyword arguments. |
{}
|
Source code in k3im/focalnet.py
533 534 535 536 537 538 539 540 541 542 543 |
|
k3im.focalnet.focalnet_small_lrf
FocalNet-Small-LRF model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img_size |
Image size. |
224
|
|
**kwargs |
Other keyword arguments. |
{}
|
Source code in k3im/focalnet.py
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 |
|
k3im.focalnet.focalnet_base_lrf
FocalNet-Base-LRF model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img_size |
Image size. |
224
|
|
**kwargs |
Other keyword arguments. |
{}
|
Source code in k3im/focalnet.py
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 |
|
k3im.focalnet.focalnet_tiny_iso_16
FocalNet-Tiny-ISO-16 model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img_size |
Image size. |
224
|
|
**kwargs |
Other keyword arguments. |
{}
|
Source code in k3im/focalnet.py
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 |
|
k3im.focalnet.focalnet_small_iso_16
FocalNet-Small-ISO-16 model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img_size |
Image size. |
224
|
|
**kwargs |
Other keyword arguments. |
{}
|
Source code in k3im/focalnet.py
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 |
|
k3im.focalnet.focalnet_base_iso_16
FocalNet-Base-ISO-16 model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img_size |
Image size. |
224
|
|
**kwargs |
Other keyword arguments. |
{}
|
Source code in k3im/focalnet.py
623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 |
|
k3im.focalnet.gMLP
Instantiates the gMLP architecture.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image_size |
Image size. |
required | |
patch_size |
Patch size. |
required | |
embedding_dim |
Size of the embedding dimension. |
required | |
num_blocks |
Number of blocks. |
required | |
dropout_rate |
Dropout rate. |
required | |
num_classes |
Number of classes to classify images into. |
required | |
positional_encoding |
Whether to include positional encoding. |
False
|
|
num_channels |
Number of image channels. |
3
|
|
aug |
Image augmentation. |
None
|
Source code in k3im/gmlp.py
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 |
|
k3im.mlp_mixer.MlpMixer
MLP-Mixer
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_classes |
number of classes for classification head |
1000
|
|
img_size |
input image size |
224
|
|
in_chans |
number of input channels |
3
|
|
patch_size |
patch size |
16
|
|
num_blocks |
number of blocks |
8
|
|
embed_dim |
embedding dimension |
512
|
|
mlp_ratio |
ratio of mlp hidden dim to embedding dim |
(0.5, 4.0)
|
|
block_layer |
block layer type (e.g. MixerBlock, ResMLPBlock, ConvMLPBlock) |
MixerBlock
|
|
mlp_layer |
mlp layer type (e.g. Mlp, ConvMlp) |
Mlp
|
|
norm_layer |
normalization layer type (default: partial(layers.LayerNormalization, epsilon=1e-6)) |
partial(LayerNormalization, epsilon=1e-06)
|
|
act_layer |
activation layer type (default: keras.activations.gelu) |
gelu
|
|
drop_rate |
dropout rate |
0.0
|
|
proj_drop_rate |
stochastic depth rate for projection |
0.0
|
|
drop_path_rate |
stochastic depth rate for block layers |
0.0
|
|
stem_norm |
whether to apply normalization to stem |
False
|
|
global_pool |
global pooling type, one of 'avg', 'max' or None |
'avg'
|
Source code in k3im/mlp_mixer.py
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 |
|
k3im.simple_vit.SimpleViT
Create a Simple Vision Transformer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
`image_size` |
tuple of (height, width) of the image |
required | |
`patch_size` |
tuple of (height, width) of the patch |
required | |
`num_classes` |
output classes for classification |
required | |
`dim` |
dimension of the model |
required | |
`depth` |
depth of the model |
required | |
`heads` |
number of heads in the model |
required | |
`mlp_dim` |
dimension of the mlp |
required | |
`channels` |
number of channels in the image |
required | |
`dim_head` |
dimension of the head |
required | |
`pool` |
pooling type, one of ( |
required | |
`aug` |
augmentation layer |
required |
Source code in k3im/simple_vit.py
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 |
|
k3im.vit.ViT
Create a Vision Transformer for 2D data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
`image_size` |
tuple of ints (height, width) specifying the image dimensions |
required | |
`patch_size` |
tuple of ints (height, width) specifying the patch dimensions |
required | |
`num_classes` |
number of classes |
required | |
`dim` |
dimension of the transformer |
required | |
`depth` |
number of transformer layers |
required | |
`heads` |
number of attention heads |
required | |
`mlp_dim` |
dimension of the mlp |
required | |
`channels` |
number of channels in the input image |
required | |
`dim_head` |
dimension of the head |
required | |
`pool` |
type of pooling at the end of the network |
required | |
`aug` |
augmentation layer |
required |
Source code in k3im/vit.py
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 |
|