-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_predict.py
More file actions
33 lines (25 loc) · 880 Bytes
/
test_predict.py
File metadata and controls
33 lines (25 loc) · 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import torch
import pandas as pd
import lightning.pytorch as pl
from datamodule import SeqDataModule
from pathlib import Path
def save_predict(trainer: pl.Trainer,
model: pl.LightningModule,
data: SeqDataModule,
save_dir: Path,
pref: str = ""):
df = data.test.copy()
for pred_name, dl in data.dls_for_predictions():
y_preds = trainer.predict(model,
dataloaders=dl)
y_preds = torch.concat(y_preds).cpu().numpy() #type: ignore
df[pred_name] = y_preds
if pref != "":
df.to_csv(save_dir / f"predictions_{pref}.tsv",
sep='\t',
index=False)
else:
df.to_csv(save_dir / f"predictions.tsv",
sep='\t',
index=False)
return df