-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update saving * refactor czi dataloader * check if output is a batch * some models dont like metatensors * add features only option * precommit * remove channel contrastive * remove oopsie committed files * incorporate optional metadata keys * move metatensor creation * precommit and update docstring --------- Co-authored-by: Benjamin Morris <[email protected]> Co-authored-by: Benjamin Morris <[email protected]>
- Loading branch information
1 parent
323ff26
commit c65dbbf
Showing
5 changed files
with
121 additions
and
72 deletions.
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