Skip to content

Commit ed3b981

Browse files
authored
Merge branch 'dev' into perf/panoptic-pairwise-iou-bincount
2 parents 60cfbdd + a3d5160 commit ed3b981

4 files changed

Lines changed: 12 additions & 13 deletions

File tree

monai/apps/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def download_url(
240240
if urlparse(url).netloc == "drive.google.com":
241241
if not has_gdown:
242242
raise RuntimeError("To download files from Google Drive, please install the gdown dependency.")
243-
if "fuzzy" not in gdown_kwargs:
243+
if "fuzzy" not in gdown_kwargs and not min_version(gdown, "6.0.0"): # "fuzzy" dropped in gdown 6.0.0
244244
gdown_kwargs["fuzzy"] = True # default to true for flexible url
245245
gdown.download(url, f"{tmp_name}", quiet=not progress, **gdown_kwargs)
246246
elif urlparse(url).netloc == "cloud-api.yandex.net":

monai/bundle/scripts.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2005,7 +2005,6 @@ def download_large_files(bundle_path: str | None = None, large_file_name: str |
20052005
parser.read_config(large_file_path)
20062006
large_files_list = parser.get()["large_files"]
20072007
for lf_data in large_files_list:
2008-
lf_data["fuzzy"] = True
20092008
if "hash_val" in lf_data and lf_data.get("hash_val", "") == "":
20102009
lf_data.pop("hash_val")
20112010
if "hash_type" in lf_data and lf_data.get("hash_type", "") == "":

monai/networks/nets/hovernet.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ def _remap_preact_resnet_model(model_url: str):
632632
pattern_bna = re.compile(r"^(.+\.d\d+)\.blk_bna\.(.+)")
633633
# download the pretrained weights into torch hub's default dir
634634
weights_dir = os.path.join(torch.hub.get_dir(), "preact-resnet50.pth")
635-
download_url(model_url, fuzzy=True, filepath=weights_dir, progress=False)
635+
download_url(model_url, filepath=weights_dir, progress=False)
636636
map_location = None if torch.cuda.is_available() else torch.device("cpu")
637637
state_dict = torch.load(weights_dir, map_location=map_location, weights_only=True)["desc"]
638638

@@ -667,7 +667,7 @@ def _remap_standard_resnet_model(model_url: str, state_dict_key: str | None = No
667667
pattern_downsample1 = re.compile(r"^(res_blocks.d\d+).+\.downsample\.1\.(.+)")
668668
# download the pretrained weights into torch hub's default dir
669669
weights_dir = os.path.join(torch.hub.get_dir(), "resnet50.pth")
670-
download_url(model_url, fuzzy=True, filepath=weights_dir, progress=False)
670+
download_url(model_url, filepath=weights_dir, progress=False)
671671
map_location = None if torch.cuda.is_available() else torch.device("cpu")
672672
state_dict = torch.load(weights_dir, map_location=map_location, weights_only=True)
673673
if state_dict_key is not None:

monai/transforms/utils.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,15 +1224,15 @@ def get_largest_connected_component_mask(
12241224
if num_features <= num_components:
12251225
out = img_.astype(bool)
12261226
else:
1227-
# ignore background
1228-
nonzeros = features[lib.nonzero(features)]
1229-
# get number voxels per feature (bincount). argsort[::-1] to get indices
1230-
# of largest components.
1231-
features_to_keep = lib.argsort(lib.bincount(nonzeros))[::-1]
1232-
# only keep the first n non-background indices
1233-
features_to_keep = features_to_keep[:num_components]
1234-
# generate labelfield. True if in list of features to keep
1235-
out = lib.isin(features, features_to_keep)
1227+
# bincount counts every label; index 0 is background, so drop it before ranking
1228+
counts = lib.bincount(features.reshape(-1))
1229+
counts[0] = 0
1230+
# argsort[::-1] gives labels of the largest components; keep the first n
1231+
features_to_keep = lib.argsort(counts)[::-1][:num_components]
1232+
# boolean lookup-table gather over the label field, cheaper than isin
1233+
keep = lib.zeros(counts.shape[0], dtype=bool)
1234+
keep[features_to_keep] = True
1235+
out = keep[features]
12361236

12371237
return convert_to_dst_type(out, dst=img, dtype=out.dtype)[0]
12381238

0 commit comments

Comments
 (0)