-
Notifications
You must be signed in to change notification settings - Fork 6
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
Inference Updates #405
Merged
Merged
Inference Updates #405
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
947dd46
update saving
9b9253a
refactor czi dataloader
ba34c0d
check if output is a batch
100db4b
some models dont like metatensors
4865af6
add features only option
89834d7
precommit
46407d5
remove channel contrastive
b8d8328
remove oopsie committed files
528df83
incorporate optional metadata keys
31217d5
move metatensor creation
bec4072
precommit and update docstring
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from pathlib import Path | ||
|
||
import pandas as pd | ||
from lightning.pytorch.callbacks import Callback | ||
|
||
|
||
class CSVSaver(Callback): | ||
def __init__(self, save_dir, meta_keys=[]): | ||
self.save_dir = Path(save_dir) | ||
self.save_dir.mkdir(parents=True, exist_ok=True) | ||
self.meta_keys = meta_keys | ||
|
||
def on_predict_epoch_end(self, trainer, pl_module): | ||
# Access the list of predictions from all predict_steps | ||
predictions = trainer.predict_loop.predictions | ||
feats = [] | ||
for pred, meta in predictions: | ||
batch_feats = pd.DataFrame(pred) | ||
for k in self.meta_keys: | ||
batch_feats[k] = meta[k] | ||
feats.append(batch_feats) | ||
pd.concat(feats).to_csv(self.save_dir / "predictions.csv", index=False) |
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
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
Oops, something went wrong.
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.
if features_only mask_ratio must be 0?
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.
I don't want to enforce that in case we want to pass in a mask and just look at features from that subset of tokens (wishful thinking for now, but that's the reason behind that choice)