Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,8 @@ def generate_apidocs(*args):
html_theme_options = {
"external_links": [{"url": "https://github.com/Project-MONAI/tutorials", "name": "Tutorials"}],
"icon_links": [
{
"name": "GitHub",
"url": "https://github.com/project-monai/monai",
"icon": "fab fa-github-square",
},
{
"name": "Twitter",
"url": "https://twitter.com/projectmonai",
"icon": "fab fa-twitter-square",
},
{"name": "GitHub", "url": "https://github.com/project-monai/monai", "icon": "fab fa-github-square"},
{"name": "Twitter", "url": "https://twitter.com/projectmonai", "icon": "fab fa-twitter-square"},
],
"collapse_navigation": True,
"navigation_depth": 3,
Expand Down
2 changes: 1 addition & 1 deletion monai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
raise RuntimeError(
"MONAI requires Python {}.{} or higher. But the current Python is: {}".format(
PY_REQUIRED_MAJOR, PY_REQUIRED_MINOR, sys.version
),
)
)

from .utils.module import load_submodules # noqa: E402
Expand Down
6 changes: 1 addition & 5 deletions monai/_extensions/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,7 @@ def load_module(
# This will either run the build or return the existing .so object.
name = module_name + platform_str.replace(".", "_")
module = load(
name=name,
sources=source,
extra_cflags=define_args,
extra_cuda_cflags=define_args,
verbose=verbose_build,
name=name, sources=source, extra_cflags=define_args, extra_cuda_cflags=define_args, verbose=verbose_build
)

return module
14 changes: 2 additions & 12 deletions monai/apps/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,7 @@ def _generate_data_list(self, dataset_dir: str) -> List[Dict]:
)

return [
{
"image": image_files_list[i],
"label": image_class[i],
"class_name": class_name[i],
}
{"image": image_files_list[i], "label": image_class[i], "class_name": class_name[i]}
for i in section_indices
]

Expand Down Expand Up @@ -366,13 +362,7 @@ class CrossValidation:

"""

def __init__(
self,
dataset_cls,
nfolds: int = 5,
seed: int = 0,
**dataset_params,
) -> None:
def __init__(self, dataset_cls, nfolds: int = 5, seed: int = 0, **dataset_params) -> None:
if not hasattr(dataset_cls, "_split_datalist"):
raise ValueError("dataset class must have _split_datalist API.")
self.dataset_cls = dataset_cls
Expand Down
13 changes: 2 additions & 11 deletions monai/apps/deepedit/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@


class DiscardAddGuidanced(MapTransform):
def __init__(
self,
keys: KeysCollection,
probability: float = 1.0,
allow_missing_keys: bool = False,
):
def __init__(self, keys: KeysCollection, probability: float = 1.0, allow_missing_keys: bool = False):
"""
Discard positive and negative points randomly or Add the two channels for inference time

Expand Down Expand Up @@ -54,11 +49,7 @@ class ResizeGuidanceCustomd(Transform):
Resize the guidance based on cropped vs resized image.
"""

def __init__(
self,
guidance: str,
ref_image: str,
) -> None:
def __init__(self, guidance: str, ref_image: str) -> None:
self.guidance = guidance
self.ref_image = ref_image

Expand Down
10 changes: 2 additions & 8 deletions monai/apps/deepgrow/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,7 @@ def _save_data_2d(vol_idx, vol_image, vol_label, dataset_dir, relative_path):
# Test Data
if vol_label is None:
data_list.append(
{
"image": image_file.replace(dataset_dir + os.pathsep, "") if relative_path else image_file,
}
{"image": image_file.replace(dataset_dir + os.pathsep, "") if relative_path else image_file}
)
continue

Expand Down Expand Up @@ -236,11 +234,7 @@ def _save_data_3d(vol_idx, vol_image, vol_label, dataset_dir, relative_path):

# Test Data
if vol_label is None:
data_list.append(
{
"image": image_file.replace(dataset_dir + os.pathsep, "") if relative_path else image_file,
}
)
data_list.append({"image": image_file.replace(dataset_dir + os.pathsep, "") if relative_path else image_file})
else:
# For all Labels
unique_labels = np.unique(vol_label.flatten())
Expand Down
15 changes: 2 additions & 13 deletions monai/apps/deepgrow/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,7 @@ class AddGuidanceSignald(Transform):

"""

def __init__(
self,
image: str = "image",
guidance: str = "guidance",
sigma: int = 2,
number_intensity_ch: int = 1,
):
def __init__(self, image: str = "image", guidance: str = "guidance", sigma: int = 2, number_intensity_ch: int = 1):
self.image = image
self.guidance = guidance
self.sigma = sigma
Expand Down Expand Up @@ -276,12 +270,7 @@ class AddRandomGuidanced(Randomizable, Transform):

