-
Notifications
You must be signed in to change notification settings - Fork 330
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move the image encoder to detectron2 backbone and fix for tf.keras ba…
…ckend
- Loading branch information
1 parent
025dd15
commit 43b0f2b
Showing
17 changed files
with
680 additions
and
312 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Copyright 2023 The KerasCV Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import numpy as np | ||
|
||
from keras_cv.backend import ops | ||
from keras_cv.layers.detectron2_layers import MultiHeadAttentionWithRelativePE | ||
from keras_cv.layers.detectron2_layers import WindowedTransformerEncoder | ||
from keras_cv.tests.test_case import TestCase | ||
|
||
|
||
class TestDetectron2Layers(TestCase): | ||
def test_multi_head_attention_with_relative_pe(self): | ||
attention_with_rel_pe = MultiHeadAttentionWithRelativePE( | ||
num_heads=16, | ||
key_dim=1280 // 16, | ||
use_bias=True, | ||
input_size=(64, 64), | ||
) | ||
x = np.ones(shape=(1, 64, 64, 1280)) | ||
x_out = ops.convert_to_numpy(attention_with_rel_pe(x)) | ||
self.assertEqual(x_out.shape, (1, 64, 64, 1280)) | ||
|
||
def test_windowed_transformer_encoder(self): | ||
windowed_transformer_encoder = WindowedTransformerEncoder( | ||
project_dim=1280, | ||
mlp_dim=1280 * 4, | ||
num_heads=16, | ||
use_bias=True, | ||
use_rel_pos=True, | ||
window_size=14, | ||
input_size=(64, 64), | ||
) | ||
x = np.ones((1, 64, 64, 1280)) | ||
x_out = ops.convert_to_numpy(windowed_transformer_encoder(x)) | ||
self.assertEqual(x_out.shape, (1, 64, 64, 1280)) | ||
self.assertAllClose(x_out, np.ones_like(x_out)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright 2023 The KerasCV Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. |
Binary file not shown.
Oops, something went wrong.