Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added fixed random seed to not depend of randomness of initialized weights #1839

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion tests/unit_tests/repvgg_unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,25 @@ def test_deployment_architecture(self):
"""
image_size = 224
in_channels = 3

for arch_name in ARCHITECTURES:
# skip custom constructors to keep all_arch_params as general as a possible
if "repvgg" not in arch_name or "custom" in arch_name:
continue

with self.subTest(arch_name=arch_name):
# Set the seed to 0 to ensure that the model is initialized with the same weights
torch.manual_seed(0)
model = ARCHITECTURES[arch_name](arch_params=self.all_arch_params)
self.assertTrue(hasattr(model.stem, "branch_3x3")) # check single layer for training mode
self.assertTrue(model.build_residual_branches)

training_mode_sd = model.state_dict()
for module in training_mode_sd:
self.assertFalse("reparam" in module) # deployment block included in training mode
test_input = torch.ones((1, in_channels, image_size, image_size))

# Initializing input with 0.1 instead of 1.0 to move mean of input closer to 0
test_input = torch.ones((1, in_channels, image_size, image_size)) * 0.1
model.eval()
training_mode_output = model(test_input)

Expand All @@ -83,6 +88,8 @@ def test_backbone_mode(self):
"""
image_size = 224
in_channels = 3
# Set the seed to 0 to ensure that the model is initialized with the same weights
torch.manual_seed(0)
test_input = torch.rand((1, in_channels, image_size, image_size))
backbone_model = RepVggA1(self.backbone_arch_params)
model = BackboneBasedModel(backbone_model, backbone_output_channel=1280, num_classes=self.backbone_arch_params.num_classes)
Expand Down
Loading