"""

def __init__(
self,
guidance: str = "guidance",
discrepancy: str = "discrepancy",
probability: str = "probability",
):
def __init__(self, guidance: str = "guidance", discrepancy: str = "discrepancy", probability: str = "probability"):
self.guidance = guidance
self.discrepancy = discrepancy
self.probability = probability
Expand Down
6 changes: 1 addition & 5 deletions monai/apps/pathology/data/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,7 @@ def _load_a_patch(self, index):
location_on_image = sample["image_locations"][patch_num]
location_on_mask = sample["mask_locations"][patch_num]

image, _ = self.image_reader.get_data(
img=sample["image"],
location=location_on_image,
size=self.patch_size,
)
image, _ = self.image_reader.get_data(img=sample["image"], location=location_on_image, size=self.patch_size)
processed_sample = {"image": image, "name": sample["name"], "mask_location": location_on_mask}
return processed_sample

Expand Down
22 changes: 4 additions & 18 deletions monai/apps/pathology/metrics/lesion_froc.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,7 @@ def __init__(
self.itc_diameter = itc_diameter
self.eval_thresholds = eval_thresholds
self.image_reader = WSIReader(image_reader_name)
self.nms = PathologyProbNMS(
sigma=nms_sigma,
prob_threshold=nms_prob_threshold,
box_size=nms_box_size,
)
self.nms = PathologyProbNMS(sigma=nms_sigma, prob_threshold=nms_prob_threshold, box_size=nms_box_size)

def prepare_inference_result(self, sample: Dict):
"""
Expand Down Expand Up @@ -151,12 +147,7 @@ def compute_fp_tp(self):
total_tp_probs.extend(tp_probs)
total_num_targets += num_targets

return (
np.array(total_fp_probs),
np.array(total_tp_probs),
total_num_targets,
num_images,
)
return (np.array(total_fp_probs), np.array(total_tp_probs), total_num_targets, num_images)

def evaluate(self):
"""
Expand All @@ -168,17 +159,12 @@ def evaluate(self):

# compute FROC curve given the evaluation of all images
fps_per_image, total_sensitivity = compute_froc_curve_data(
fp_probs=fp_probs,
tp_probs=tp_probs,
num_targets=num_targets,
num_images=num_images,
fp_probs=fp_probs, tp_probs=tp_probs, num_targets=num_targets, num_images=num_images
)

# compute FROC score give specific evaluation threshold
froc_score = compute_froc_score(
fps_per_image=fps_per_image,
total_sensitivity=total_sensitivity,
eval_thresholds=self.eval_thresholds,
fps_per_image=fps_per_image, total_sensitivity=total_sensitivity, eval_thresholds=self.eval_thresholds
)

return froc_score
4 changes: 1 addition & 3 deletions monai/apps/pathology/transforms/spatial/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ class SplitOnGrid(Transform):
"""

def __init__(
self,
grid_size: Union[int, Tuple[int, int]] = (2, 2),
patch_size: Optional[Union[int, Tuple[int, int]]] = None,
self, grid_size: Union[int, Tuple[int, int]] = (2, 2), patch_size: Optional[Union[int, Tuple[int, int]]] = None
):
# Grid size
if isinstance(grid_size, int):
Expand Down
6 changes: 1 addition & 5 deletions monai/apps/pathology/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@ class PathologyProbNMS(ProbNMS):
Pathology.
"""

def __call__(
self,
probs_map: Union[np.ndarray, torch.Tensor],
resolution_level: int = 0,
):
def __call__(self, probs_map: Union[np.ndarray, torch.Tensor], resolution_level: int = 0):
"""
probs_map: the input probabilities map, it must have shape (H[, W, ...]).
resolution_level: the level at which the probabilities map is made.
Expand Down
15 changes: 2 additions & 13 deletions monai/apps/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@
else:
tqdm, has_tqdm = optional_import("tqdm", "4.47.0", min_version, "tqdm")

__all__ = [
"check_hash",
"download_url",
"extractall",
"download_and_extract",
]
__all__ = ["check_hash", "download_url", "extractall", "download_and_extract"]


def _basename(p):
Expand Down Expand Up @@ -69,13 +64,7 @@ def update_to(self, b: int = 1, bsize: int = 1, tsize: Optional[int] = None):
self.total = tsize
self.update(b * bsize - self.n) # will also set self.n = b * bsize

with TqdmUpTo(
unit="B",
unit_scale=True,
unit_divisor=1024,
miniters=1,
desc=_basename(filepath),
) as t:
with TqdmUpTo(unit="B", unit_scale=True, unit_divisor=1024, miniters=1, desc=_basename(filepath)) as t:
urlretrieve(url, filepath, reporthook=t.update_to)
else:
if not has_tqdm and progress:
Expand Down
6 changes: 1 addition & 5 deletions monai/data/csv_saver.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ class CSVSaver:
"""

def __init__(
self,
output_dir: str = "./",
filename: str = "predictions.csv",
overwrite: bool = True,
flush: bool = False,
self, output_dir: str = "./", filename: str = "predictions.csv", overwrite: bool = True, flush: bool = False
) -> None:
"""
Args:
Expand Down
6 changes: 1 addition & 5 deletions monai/data/dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,4 @@ def __init__(self, dataset: Dataset, num_workers: int = 0, **kwargs) -> None:
if "worker_init_fn" not in kwargs:
kwargs.update({"worker_init_fn": worker_init_fn})

