Skip to content

Commit

Permalink
Update more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NielsRogge committed Aug 25, 2024
1 parent be0cf18 commit 615b612
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 45 deletions.
11 changes: 4 additions & 7 deletions tests/models/bit/test_modeling_bit.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def __init__(
hidden_act="relu",
num_labels=3,
scope=None,
out_features=["stage2", "stage3", "stage4"],
out_indices=[2, 3, 4],
num_groups=1,
):
Expand All @@ -69,7 +68,6 @@ def __init__(
self.num_labels = num_labels
self.scope = scope
self.num_stages = len(hidden_sizes)
self.out_features = out_features
self.out_indices = out_indices
self.num_groups = num_groups

Expand All @@ -92,7 +90,6 @@ def get_config(self):
depths=self.depths,
hidden_act=self.hidden_act,
num_labels=self.num_labels,
out_features=self.out_features,
out_indices=self.out_indices,
num_groups=self.num_groups,
)
Expand Down Expand Up @@ -122,15 +119,15 @@ def create_and_check_backbone(self, config, pixel_values, labels):
result = model(pixel_values)

# verify feature maps
self.parent.assertEqual(len(result.feature_maps), len(config.out_features))
self.parent.assertEqual(len(result.feature_maps), len(config.out_indices))
self.parent.assertListEqual(list(result.feature_maps[0].shape), [self.batch_size, self.hidden_sizes[1], 4, 4])

# verify channels
self.parent.assertEqual(len(model.channels), len(config.out_features))
self.parent.assertEqual(len(model.channels), len(config.out_indices))
self.parent.assertListEqual(model.channels, config.hidden_sizes[1:])

