Skip to content

Commit

Permalink
Fixing last issues for dataloader
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianHoerst committed Mar 27, 2024
1 parent c2151ea commit ac85c6c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 36 deletions.
36 changes: 1 addition & 35 deletions pathopatch/patch_extraction/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@

warnings.filterwarnings("ignore", category=DeprecationWarning)
warnings.filterwarnings("ignore", category=UserWarning)
from tqdm import tqdm
import yaml


class LivePatchWSIConfig(BaseModel):
Expand Down Expand Up @@ -96,7 +94,7 @@ class LivePatchWSIConfig(BaseModel):

# basic setup
patch_size: int
patch_overlap: int = 0
patch_overlap: float = 0.0
downsample: Optional[int] = 1
target_mpp: Optional[float]
target_mag: Optional[float]
Expand Down Expand Up @@ -766,35 +764,3 @@ def __next__(self) -> Tuple[torch.Tensor, List[dict], List[np.ndarray]]:

def __len__(self):
return int(np.ceil((len(self.dataset) - self.discard_count) / self.batch_size))


if __name__ == "__main__":
"""Just for testing purposes"""
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logger.info("Test")
patch_config = LivePatchWSIConfig(
wsi_path="/Users/fhoerst/Fabian-Projekte/Preprocessing/PathoPatcher/test_database/input/WSI/CMU-1-Small-Region.svs",
patch_size=400,
patch_overlap=25.0,
target_mpp=0.499,
)
outdir = Path(
"/Users/fhoerst/Fabian-Projekte/Preprocessing/PathoPatcher/tests/tmp_results_folder/complex_setup_dataset/memory"
)
outdir.mkdir(parents=True, exist_ok=True)
(outdir / "patches").mkdir(parents=True, exist_ok=True)
(outdir / "metadata").mkdir(parents=True, exist_ok=True)
patch_dataset = LivePatchWSIDataset(patch_config, logger, transforms=None)
patch_dataloader = LivePatchWSIDataloader(patch_dataset, batch_size=1)
for batch in tqdm(patch_dataloader, total=len(patch_dataloader)):
image_tensor = batch[0]
metadata = batch[1][0]
patch_name = f"CMU-1-Small-Region_{metadata['row']}_{metadata['col']}.png"
image_pil = Image.fromarray(image_tensor[0, ...].numpy().astype(np.uint8))
image_pil.save(outdir / "patches" / patch_name)
metadata.pop("discard_patch")
with open(
outdir / "metadata" / f"{patch_name.replace('.png', '.yaml')}", "w"
) as f:
yaml.dump(metadata, f, sort_keys=False)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import find_packages, setup

VERSION = "0.9.5.1b"
VERSION = "0.9.5.3b"
DESCRIPTION = "PathoPatch - Accelerating Artificial Intelligence Based Whole Slide Image Analysis with an Optimized Preprocessing Pipeline"
with open("docs/README_pypi.md", "r") as fh:
LONG_DESCRIPTION = fh.read()
Expand Down

0 comments on commit ac85c6c

Please sign in to comment.