super().__init__( # type: ignore[call-overload]
dataset=dataset,
num_workers=num_workers,
**kwargs,
)
super().__init__(dataset=dataset, num_workers=num_workers, **kwargs) # type: ignore[call-overload]
7 changes: 1 addition & 6 deletions monai/data/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1218,11 +1218,6 @@ def __init__(
files = ensure_tuple(filename)
dfs = [pd.read_csv(f) for f in files]
data = convert_tables_to_dicts(
dfs=dfs,
row_indices=row_indices,
col_names=col_names,
col_types=col_types,
col_groups=col_groups,
**kwargs,
dfs=dfs, row_indices=row_indices, col_names=col_names, col_types=col_types, col_groups=col_groups, **kwargs
)
super().__init__(data=data, transform=transform)
5 changes: 1 addition & 4 deletions monai/data/decathlon_datalist.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,7 @@ def load_decathlon_datalist(
return _append_paths(base_dir, is_segmentation, expected_data)


def load_decathlon_properties(
data_property_file_path: str,
property_keys: Union[Sequence[str], str],
) -> Dict:
def load_decathlon_properties(data_property_file_path: str, property_keys: Union[Sequence[str], str]) -> Dict:
"""Load the properties from the JSON file contains data property with specified `property_keys`.

Args:
Expand Down
23 changes: 4 additions & 19 deletions monai/data/image_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,12 +637,7 @@ def _get_meta_dict(self, img) -> Dict:
img: a PIL Image object loaded from an image file.

"""
return {
"format": img.format,
"mode": img.mode,
"width": img.width,
"height": img.height,
}
return {"format": img.format, "mode": img.mode, "width": img.width, "height": img.height}

def _get_spatial_shape(self, img):
"""
Expand Down Expand Up @@ -729,10 +724,7 @@ def get_data(

if self.reader_lib == "openslide" and size is None:
# the maximum size is set to WxH
size = (
img.shape[0] // (2 ** level) - location[0],
img.shape[1] // (2 ** level) - location[1],
)
size = (img.shape[0] // (2 ** level) - location[0], img.shape[1] // (2 ** level) - location[1])

region = self._extract_region(img, location=location, size=size, level=level, dtype=dtype)

Expand All @@ -745,10 +737,7 @@ def get_data(
else:
tuple_patch_size = ensure_tuple_rep(patch_size, 2)
patches = self._extract_patches(
region,
patch_size=tuple_patch_size, # type: ignore
grid_shape=grid_shape,
dtype=dtype,
region, patch_size=tuple_patch_size, grid_shape=grid_shape, dtype=dtype # type: ignore
)

return patches, metadata
Expand All @@ -772,11 +761,7 @@ def _extract_region(
region = self.convert_to_rgb_array(region, dtype)
return region

def convert_to_rgb_array(
self,
raw_region,
dtype: DtypeLike = np.uint8,
):
def convert_to_rgb_array(self, raw_region, dtype: DtypeLike = np.uint8):
"""Convert to RGB mode and numpy array"""
if self.reader_lib == "openslide":
# convert to RGB
Expand Down
6 changes: 1 addition & 5 deletions monai/data/png_saver.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,7 @@ def save(self, data: Union[torch.Tensor, np.ndarray], meta_data: Optional[Dict]
raise ValueError(f"Unsupported number of channels: {data.shape[0]}, available options are [1, 3, 4]")

write_png(
np.asarray(data),
file_name=path,
output_spatial_shape=spatial_shape,
mode=self.mode,
scale=self.scale,
np.asarray(data), file_name=path, output_spatial_shape=spatial_shape, mode=self.mode, scale=self.scale
)

if self.print_log:
Expand Down
4 changes: 1 addition & 3 deletions monai/data/test_time_augmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,7 @@ def __call__(
transform_info = batch_data[transform_key]
if self.nearest_interp:
transform_info = convert_inverse_interp_mode(
trans_info=deepcopy(transform_info),
mode="nearest",
align_corners=None,
trans_info=deepcopy(transform_info), mode="nearest", align_corners=None
)

# create a dictionary containing the inferred batch and their transforms
Expand Down
7 changes: 1 addition & 6 deletions monai/data/thread_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,7 @@ class ThreadDataLoader(DataLoader):
"""

def __init__(
self,
dataset: Dataset,
buffer_size: int = 1,
buffer_timeout: float = 0.01,
num_workers: int = 0,
**kwargs,
self, dataset: Dataset, buffer_size: int = 1, buffer_timeout: float = 0.01, num_workers: int = 0, **kwargs
):
super().__init__(dataset, num_workers, **kwargs)
self.buffer_size = buffer_size
Expand Down
Loading