Skip to content

Commit

Permalink
Add backbone_hidden_size
Browse files Browse the repository at this point in the history
  • Loading branch information
NielsRogge committed Apr 20, 2024
1 parent ff70bff commit 75a8ccb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/transformers/models/zoedepth/configuration_zoedepth.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class ZoeDepthConfig(PretrainedConfig):
- "project" passes information to the other tokens by concatenating the readout to all other tokens before
projecting the
representation to the original feature dimension D using a linear layer followed by a GELU non-linearity.
backbone_hidden_size (`int`, *optional*, defaults to 1024):
The hidden size of the backbone.
reassemble_factors (`List[int]`, *optional*, defaults to `[4, 2, 1, 0.5]`):
The up/downsampling factors of the reassemble layers.
neck_hidden_sizes (`List[str]`, *optional*, defaults to `[96, 192, 384, 768]`):
Expand Down Expand Up @@ -133,6 +135,7 @@ def __init__(
hidden_act="gelu",
initializer_range=0.02,
readout_type="project",
backbone_hidden_size=1024,
reassemble_factors=[4, 2, 1, 0.5],
neck_hidden_sizes=[96, 192, 384, 768],
fusion_hidden_size=256,
Expand Down Expand Up @@ -198,6 +201,7 @@ def __init__(
self.hidden_act = hidden_act
self.use_pretrained_backbone = use_pretrained_backbone
self.initializer_range = initializer_range
self.backbone_hidden_size = backbone_hidden_size
self.readout_type = readout_type
self.reassemble_factors = reassemble_factors
self.neck_hidden_sizes = neck_hidden_sizes
Expand Down
6 changes: 3 additions & 3 deletions src/transformers/models/zoedepth/modeling_zoedepth.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def __init__(self, config):

if config.readout_type == "project":
self.readout_projects = nn.ModuleList()
hidden_size = config.backbone_config.hidden_size
hidden_size = config.backbone_hidden_size
for _ in range(len(config.neck_hidden_sizes)):
self.readout_projects.append(
nn.Sequential(nn.Linear(2 * hidden_size, hidden_size), ACT2FN[config.hidden_act])
Expand Down Expand Up @@ -156,7 +156,7 @@ class ZoeDepthReassembleLayer(nn.Module):
def __init__(self, config, channels, factor):
super().__init__()
# projection
hidden_size = config.backbone_config.hidden_size
hidden_size = config.backbone_hidden_size
self.projection = nn.Conv2d(in_channels=hidden_size, out_channels=channels, kernel_size=1)

# up/down sampling depending on factor
Expand Down Expand Up @@ -1302,7 +1302,7 @@ def forward(
hidden_states = outputs.feature_maps

_, _, height, width = pixel_values.shape
patch_size = self.config.backbone_config.patch_size
patch_size = self.backbone.config.patch_size
patch_height = height // patch_size
patch_width = width // patch_size

Expand Down
3 changes: 3 additions & 0 deletions tests/models/zoedepth/test_modeling_zoedepth.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def __init__(
out_features=["stage1", "stage2"],
apply_layernorm=False,
reshape_hidden_states=False,
backbone_hidden_size=4,
neck_hidden_sizes=[2, 2],
fusion_hidden_size=6,
bottleneck_features=6,
Expand All @@ -76,6 +77,7 @@ def __init__(
self.use_labels = use_labels
self.num_labels = num_labels
self.is_training = is_training
self.backbone_hidden_size = backbone_hidden_size
self.neck_hidden_sizes = neck_hidden_sizes
self.fusion_hidden_size = fusion_hidden_size
self.bottleneck_features = bottleneck_features
Expand All @@ -98,6 +100,7 @@ def get_config(self):
return ZoeDepthConfig(
backbone_config=self.get_backbone_config(),
backbone=None,
backbone_hidden_size=self.backbone_hidden_size,
neck_hidden_sizes=self.neck_hidden_sizes,
fusion_hidden_size=self.fusion_hidden_size,
bottleneck_features=self.bottleneck_features,
Expand Down

0 comments on commit 75a8ccb

Please sign in to comment.