# verify backbone works with out_features=None
config.out_features = None
# verify backbone works with out_indices=None
config.out_indices = None
model = BitBackbone(config=config)
model.to(torch_device)
model.eval()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ def get_config(self):
depths=[1, 1, 2, 1],
hidden_act="relu",
num_labels=3,
out_features=["stage2", "stage3", "stage4"],
out_indices=[2, 3, 4],
)
return ConditionalDetrConfig(
Expand Down
11 changes: 4 additions & 7 deletions tests/models/convnext/test_modeling_convnext.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def __init__(
hidden_act="gelu",
num_labels=10,
initializer_range=0.02,
out_features=["stage2", "stage3", "stage4"],
out_indices=[2, 3, 4],
scope=None,
):
Expand All @@ -71,7 +70,6 @@ def __init__(
self.hidden_act = hidden_act
self.num_labels = num_labels
self.initializer_range = initializer_range
self.out_features = out_features
self.out_indices = out_indices
self.scope = scope

Expand All @@ -94,7 +92,6 @@ def get_config(self):
hidden_act=self.hidden_act,
is_decoder=False,
initializer_range=self.initializer_range,
out_features=self.out_features,
out_indices=self.out_indices,
num_labels=self.num_labels,
)
Expand Down Expand Up @@ -124,15 +121,15 @@ def create_and_check_backbone(self, config, pixel_values, labels):
result = model(pixel_values)

# verify hidden states
self.parent.assertEqual(len(result.feature_maps), len(config.out_features))
self.parent.assertEqual(len(result.feature_maps), len(config.out_indices))
self.parent.assertListEqual(list(result.feature_maps[0].shape), [self.batch_size, self.hidden_sizes[1], 4, 4])

# verify channels
self.parent.assertEqual(len(model.channels), len(config.out_features))
self.parent.assertEqual(len(model.channels), len(config.out_indices))
self.parent.assertListEqual(model.channels, config.hidden_sizes[1:])

# verify backbone works with out_features=None
config.out_features = None
# verify backbone works with out_indices=None
config.out_indices = None
model = ConvNextBackbone(config=config)
model.to(torch_device)
model.eval()
Expand Down
11 changes: 4 additions & 7 deletions tests/models/convnextv2/test_modeling_convnextv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def __init__(
hidden_act="gelu",
num_labels=10,
initializer_range=0.02,
out_features=["stage2", "stage3", "stage4"],
out_indices=[2, 3, 4],
scope=None,
):
Expand All @@ -72,7 +71,6 @@ def __init__(
self.hidden_act = hidden_act
self.num_labels = num_labels
self.initializer_range = initializer_range
self.out_features = out_features
self.out_indices = out_indices
self.scope = scope

Expand All @@ -96,7 +94,6 @@ def get_config(self):
hidden_act=self.hidden_act,
is_decoder=False,
initializer_range=self.initializer_range,
out_features=self.out_features,
out_indices=self.out_indices,
num_labels=self.num_labels,
)
Expand Down Expand Up @@ -126,15 +123,15 @@ def create_and_check_backbone(self, config, pixel_values, labels):
result = model(pixel_values)

# verify hidden states
self.parent.assertEqual(len(result.feature_maps), len(config.out_features))
self.parent.assertEqual(len(result.feature_maps), len(config.out_indices))
self.parent.assertListEqual(list(result.feature_maps[0].shape), [self.batch_size, self.hidden_sizes[1], 4, 4])

# verify channels
self.parent.assertEqual(len(model.channels), len(config.out_features))
self.parent.assertEqual(len(model.channels), len(config.out_indices))
self.parent.assertListEqual(model.channels, config.hidden_sizes[1:])

# verify backbone works with out_features=None
config.out_features = None
# verify backbone works with out_indices=None
config.out_indices = None
model = ConvNextV2Backbone(config=config)
model.to(torch_device)
model.eval()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ def get_config(self):
depths=[1, 1, 2, 1],
hidden_act="relu",
num_labels=3,
out_features=["stage2", "stage3", "stage4"],
out_indices=[2, 3, 4],
)
return DeformableDetrConfig(
Expand Down
1 change: 0 additions & 1 deletion tests/models/detr/test_modeling_detr.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ def get_config(self):
depths=[1, 1, 2, 1],
hidden_act="relu",
num_labels=3,
out_features=["stage2", "stage3", "stage4"],
out_indices=[2, 3, 4],
)
return DetrConfig(
Expand Down
11 changes: 4 additions & 7 deletions tests/models/dinat/test_modeling_dinat.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def __init__(
scope=None,
use_labels=True,
num_labels=10,
out_features=["stage1", "stage2"],
out_indices=[1, 2],
):
self.parent = parent
Expand All @@ -91,7 +90,6 @@ def __init__(
self.scope = scope
self.use_labels = use_labels
self.num_labels = num_labels
self.out_features = out_features
self.out_indices = out_indices

def prepare_config_and_inputs(self):
Expand Down Expand Up @@ -125,7 +123,6 @@ def get_config(self):
patch_norm=self.patch_norm,
layer_norm_eps=self.layer_norm_eps,
initializer_range=self.initializer_range,
out_features=self.out_features,
out_indices=self.out_indices,
)

Expand Down Expand Up @@ -166,14 +163,14 @@ def create_and_check_backbone(self, config, pixel_values, labels):
result = model(pixel_values)

# verify hidden states
self.parent.assertEqual(len(result.feature_maps), len(config.out_features))
self.parent.assertEqual(len(result.feature_maps), len(config.out_indices))
self.parent.assertListEqual(list(result.feature_maps[0].shape), [self.batch_size, model.channels[0], 16, 16])

# verify channels
self.parent.assertEqual(len(model.channels), len(config.out_features))
self.parent.assertEqual(len(model.channels), len(config.out_indices))

# verify backbone works with out_features=None
config.out_features = None
# verify backbone works with out_indices=None
config.out_indices = None
model = DinatBackbone(config=config)
model.to(torch_device)
model.eval()
Expand Down
11 changes: 4 additions & 7 deletions tests/models/swin/test_modeling_swin.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def __init__(
use_labels=True,
type_sequence_label_size=10,
encoder_stride=8,
out_features=["stage1", "stage2"],
out_indices=[1, 2],
):
self.parent = parent
Expand All @@ -94,7 +93,6 @@ def __init__(
self.use_labels = use_labels
self.type_sequence_label_size = type_sequence_label_size
self.encoder_stride = encoder_stride
self.out_features = out_features
self.out_indices = out_indices

def prepare_config_and_inputs(self):
Expand Down Expand Up @@ -128,7 +126,6 @@ def get_config(self):
layer_norm_eps=self.layer_norm_eps,
initializer_range=self.initializer_range,
encoder_stride=self.encoder_stride,
out_features=self.out_features,
out_indices=self.out_indices,
)

Expand All @@ -150,14 +147,14 @@ def create_and_check_backbone(self, config, pixel_values, labels):
result = model(pixel_values)

# verify hidden states
self.parent.assertEqual(len(result.feature_maps), len(config.out_features))
self.parent.assertEqual(len(result.feature_maps), len(config.out_indices))
self.parent.assertListEqual(list(result.feature_maps[0].shape), [self.batch_size, model.channels[0], 16, 16])

# verify channels
self.parent.assertEqual(len(model.channels), len(config.out_features))
self.parent.assertEqual(len(model.channels), len(config.out_indices))

# verify backbone works with out_features=None
config.out_features = None
# verify backbone works with out_indices=None
config.out_indices = None
model = SwinBackbone(config=config)
model.to(torch_device)
model.eval()
Expand Down
1 change: 0 additions & 1 deletion tests/models/tvp/test_modeling_tvp.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ def get_config(self):
hidden_sizes=[64, 128],
depths=[2, 2],
hidden_act="relu",
out_features=["stage2"],
out_indices=[2],
)
return TvpConfig(
Expand Down
6 changes: 3 additions & 3 deletions tests/models/upernet/test_modeling_upernet.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(
hidden_act="gelu",
type_sequence_label_size=10,
initializer_range=0.02,
out_features=["stage2", "stage3", "stage4"],
out_indices=[2, 3, 4],
num_labels=3,
scope=None,
):
Expand All @@ -79,7 +79,7 @@ def __init__(
self.hidden_act = hidden_act
self.type_sequence_label_size = type_sequence_label_size
self.initializer_range = initializer_range
self.out_features = out_features
self.out_indices = out_indices
self.num_labels = num_labels
self.scope = scope
self.num_hidden_layers = num_stages
Expand All @@ -104,7 +104,7 @@ def get_backbone_config(self):
is_training=self.is_training,
intermediate_size=self.intermediate_size,
hidden_act=self.hidden_act,
out_features=self.out_features,
out_indices=self.out_indices,
)

def get_config(self):
Expand Down
6 changes: 3 additions & 3 deletions tests/models/zoedepth/test_modeling_zoedepth.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(
num_hidden_layers=2,
num_attention_heads=2,
intermediate_size=8,
out_features=["stage1", "stage2"],
out_indices=[1, 2],
apply_layernorm=False,
reshape_hidden_states=False,
neck_hidden_sizes=[2, 2],
Expand All @@ -69,7 +69,7 @@ def __init__(
self.num_hidden_layers = num_hidden_layers
self.num_attention_heads = num_attention_heads
self.intermediate_size = intermediate_size
self.out_features = out_features
self.out_indices = out_indices
self.apply_layernorm = apply_layernorm
self.reshape_hidden_states = reshape_hidden_states
self.use_labels = use_labels
Expand Down Expand Up @@ -113,7 +113,7 @@ def get_backbone_config(self):
num_attention_heads=self.num_attention_heads,
intermediate_size=self.intermediate_size,
is_training=self.is_training,
out_features=self.out_features,
out_indices=self.out_indices,
reshape_hidden_states=self.reshape_hidden_states,
)

Expand Down

0 comments on commit 615b612

Please sign in to comment.