|
|
|
|
|
|
|
import numpy as np |
|
import pandas as pd |
|
import torch |
|
from pytorch_lightning import Trainer |
|
from torch.utils.data import DataLoader |
|
from utils.datasets import ECGSingleLeadDataset |
|
from utils.models import EffNet |
|
from utils.training_models import BinaryClassificationModel |
|
|
|
|
|
def append_noise_predictions_to_manifest(data_path, manifest_path, weights_path): |
|
|
|
test_ds = ECGSingleLeadDataset( |
|
data_path=data_path, |
|
manifest_path=manifest_path, |
|
update_manifest_func=None, |
|
) |
|
|
|
|
|
test_dl = DataLoader( |
|
test_ds, |
|
num_workers=16, |
|
batch_size=512, |
|
drop_last=False, |
|
shuffle=False |
|
) |
|
|
|
|
|
backbone = EffNet(input_channels=1, output_neurons=1) |
|
|
|
|
|
model = BinaryClassificationModel(backbone) |
|
|
|
|
|
weights = torch.load(weights_path) |
|
model.load_state_dict(weights) |
|
|
|
|
|
trainer = Trainer(accelerator="gpu", devices=1) |
|
|
|
|
|
trainer.predict(model, dataloaders=test_dl) |
|
|
|
|
|
df = pd.read_csv('dataloader_0_predictions.csv') |
|
|
|
|
|
max_preds = df['preds'].max() |
|
min_preds = df['preds'].min() |
|
df['noise_preds_normal'] = (df['preds'] - min_preds) / (max_preds - min_preds) |
|
|
|
|
|
df.drop(columns='preds', inplace=True) |
|
|
|
|
|
df.to_csv(manifest_path) |
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
data_path="/your/wearable/ecg/data path/" |
|
|
|
manifest_path="manifest" |
|
|
|
weights_path = "model_noise_classifier.pt" |
|
|
|
append_noise_predictions_to_manifest(data_path, manifest_path, weights_path) |
|
|
|
|