Skip to content

Commit 931663a

Browse files
committed
Use numpy as the inputs.
1 parent 08e164c commit 931663a

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

keras_hub/src/models/depth_anything/depth_anything_backbone_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import numpy as np
12
import pytest
2-
from keras import ops
33

44
from keras_hub.src.models.depth_anything.depth_anything_backbone import (
55
DepthAnythingBackbone,
@@ -31,7 +31,7 @@ def setUp(self):
3131
"head_in_index": -1,
3232
"feature_keys": ["Stage1", "Stage2", "Stage3", "Stage4"],
3333
}
34-
self.input_data = ops.ones((2, 70, 70, 3))
34+
self.input_data = np.ones((2, 70, 70, 3), dtype="float32")
3535

3636
def test_backbone_basics(self):
3737
self.run_backbone_test(

keras_hub/src/models/depth_anything/depth_anything_depth_estimator_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import numpy as np
12
import pytest
2-
from keras import ops
33

44
from keras_hub.src.models.depth_anything.depth_anything_backbone import (
55
DepthAnythingBackbone,
@@ -30,8 +30,8 @@ def setUp(self):
3030
image_shape=(70, 70, 3),
3131
apply_layernorm=True,
3232
)
33-
self.images = ops.ones((2, 70, 70, 3))
34-
self.depths = ops.zeros((2, 70, 70, 1))
33+
self.images = np.ones((2, 70, 70, 3), dtype="float32")
34+
self.depths = np.zeros((2, 70, 70, 1), dtype="float32")
3535
self.image_converter = DepthAnythingImageConverter(image_size=(70, 70))
3636
self.preprocessor = DepthAnythingDepthEstimatorPreprocessor(
3737
self.image_converter
@@ -82,7 +82,7 @@ def test_saved_model(self):
8282

8383
@pytest.mark.extra_large
8484
def test_all_presets(self):
85-
images = ops.ones((2, 518, 518, 3))
85+
images = np.ones((2, 518, 518, 3), dtype="float32")
8686
for preset in DepthAnythingDepthEstimator.presets:
8787
self.run_preset_test(
8888
cls=DepthAnythingDepthEstimator,

keras_hub/src/models/dinov2/dinov2_layers.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import keras
12
from keras import backend
23
from keras import config
34
from keras import initializers
@@ -276,20 +277,24 @@ def get_config(self):
276277
)
277278
return config
278279

279-
def compute_output_shape(self, input_shape):
280-
output_shape = [input_shape[0], None, self.hidden_dim]
280+
def compute_output_shape(self, inputs_shape):
281+
output_shape = [inputs_shape[0], None, self.hidden_dim]
281282
if self.data_format == "channels_last":
282-
if input_shape[1] is not None and input_shape[2] is not None:
283-
patch_num = input_shape[1] // self.patch_size
283+
if inputs_shape[1] is not None and inputs_shape[2] is not None:
284+
patch_num = inputs_shape[1] // self.patch_size
284285
# 1 is for cls token.
285286
output_shape[1] = 1 + self.num_register_tokens + patch_num**2
286287
else:
287-
if input_shape[2] is not None and input_shape[3] is not None:
288-
patch_num = input_shape[2] // self.patch_size
288+
if inputs_shape[2] is not None and inputs_shape[3] is not None:
289+
patch_num = inputs_shape[2] // self.patch_size
289290
# 1 is for cls token.
290291
output_shape[1] = 1 + self.num_register_tokens + patch_num**2
291292
return output_shape
292293

294+
def compute_output_spec(self, inputs):
295+
output_shape = self.compute_output_shape(inputs.shape)
296+
return keras.KerasTensor(output_shape, dtype=self.compute_dtype)
297+
293298
@staticmethod
294299
def _interpolate_position_embeddings(
295300
position_embeddings,

0 commit comments

Comments
 (0)