StreamingModule
Bases: LightningModule
Source code in lightstream\modules\streaming.py
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 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 |
|
backward_streaming(image, gradient)
Perform the backward pass using the streaming network
Backward only if streaming is turned on. This method is primarily a convenience function
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image |
The input image in [1,C,H,W] format |
required | |
gradient |
The gradient of the next layer in the model to continue backpropagation with |
required |
Source code in lightstream\modules\streaming.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
|
configure_tile_stride()
Helper function that returns the tile stride during streaming.
Streaming assumes that the input image is perfectly divisible with the network output stride or the tile stride. This function will return the tile stride, which can then be used within data processing pipelines to pad/crop images to a multiple of the tile stride.
Examples:
Returns:
Name | Type | Description |
---|---|---|
tile_stride |
ndarray
|
the tile stride. |
Source code in lightstream\modules\streaming.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
|
disable_streaming_hooks()
Disable streaming hooks and replace streamingconv2d with conv2d modules
This will still use the StreamingCNN backward and forward functions, but the memory gains from gradient checkpointing will be turned off.
Source code in lightstream\modules\streaming.py
119 120 121 122 123 124 125 |
|
enable_streaming_hooks()
Enable streaming hooks and use streamingconv2d modules
Source code in lightstream\modules\streaming.py
127 128 129 |
|
forward_streaming(x)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
Tensor
|
|
required |
The |
|
required |
Returns:
Name | Type | Description |
---|---|---|
out |
Tensor
|
|
The output of the streaming model
|
|
Source code in lightstream\modules\streaming.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
|
freeze_streaming_normalization_layers()
Do not use normalization layers within lightstream, only local ops are allowed
Source code in lightstream\modules\streaming.py
47 48 49 50 51 52 53 54 55 56 |
|
get_trainable_params()
Get trainable parameters for the entire model
If self.streaming_layers is True, then the parameters of the streaming network will be trained. Otherwise, the parameters will be left untrained (no gradients will be collected)
Source code in lightstream\modules\streaming.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
|
load_tile_cache_if_needed(use_tile_cache=True)
Load the tile cache for the model from the read_dir
Parameters:
Name | Type | Description | Default |
---|---|---|---|
use_tile_cache |
bool
|
Whether to use the tile cache file and load it into the streaming module |
True
|
Returns:
Name | Type | Description |
---|---|---|
state_dict |
state_dict | None
|
The state dict if present |
Source code in lightstream\modules\streaming.py
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 |
|
on_predict_start()
on_predict_start hook
Do not override this method. Instead, call the parent class using super().on_train_start if you want to add this hook into your pipelines
Source code in lightstream\modules\streaming.py
109 110 111 112 113 114 115 116 |
|
on_test_start()
on_test_start hook
Do not override this method. Instead, call the parent class using super().on_train_start if you want to add this hook into your pipelines
Source code in lightstream\modules\streaming.py
99 100 101 102 103 104 105 106 |
|
on_train_epoch_start()
on_train_epoch_start hook
Do not override this method. Instead, call the parent class using super().on_train_start if you want to add this hook into your pipelines
Source code in lightstream\modules\streaming.py
58 59 60 61 62 63 64 65 |
|
on_train_start()
on_train_start hook
Do not override this method. Instead, call the parent class using super().on_train_start if you want to add this hook into your pipelines
Source code in lightstream\modules\streaming.py
89 90 91 92 93 94 95 96 |
|
on_validation_start()
on_validation_start hook
Do not override this method. Instead, call the parent class using super().on_train_start if you want to add this hook into your pipelines
Source code in lightstream\modules\streaming.py
80 81 82 83 84 85 86 87 |
|
save_tile_cache_if_needed(overwrite=False)
Writes the tile cache to a file, so it does not have to be recomputed
The tile cache is normally calculated for each run. However, this can take a long time. By writing it to a file it can be reloaded without the need for recomputation.
Limitations: This only works for the exact same model and for a single tile size. If the streaming part of the model changes, or if the tile size is changed, it will no longer work.
Source code in lightstream\modules\streaming.py
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 |
|