rslearn.models.swin¶
swin ¶
Swin Transformer.
Swin ¶
Bases: FeatureExtractor
A Swin Transformer model.
It can either be used stand-alone for classification, or as a feature extractor in combination with other decoder modules.
Source code in rslearn/models/swin.py
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 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 | |
get_backbone_channels ¶
Returns the output channels of this model when used as a backbone.
The output channels is a list of (downsample_factor, depth) that corresponds to the feature maps that the backbone returns. For example, an element [2, 32] indicates that the corresponding feature map is 1/2 the input resolution and has 32 channels.
Returns:
| Type | Description |
|---|---|
list[tuple[int, int]]
|
the output channels of the backbone as a list of (downsample_factor, depth) |
list[tuple[int, int]]
|
tuples. |
Source code in rslearn/models/swin.py
forward ¶
forward(context: ModelContext) -> FeatureVector | FeatureMaps
Compute outputs from the backbone.
If output_layers is set, then the outputs are multi-scale feature maps; otherwise, the model is being used for classification so the outputs are class probabilities and the loss.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
ModelContext
|
the model context. Input dicts must include "image" key containing the image to process. |
required |
Returns:
| Type | Description |
|---|---|
FeatureVector | FeatureMaps
|
a FeatureVector if the configured output_layers is None, or a FeatureMaps otherwise containing one feature map per configured output layer. |