-
-
Notifications
You must be signed in to change notification settings - Fork 385
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
SWA script added #945
Merged
Merged
SWA script added #945
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
a9af7cd
SWA script added
27828ff
Codestyle fixed
1f770dc
fixed pr issues
78ff817
added test and fix
8260b0a
codestyle fix
7ab43ab
fixes
504f6be
test fixed
6482869
division fix
89d079c
codestyle fixed
4b0ce99
fixed again
a4e07c5
check keys matching added
5b00ca3
Merge branch 'master' into master
95034ca
Merge branch 'master' into master
44f750a
fixed test
17a0ff1
fixed docs
669bbb9
fix
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 |
---|---|---|
|
@@ -16,9 +16,9 @@ def average_weights(state_dicts: List[dict]) -> OrderedDict: | |
""" | ||
Averaging of input weights. | ||
Args: | ||
state_dicts (List[dict]): Weights to avarage | ||
state_dicts (List[dict]): Weights to average | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you please remove type from docs (the type already specified in arguments) |
||
Returns: | ||
Avaraged weights | ||
Averaged weights | ||
""" | ||
# source https://gist.github.com/qubvel/70c3d5e4cddcde731408f478e12ef87b | ||
|
||
|
@@ -45,17 +45,14 @@ def load_weight(path: str) -> dict: | |
return weights | ||
|
||
|
||
def generate_averaged_weights( | ||
logdir: Path, models_mask: str, save_avaraged_model: bool = True | ||
) -> OrderedDict: | ||
def generate_averaged_weights(logdir: Path, models_mask: str) -> OrderedDict: | ||
""" | ||
Averaging of input weights. | ||
Averaging of input weights and saving them. | ||
Args: | ||
logdir (Path): Path to logs directory | ||
models_mask (str): globe-like pattern for models to average | ||
save_avaraged_model (bool): Flag for saving avaraged model | ||
Returns: | ||
Avaraged weights | ||
Averaged weights | ||
""" | ||
|
||
config_path = logdir / "configs" / "_config.json" | ||
|
@@ -66,9 +63,6 @@ def generate_averaged_weights( | |
all_weights = [load_weight(path) for path in models_pathes] | ||
averaged_dict = average_weights(all_weights) | ||
|
||
if save_avaraged_model: | ||
torch.save( | ||
averaged_dict, str(logdir / "checkpoints" / "swa_weights.pth") | ||
) | ||
torch.save(averaged_dict, str(logdir / "checkpoints" / "swa_weights.pth")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's return the model and save it outside |
||
|
||
return averaged_dict |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's simplify to
--models-mask