-
Notifications
You must be signed in to change notification settings - Fork 2
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
score() returns information with predictions and labels #70
Conversation
The initialization of _features is done once in __init__() It is not necessary to initialize it again when _get_features_hook() is called.
At feature extractor construction, the output_layers_id are used to return features. The model output, i.e the logits, are now also returned. As a consequence, predict_tensor() always returns a list of features + logits, even for a single tensor. Note that, for PyTorch feature extractor, a new member `self._hook_layers_id` is introduced: it is simply the output_layers_id + the last layer id (-1) for the model logits. This new member variable is used to register the hooks in prepare_extractor() and to return the features+logits in predict_tensor().
This commit prepares the new architecture of predict() where a dictionary will be returned with extra information, such as labels and logits.
predict() now returns a 2-tuple of features and extra information. Extra information contains the logits of the model and the labels.
Since predict() now returns a tuple (features, info), all calls to predict() are updated.
The two methods `score()` and `_score_tensor()` of OOD detectors now return a tuple: - a NumPy array of OOD scores - a dictionary containing extra information e.g. logits and labels. This dictionary is the same as in extractor `predict()`.
9e8ddb5
to
0675fd4
Compare
The argument `return_labels` has been removed and predict() now returns a dict containing logits and labels. The unit tests are updated to reflect these changes.
The `score()` function of OOD detectors now returns a tuple of scores and a dictionary containing extra information. The tests now reflect these changes.
0675fd4
to
b2cc11f
Compare
We now use the info["logits"] to compute ood scores for these detectors
☂️ Python Coverage
Overall Coverage
New FilesNo new covered files... Modified Files
|
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.
While reviewing, I felt that finally there were many ,_
cluttering the codebase. I wonder if we would better only return a dict like {features:..., pred:..., labels:..., ...}
...
Otherwise, mostly a few explanations to add in doc.
* Now _score_tensor outputs scores and logits while labels are accessed in the score function * For consistency and to spare VRAM, labels and logits are converted to np arrays
This PR aims at returning both score and predictions when calling
score()
function. Many changes have been introduced:predict_tensor()
in FeatureExtractor now returns the intermediate features + the model output (logits) as a list of tensors. The logits tensor is always the last element of the list.predict()
in FeatureExtractor now returns a tuple of 2 elements: the features (legacy behaviour) and a dictionary containing the logits and the labels.return_labels
inpredict()
was removed. This flag is now useless since labels are in the new dictionary.score()
in detectors returns a tuple of 2 elements: the OOD scores (legacy behaviour) and the same dictionary as above.output_layers_id
has been renamed tofeature_layers_id