From 08b4659bee93637e6444887b9b90fffb2860368a Mon Sep 17 00:00:00 2001 From: akore Date: Tue, 21 Nov 2023 16:30:40 -0500 Subject: [PATCH] fix monitor-api notebook --- cyclops/data/transforms.py | 4 ++-- .../source/tutorials/nihcxr/monitor_api.ipynb | 21 +++++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/cyclops/data/transforms.py b/cyclops/data/transforms.py index 0623ac072..5c2e4216d 100644 --- a/cyclops/data/transforms.py +++ b/cyclops/data/transforms.py @@ -45,7 +45,7 @@ def __init__( allow_missing_keys: bool = False, ): self.transform = Dictd( - transform=Lambda(func=func), + transform=Lambda(func), keys=keys, allow_missing_keys=allow_missing_keys, ) @@ -70,7 +70,7 @@ def __init__( allow_missing_keys: bool = False, ): self.transform = Dictd( - transform=Resize(spatial_size=spatial_size), + transform=Resize(size=spatial_size), keys=keys, allow_missing_keys=allow_missing_keys, ) diff --git a/docs/source/tutorials/nihcxr/monitor_api.ipynb b/docs/source/tutorials/nihcxr/monitor_api.ipynb index 929fc939f..a8ab67050 100644 --- a/docs/source/tutorials/nihcxr/monitor_api.ipynb +++ b/docs/source/tutorials/nihcxr/monitor_api.ipynb @@ -26,17 +26,25 @@ "\"\"\"NIHCXR Clinical Drift Experiments Tutorial.\"\"\"\n", "\n", "\n", + "import random\n", + "\n", "import numpy as np\n", - "from monai.transforms import Compose, Lambdad, Resized\n", + "import torch\n", + "from torchvision.transforms import Compose\n", "from torchxrayvision.models import DenseNet\n", "\n", "from cyclops.data.loader import load_nihcxr\n", "from cyclops.data.slicer import SliceSpec\n", + "from cyclops.data.transforms import Lambdad, Resized\n", "from cyclops.monitor import ClinicalShiftApplicator, Detector, Reductor, TSTester\n", "from cyclops.monitor.plotter import plot_drift_experiment, plot_drift_timeseries\n", "\n", "\n", - "nih_ds = load_nihcxr(\"/mnt/data/clinical_datasets/NIHCXR\")[\"test\"]" + "nih_ds = load_nihcxr(\"/mnt/data/clinical_datasets/NIHCXR\")[\"test\"]\n", + "\n", + "random.seed(42)\n", + "np.random.seed(42)\n", + "torch.manual_seed(42)" ] }, { @@ -65,18 +73,19 @@ "transforms = Compose(\n", " [\n", " Resized(\n", - " keys=(\"image\",),\n", " spatial_size=(224, 224),\n", + " keys=(\"image\",),\n", " allow_missing_keys=True,\n", " ),\n", " Lambdad(\n", - " keys=(\"image\",),\n", " func=lambda x: ((2 * (x / 255.0)) - 1.0) * 1024,\n", + " keys=(\"image\",),\n", " allow_missing_keys=True,\n", " ),\n", " Lambdad(\n", - " (\"image\",),\n", - " func=lambda x: np.mean(x, axis=0)[np.newaxis, :] if x.shape[0] != 1 else x,\n", + " func=lambda x: x[0][np.newaxis, :] if x.shape[0] != 1 else x,\n", + " keys=(\"image\",),\n", + " allow_missing_keys=True,\n", " ),\n", " ],\n", ")"