Skip to content

Commit

Permalink
Update VITDet to conform to KerasCV scaling standards (#2086)
Browse files Browse the repository at this point in the history
* Update VITDet to conform to KerasCV scaling standards

* dtype fix
  • Loading branch information
ianstenbit authored Sep 22, 2023
1 parent e5cd24a commit 7712a81
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
Binary file modified keras_cv/models/backbones/vit_det/data/vitdet_base_out.npz
Binary file not shown.
8 changes: 7 additions & 1 deletion keras_cv/models/backbones/vit_det/vit_det_backbone.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from keras_cv.api_export import keras_cv_export
from keras_cv.backend import keras
from keras_cv.backend import ops
from keras_cv.layers.vit_det_layers import AddPositionalEmbedding
from keras_cv.layers.vit_det_layers import ViTDetPatchingAndEmbedding
from keras_cv.layers.vit_det_layers import WindowedTransformerEncoder
Expand Down Expand Up @@ -81,9 +82,9 @@ class ViTDetBackbone(Backbone):
def __init__(
self,
*,
include_rescaling,
input_shape=(1024, 1024, 3),
input_tensor=None,
include_rescaling=False,
patch_size=16,
embed_dim=768,
depth=12,
Expand Down Expand Up @@ -123,6 +124,11 @@ def __init__(
# Use common rescaling strategy across keras_cv
x = keras.layers.Rescaling(1.0 / 255.0)(x)

# VITDet scales inputs based on the standard ImageNet mean/stddev.
x = (x - ops.array([0.229, 0.224, 0.225], dtype=x.dtype)) / (
ops.array([0.485, 0.456, 0.406], dtype=x.dtype)
)

x = ViTDetPatchingAndEmbedding(
kernel_size=(patch_size, patch_size),
strides=(patch_size, patch_size),
Expand Down
6 changes: 3 additions & 3 deletions keras_cv/models/backbones/vit_det/vit_det_backbone_presets.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"config": {
"input_shape": (1024, 1024, 3),
"input_tensor": None,
"include_rescaling": False,
"include_rescaling": True,
"patch_size": 16,
"embed_dim": 768,
"depth": 12,
Expand Down Expand Up @@ -61,7 +61,7 @@
"config": {
"input_shape": (1024, 1024, 3),
"input_tensor": None,
"include_rescaling": False,
"include_rescaling": True,
"patch_size": 16,
"embed_dim": 1024,
"depth": 24,
Expand Down Expand Up @@ -92,7 +92,7 @@
"config": {
"input_shape": (1024, 1024, 3),
"input_tensor": None,
"include_rescaling": False,
"include_rescaling": True,
"patch_size": 16,
"embed_dim": 1280,
"depth": 32,
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit 7712a81

Please sign in to comment.