Skip to content

Commit

Permalink
Merge pull request #1 from swaradgat19/fix/geojson_command
Browse files Browse the repository at this point in the history
Fix/geojson command
  • Loading branch information
swaradgat19 authored Oct 3, 2023
2 parents 9c33ebc + b1d39af commit 2e53003
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 25 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ jobs:
--wsi-dir slides/ --results-dir results/ --model breast-tumor-resnet34.tcga-brca
test -f results/run_metadata_*.json
test -f results/patches/JP2K-33003-1.h5
test -f results/model-outputs/JP2K-33003-1.csv
test $(wc -l < results/model-outputs/JP2K-33003-1.csv) -eq 675
test -f results/model-outputs-csv/JP2K-33003-1.csv
test $(wc -l < results/model-outputs-csv/JP2K-33003-1.csv) -eq 675
# This is run on multiple operating systems.
test-package:
Expand Down Expand Up @@ -104,8 +104,8 @@ jobs:
wsinfer run --wsi-dir slides/ --results-dir results/ --model breast-tumor-resnet34.tcga-brca
test -f results/run_metadata_*.json
test -f results/patches/JP2K-33003-1.h5
test -f results/model-outputs/JP2K-33003-1.csv
test $(wc -l < results/model-outputs/JP2K-33003-1.csv) -eq 675
test -f results/model-outputs-csv/JP2K-33003-1.csv
test $(wc -l < results/model-outputs-csv/JP2K-33003-1.csv) -eq 675
# FIXME: tissue segmentation has different outputs on Windows. The patch sizes
# are the same but the coordinates found are different.
- name: Run 'wsinfer run' on Windows
Expand All @@ -118,7 +118,7 @@ jobs:
wsinfer run --wsi-dir slides/ --results-dir results/ --model breast-tumor-resnet34.tcga-brca
Test-Path -Path results/run_metadata_*.json -PathType Leaf
Test-Path -Path results/patches/JP2K-33003-1.h5 -PathType Leaf
Test-Path -Path results/model-outputs/JP2K-33003-1.csv -PathType Leaf
Test-Path -Path results/model-outputs-csv/JP2K-33003-1.csv -PathType Leaf
# test $(python -c "print(sum(1 for _ in open('results/model-outputs/JP2K-33003-1.csv')))") -eq 675
style-and-types:
Expand Down
6 changes: 3 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
},
"use_edit_page_button": True,
"show_toc_level": 1,
# "navbar_align": "content",
"navbar_align": "left",
"github_url": "https://github.com/SBU-BMI/wsinfer",
"navbar_end": ["version-switcher", "theme-switcher", "navbar-icon-links"],
"show_version_warning_banner": True,
Expand All @@ -112,5 +112,5 @@
],
"header_links_before_dropdown": 6,
}
# html_logo = "_static/logo.svg"
# html_favicon = "_static/log

html_favicon = "_static/logo.svg"
3 changes: 1 addition & 2 deletions docs/qupath_ext.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ QuPath extension
================

WSInfer has a QuPath extension for interactive model inference.

This documentation is a work in progress.
See `the documentation on QuPath's website <https://qupath.readthedocs.io/en/latest/docs/deep/wsinfer.html>`_.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ dependencies = [
"torch>=1.7",
"torchvision",
"tqdm",
"wsinfer-zoo",
"wsinfer-zoo>=0.6.2",
]
dynamic = ["version"]

Expand Down
2 changes: 1 addition & 1 deletion wsinfer/cli/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def run(
# different directory, both directories need to be bind mounted onto the container.
# If only the symlinked directory is included, then the patching script will fail,
# even though it looks like there are files in the wsi_dir directory.
files_in_wsi_dir = [p for p in wsi_dir.glob("*") if p.exists()]
files_in_wsi_dir = [p for p in wsi_dir.iterdir() if p.is_file()]
if not files_in_wsi_dir:
raise FileNotFoundError(f"no files exist in the slide directory: {wsi_dir}")

Expand Down
2 changes: 1 addition & 1 deletion wsinfer/modellib/run_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def run_inference(
wsi_dir = Path(wsi_dir)
if not wsi_dir.exists():
raise errors.WholeSlideImageDirectoryNotFound(f"directory not found: {wsi_dir}")
wsi_paths = list(wsi_dir.glob("*"))
wsi_paths = [p for p in wsi_dir.iterdir() if p.is_file()]
if not wsi_paths:
raise errors.WholeSlideImagesNotFound(wsi_dir)
results_dir = Path(results_dir)
Expand Down
2 changes: 1 addition & 1 deletion wsinfer/patchlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def segment_and_patch_directory_of_slides(

_validate_wsi_directory(wsi_dir)

slide_paths = sorted(wsi_dir.glob("*"))
slide_paths = sorted([p for p in wsi_dir.iterdir() if p.is_file()])

# NOTE: we could use multi-processing here but then the logs would get
# discombobulated.
Expand Down
9 changes: 4 additions & 5 deletions wsinfer/write_geojson.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
from __future__ import annotations

import json
import shutil
import uuid
from functools import partial
from pathlib import Path

import click
import pandas as pd
from tqdm.contrib.concurrent import process_map

Expand Down Expand Up @@ -91,9 +89,10 @@ def write_geojsons(csvs: list[Path], results_dir: Path, num_workers: int) -> Non
)
if not (results_dir / "model-outputs-csv").exists():
raise FileExistsError(
"Expected results_dir to contain a 'model-outputs-csv' directory but it does"
" not. Please provide the path to the directory that contains"
" model-outputs, masks, and patches."
"Expected results_dir to contain a 'model-outputs-csv' "
"directory but it does not."
"Please provide the path to the directory"
"that contains model-outputs, masks, and patches."
)
if output.exists():
geojsons = list((results_dir / "model-outputs-geojson").glob("*.json"))
Expand Down
11 changes: 5 additions & 6 deletions wsinfer/wsi.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,10 @@ def _get_mpp_tiffslide(
def _get_mpp_tifffile(slide_path: str | Path) -> tuple[float, float]:
"""Read MPP using Tifffile."""
with tifffile.TiffFile(slide_path) as tif:
try:
series0 = tif.series[0]
page0 = series0[0]
except:
raise CannotReadSpacing()
series0 = tif.series[0]
page0 = series0[0]
if not isinstance(page0, tifffile.TiffPage):
raise CannotReadSpacing("not a tifffile.TiffPage instance")
try:
resolution_unit = page0.tags["ResolutionUnit"].value
x_resolution = Fraction(*page0.tags["XResolution"].value)
Expand Down Expand Up @@ -291,7 +290,7 @@ def get_avg_mpp(slide_path: Path | str) -> float:
def _validate_wsi_directory(wsi_dir: str | Path) -> None:
"""Validate a directory of whole slide images."""
wsi_dir = Path(wsi_dir)
maybe_slides = sorted(wsi_dir.glob("*"))
maybe_slides = [p for p in wsi_dir.iterdir() if p.is_file()]
uniq_stems = set(p.stem for p in maybe_slides)
if len(uniq_stems) != len(maybe_slides):
raise DuplicateFilePrefixesFound(
Expand Down

0 comments on commit 2e53003

Please sign in to comment.