-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
32 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import pytest | ||
import keras | ||
from keras import ops | ||
|
||
|
||
from k3_addons.layers.attention.cbam import ChannelAttention, SpatialAttention, CBAMBlock | ||
|
||
|
||
@pytest.mark.parametrize("input_shape", [(1, 10, 10, 256), (1, 14, 14, 128)]) | ||
def test_channel_attention(input_shape): | ||
inputs = keras.random.normal(input_shape) | ||
layer = ChannelAttention() | ||
out = layer(inputs) | ||
assert ops.shape(out) == (1, 1, 1,) + (input_shape[-1],) | ||
|
||
@pytest.mark.parametrize("input_shape", [(1, 10, 10, 256), (1, 14, 14, 128)]) | ||
def test_spatial_attention(input_shape): | ||
inputs = keras.random.normal(input_shape) | ||
layer = SpatialAttention() | ||
out = layer(inputs) | ||
assert ops.shape(out) == input_shape[:-1] + (1,) # Dynamic assertion | ||
|
||
@pytest.mark.parametrize("input_shape", [(1, 10, 10, 256), (1, 14, 14, 128)]) | ||
def test_cbam(input_shape): | ||
inputs = keras.random.normal(input_shape) # Modify input shape | ||
layer = CBAMBlock() | ||
out = layer(inputs) | ||
assert ops.shape(out) == input_shape # Output shape should remain the same |