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
Serialize multi_label_threshold for classification models #2368
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ed50f07
First commit for adding multi_label_threshold to state_dict of classi…
yosipk 3340d69
Revert "First commit for PR that adds per-label thresholds"
yosipk 431c237
Added deserialization with default value for loading legacy models
yosipk 3dc5d0d
Merge branch 'master' into GH-2367-serialize-multi-label-threshold
alanakbik 3336e8f
Correct merge mistake
alanakbik 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 |
---|---|---|
|
@@ -87,6 +87,7 @@ def _get_state_dict(self): | |
"label_dictionary": self.label_dictionary, | ||
"label_type": self.label_type, | ||
"multi_label": self.multi_label, | ||
"multi_label_threshold": self.multi_label_threshold, | ||
"weight_dict": self.weight_dict, | ||
} | ||
return model_state | ||
|
@@ -101,6 +102,7 @@ def _init_model_with_state_dict(state): | |
label_dictionary=state["label_dictionary"], | ||
label_type=label_type, | ||
multi_label=state["multi_label"], | ||
multi_label_threshold=0.5 if "multi_label_threshold" not in state.keys() else state["multi_label_threshold"], | ||
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. Instead of default
and then use 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. Cool didn't know about this! |
||
loss_weights=weights, | ||
) | ||
model.load_state_dict(state["state_dict"]) | ||
|
@@ -140,4 +142,4 @@ def _fetch_model(model_name) -> str: | |
|
||
@property | ||
def label_type(self): | ||
return self._label_type | ||
return self._label_type |
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
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.
Instead of default
0.5
the defaults can be read from the class:and then use
multi_label_threshold_default
instead of0.5
.