|
6 | 6 |
|
7 | 7 |
|
8 | 8 | class DepthAnythingTokenToImage(layers.Layer):
|
| 9 | + """A layer that converts tokens into images. |
| 10 | +
|
| 11 | + Args: |
| 12 | + hidden_dim: int. The number of units in the hidden layers. |
| 13 | + patch_height: int. The height of each patch. |
| 14 | + patch_width: int. The width of each patch. |
| 15 | + num_cls_tokens: int. The number of class tokens at the beginning of |
| 16 | + the sequence. Defaults to `1`. |
| 17 | + num_register_tokens: int. The number of register tokens after the |
| 18 | + class tokens. Defaults to `0`. |
| 19 | + data_format: `None` or str. If specified, either `"channels_last"` or |
| 20 | + `"channels_first"`. The ordering of the dimensions in the |
| 21 | + inputs. `"channels_last"` corresponds to inputs with shape |
| 22 | + `(batch_size, height, width, channels)` |
| 23 | + while `"channels_first"` corresponds to inputs with shape |
| 24 | + `(batch_size, channels, height, width)`. It defaults to the |
| 25 | + `image_data_format` value found in your Keras config file at |
| 26 | + `~/.keras/keras.json`. If you never set it, then it will be |
| 27 | + `"channels_last"`. |
| 28 | + **kwargs: other keyword arguments passed to `keras.layers.Layer`, |
| 29 | + including `name`, `dtype` etc. |
| 30 | + """ |
| 31 | + |
9 | 32 | def __init__(
|
10 | 33 | self,
|
11 | 34 | hidden_dim,
|
@@ -65,6 +88,26 @@ def compute_output_shape(self, input_shape):
|
65 | 88 |
|
66 | 89 |
|
67 | 90 | class DepthAnythingReassembleLayer(layers.Layer):
|
| 91 | + """A layer that resizes the input images. |
| 92 | +
|
| 93 | + Args: |
| 94 | + hidden_dim: int. The number of units in the hidden layers. |
| 95 | + factor: float. The resizing factor. If `factor > 1`, the layer upsamples |
| 96 | + the input. If `factor < 1`, the layer downsamples the input. If |
| 97 | + `factor == 1`, the layer only applies a linear projection. |
| 98 | + data_format: `None` or str. If specified, either `"channels_last"` or |
| 99 | + `"channels_first"`. The ordering of the dimensions in the |
| 100 | + inputs. `"channels_last"` corresponds to inputs with shape |
| 101 | + `(batch_size, height, width, channels)` |
| 102 | + while `"channels_first"` corresponds to inputs with shape |
| 103 | + `(batch_size, channels, height, width)`. It defaults to the |
| 104 | + `image_data_format` value found in your Keras config file at |
| 105 | + `~/.keras/keras.json`. If you never set it, then it will be |
| 106 | + `"channels_last"`. |
| 107 | + **kwargs: other keyword arguments passed to `keras.layers.Layer`, |
| 108 | + including `name`, `dtype` etc. |
| 109 | + """ |
| 110 | + |
68 | 111 | def __init__(self, hidden_dim, factor, data_format=None, **kwargs):
|
69 | 112 | super().__init__(**kwargs)
|
70 | 113 | self.hidden_dim = int(hidden_dim)
|
@@ -152,6 +195,23 @@ def compute_output_shape(self, input_shape):
|
152 | 195 |
|
153 | 196 |
|
154 | 197 | class DepthAnythingPreActResidualLayer(layers.Layer):
|
| 198 | + """A ReLU + Conv2D layer. |
| 199 | +
|
| 200 | + Args: |
| 201 | + hidden_dim: int. The number of units in the hidden layers. |
| 202 | + data_format: `None` or str. If specified, either `"channels_last"` or |
| 203 | + `"channels_first"`. The ordering of the dimensions in the |
| 204 | + inputs. `"channels_last"` corresponds to inputs with shape |
| 205 | + `(batch_size, height, width, channels)` |
| 206 | + while `"channels_first"` corresponds to inputs with shape |
| 207 | + `(batch_size, channels, height, width)`. It defaults to the |
| 208 | + `image_data_format` value found in your Keras config file at |
| 209 | + `~/.keras/keras.json`. If you never set it, then it will be |
| 210 | + `"channels_last"`. |
| 211 | + **kwargs: other keyword arguments passed to `keras.layers.Layer`, |
| 212 | + including `name`, `dtype` etc. |
| 213 | + """ |
| 214 | + |
155 | 215 | def __init__(self, hidden_dim, data_format=None, **kwargs):
|
156 | 216 | super().__init__(**kwargs)
|
157 | 217 | self.hidden_dim = int(hidden_dim)
|
@@ -229,6 +289,24 @@ def compute_output_shape(self, input_shape):
|
229 | 289 |
|
230 | 290 |
|
231 | 291 | class DepthAnythingFeatureFusionLayer(layers.Layer):
|
| 292 | + """A layer that fuses the incoming features. |
| 293 | +
|
| 294 | + Args: |
| 295 | + hidden_dim: int. The number of units in the hidden layers. |
| 296 | + size: tuple of int. The target size of the output feature map. |
| 297 | + data_format: `None` or str. If specified, either `"channels_last"` or |
| 298 | + `"channels_first"`. The ordering of the dimensions in the |
| 299 | + inputs. `"channels_last"` corresponds to inputs with shape |
| 300 | + `(batch_size, height, width, channels)` |
| 301 | + while `"channels_first"` corresponds to inputs with shape |
| 302 | + `(batch_size, channels, height, width)`. It defaults to the |
| 303 | + `image_data_format` value found in your Keras config file at |
| 304 | + `~/.keras/keras.json`. If you never set it, then it will be |
| 305 | + `"channels_last"`. |
| 306 | + **kwargs: other keyword arguments passed to `keras.layers.Layer`, |
| 307 | + including `name`, `dtype` etc. |
| 308 | + """ |
| 309 | + |
232 | 310 | def __init__(self, hidden_dim, size, data_format=None, **kwargs):
|
233 | 311 | super().__init__(**kwargs)
|
234 | 312 | self.hidden_dim = int(hidden_dim)
|
@@ -301,6 +379,33 @@ def compute_output_shape(self, input_shape):
|
301 | 379 |
|
302 | 380 |
|
303 | 381 | class DepthAnythingNeck(layers.Layer):
|
| 382 | + """A DepthAnything neck layer. |
| 383 | +
|
| 384 | + Args: |
| 385 | + patch_size: int. The size of one side of each patch. |
| 386 | + image_size: tuple of ints. The (height, width) of the input images. |
| 387 | + backbone_hidden_dim: int. The number of units in the backbone layers. |
| 388 | + neck_hidden_dims: List of int. The number of units in each neck layer. |
| 389 | + reassemble_factors: List of float. The resizing factor in each neck |
| 390 | + layer. |
| 391 | + fusion_hidden_dim: int. The number of units in the fusion layers. |
| 392 | + num_cls_tokens: int. The number of class tokens at the beginning of |
| 393 | + the sequence. Defaults to `1`. |
| 394 | + num_register_tokens: int. The number of register tokens after the |
| 395 | + class tokens. Defaults to `0`. |
| 396 | + data_format: `None` or str. If specified, either `"channels_last"` or |
| 397 | + `"channels_first"`. The ordering of the dimensions in the |
| 398 | + inputs. `"channels_last"` corresponds to inputs with shape |
| 399 | + `(batch_size, height, width, channels)` |
| 400 | + while `"channels_first"` corresponds to inputs with shape |
| 401 | + `(batch_size, channels, height, width)`. It defaults to the |
| 402 | + `image_data_format` value found in your Keras config file at |
| 403 | + `~/.keras/keras.json`. If you never set it, then it will be |
| 404 | + `"channels_last"`. |
| 405 | + **kwargs: other keyword arguments passed to `keras.layers.Layer`, |
| 406 | + including `name`, `dtype` etc. |
| 407 | + """ |
| 408 | + |
304 | 409 | def __init__(
|
305 | 410 | self,
|
306 | 411 | patch_size,
|
@@ -464,6 +569,30 @@ def get_config(self):
|
464 | 569 |
|
465 | 570 |
|
466 | 571 | class DepthAnythingDepthEstimationHead(layers.Layer):
|
| 572 | + """A DepthAnything neck layer. |
| 573 | +
|
| 574 | + Args: |
| 575 | + patch_size: int. The size of one side of each patch. |
| 576 | + patch_height: int. The height of each patch. |
| 577 | + patch_width: int. The width of each patch. |
| 578 | + hidden_dim: int. The number of units in the hidden layers. |
| 579 | + fusion_hidden_dim: int. The number of units in the fusion layers. |
| 580 | + head_hidden_dim: int. The number of units in the head layers. |
| 581 | + head_in_index: int. The index of the feature map to be used as input |
| 582 | + to the head. |
| 583 | + data_format: `None` or str. If specified, either `"channels_last"` or |
| 584 | + `"channels_first"`. The ordering of the dimensions in the |
| 585 | + inputs. `"channels_last"` corresponds to inputs with shape |
| 586 | + `(batch_size, height, width, channels)` |
| 587 | + while `"channels_first"` corresponds to inputs with shape |
| 588 | + `(batch_size, channels, height, width)`. It defaults to the |
| 589 | + `image_data_format` value found in your Keras config file at |
| 590 | + `~/.keras/keras.json`. If you never set it, then it will be |
| 591 | + `"channels_last"`. |
| 592 | + **kwargs: other keyword arguments passed to `keras.layers.Layer`, |
| 593 | + including `name`, `dtype` etc. |
| 594 | + """ |
| 595 | + |
467 | 596 | def __init__(
|
468 | 597 | self,
|
469 | 598 | patch_size,
|
|
0 commit comments