From 9db88531438a3581914ba1444fb6f4b5e82f0d36 Mon Sep 17 00:00:00 2001 From: szymanowiczs Date: Thu, 9 Jul 2020 16:06:17 +0200 Subject: [PATCH] Change branch_names type to tuple According to Python documentation, 'sets do not record element position or order of insertion' and the ordering of the elements is not deterministic, i.e. might change with the random seed or other seemingly irrelevant operations (in my case it changed with changing the test batch size). If the order of branches changes, attempting to load a model will result in layer name mismatch, and hence the layers being incorrectly populated with random weights, preventing the reproducibility of results in testing. Changing the type of branch_names to tuple ensures the object is still immutable and has deterministic behaviour. --- torchreid/components/branches.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torchreid/components/branches.py b/torchreid/components/branches.py index 09bfa74..5f72e85 100644 --- a/torchreid/components/branches.py +++ b/torchreid/components/branches.py @@ -26,7 +26,7 @@ def _get_middle_subbranch_for(self, backbone, args, last_branch_class): def _get_branches(self, backbone, args) -> list: - branch_names = frozenset(args['branches']) + branch_names = tuple(args['branches']) branch_list = [] for branch_name in branch_names: