Skip to content

Commit 4b673d9

Browse files
committed
Rename the key of the pyramid outputs in DINOV2.
1 parent 931663a commit 4b673d9

File tree

6 files changed

+7
-8
lines changed

6 files changed

+7
-8
lines changed

keras_hub/src/models/depth_anything/depth_anything_backbone_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def setUp(self):
2929
"fusion_hidden_dim": 128,
3030
"head_hidden_dim": 16,
3131
"head_in_index": -1,
32-
"feature_keys": ["Stage1", "Stage2", "Stage3", "Stage4"],
32+
"feature_keys": ["stage1", "stage2", "stage3", "stage4"],
3333
}
3434
self.input_data = np.ones((2, 70, 70, 3), dtype="float32")
3535

keras_hub/src/models/depth_anything/depth_anything_depth_estimator_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def setUp(self):
4343
fusion_hidden_dim=128,
4444
head_hidden_dim=16,
4545
head_in_index=-1,
46-
feature_keys=["Stage1", "Stage2", "Stage3", "Stage4"],
46+
feature_keys=["stage1", "stage2", "stage3", "stage4"],
4747
)
4848
self.init_kwargs = {
4949
"backbone": self.backbone,

keras_hub/src/models/dinov2/dinov2_backbone.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def __init__(
196196
pyramid_outputs = {}
197197
image_input = layers.Input(shape=image_shape, name="images")
198198
x = self.embeddings(image_input)
199-
pyramid_outputs["Stem"] = x
199+
pyramid_outputs["stem"] = x
200200
x, encoder_pyramid_outputs = self.encoder(x)
201201
pyramid_outputs.update(encoder_pyramid_outputs)
202202
x = self.layernorm(x)

keras_hub/src/models/dinov2/dinov2_backbone_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_backbone_basics(self):
3636
init_kwargs=self.init_kwargs,
3737
input_data=self.input_data,
3838
expected_output_shape=(2, sequence_length, hidden_dim),
39-
expected_pyramid_output_keys=["Stem", "Stage1", "Stage2"],
39+
expected_pyramid_output_keys=["stem", "stage1", "stage2"],
4040
expected_pyramid_image_sizes=[(sequence_length, hidden_dim)] * 3,
4141
run_data_format_check=False,
4242
)
@@ -131,7 +131,7 @@ def test_backbone_basics(self):
131131
init_kwargs=self.init_kwargs,
132132
input_data=self.input_data,
133133
expected_output_shape=(2, sequence_length, hidden_dim),
134-
expected_pyramid_output_keys=["Stem", "Stage1", "Stage2"],
134+
expected_pyramid_output_keys=["stem", "stage1", "stage2"],
135135
expected_pyramid_image_sizes=[(sequence_length, hidden_dim)] * 3,
136136
run_data_format_check=False,
137137
)

keras_hub/src/models/dinov2/dinov2_layers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ def call(self, inputs, training=None):
870870
x = inputs
871871
for layer_index, layer in enumerate(self.layers, start=1):
872872
x = layer(x, training=training)
873-
pyramid_outputs[f"Stage{str(layer_index)}"] = x
873+
pyramid_outputs[f"stage{str(layer_index)}"] = x
874874
return x, pyramid_outputs
875875

876876
def get_config(self):
@@ -892,5 +892,5 @@ def get_config(self):
892892
def compute_output_shape(self, input_shape):
893893
pyramid_outputs = {}
894894
for layer_index in range(1, len(self.layers) + 1):
895-
pyramid_outputs[f"Stage{str(layer_index)}"] = input_shape
895+
pyramid_outputs[f"stage{str(layer_index)}"] = input_shape
896896
return input_shape, pyramid_outputs

tools/checkpoint_conversion/convert_depth_anything_checkpoints.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ def convert_model(hf_model, dtype=None):
6464
model_config = hf_model.config.to_dict()
6565
# In KerasHub, the stage names are capitalized.
6666
feature_keys = model_config["backbone_config"]["out_features"]
67-
feature_keys = [key.replace("stage", "Stage") for key in feature_keys]
6867
assert model_config["depth_estimation_type"] == "relative"
6968
assert model_config["max_depth"] in (None, 1.0)
7069
return DepthAnythingBackbone(

0 commit comments

Comments
 (0)