Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
4b0c3db
Bump actions/checkout from 4 to 6 (#8649)
dependabot[bot] Dec 2, 2025
0509ef2
Fix network_type docstring formatting in PerceptualLoss
aman0311x Dec 22, 2025
c0b0bdb
DCO Remediation Commit for Mohammad Amanour Rahman <amanourrahman@gma…
aman0311x Dec 22, 2025
658af71
DCO Remediation Commit for Mohammad Amanour Rahman <amanourrahman@gma…
aman0311x Dec 22, 2025
2563a3c
Fix PerceptualLoss enum references and docstrings
aman0311x Dec 22, 2025
d2de10d
DCO Remediation Commit for Mohammad Amanour Rahman <amanourrahman@gma…
aman0311x Dec 22, 2025
f9c1559
DCO Remediation Commit for Mohammad Amanour Rahman <amanourrahman@gma…
aman0311x Dec 22, 2025
695609c
Fix PerceptualLoss enum references and docstrings
aman0311x Dec 22, 2025
67ba0fa
DCO Remediation Commit for Mohammad Amanour Rahman <amanourrahman@gma…
aman0311x Dec 22, 2025
10b5cda
DCO Remediation Commit for Mohammad Amanour Rahman <amanourrahman@gma…
aman0311x Dec 22, 2025
eae8ca5
DCO Remediation Commit for Mohammad Amanour Rahman <amanourrahman@gma…
aman0311x Dec 22, 2025
0bad60d
Fix network_type docstring formatting in PerceptualLoss
aman0311x Dec 22, 2025
8f9f507
WIP: temp commit before cherry-pick
aman0311x Dec 22, 2025
31e620a
Mohammad Amanour Rahman <[email protected]>
aman0311x Dec 22, 2025
3b7a5c0
feat: add installation hints for missing image writers #7980
aman0311x Dec 23, 2025
c9a4728
Fix N806: rename RECOMMENDED_PACKAGES to lowercase
aman0311x Dec 29, 2025
3d3b0cc
Fix logic: preserve dots in format extension for nii.gz lookup
aman0311x Dec 29, 2025
f1210bb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 29, 2025
c409965
Merge branch 'dev' into dev
aman0311x Dec 29, 2025
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
21 changes: 20 additions & 1 deletion monai/data/image_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,26 @@ def resolve_writer(ext_name, error_if_not_found=True) -> Sequence:
except Exception: # other writer init errors indicating it exists
avail_writers.append(_writer)
if not avail_writers and error_if_not_found:
raise OptionalImportError(f"No ImageWriter backend found for {fmt}.")
recommended_packages = {
"png": "Pillow",
"jpg": "Pillow",
"jpeg": "Pillow",
"nii": "nibabel or SimpleITK",
"nii.gz": "nibabel or SimpleITK",
"nrrd": "pynrrd",
"tif": "Pillow or tifffile",
"tiff": "Pillow or tifffile",
}

fmt_clean = fmt.lower()
package_hint = recommended_packages.get(fmt_clean, "")

msg = f"No ImageWriter backend found for {fmt}."
if package_hint:
msg += f" Please install '{package_hint}' (e.g., pip install {package_hint})."

raise OptionalImportError(msg)

writer_tuple = ensure_tuple(avail_writers)
SUPPORTED_WRITERS[fmt] = writer_tuple
return writer_tuple
Expand Down
20 changes: 13 additions & 7 deletions monai/losses/perceptual.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
torchvision, _ = optional_import("torchvision")


class PercetualNetworkType(StrEnum):
class PerceptualNetworkType(StrEnum):
alex = "alex"
vgg = "vgg"
squeeze = "squeeze"
Expand All @@ -49,9 +49,15 @@ class PerceptualLoss(nn.Module):

Args:
spatial_dims: number of spatial dimensions.
network_type: {``"alex"``, ``"vgg"``, ``"squeeze"``, ``"radimagenet_resnet50"``,
``"medicalnet_resnet10_23datasets"``, ``"medicalnet_resnet50_23datasets"``, ``"resnet50"``}
Specifies the network architecture to use. Defaults to ``"alex"``.
network_type: str | PercetualNetworkType = PercetualNetworkType.alex,
One of:
- "alex"
- "vgg"
- "squeeze"
- "radimagenet_resnet50"
- "medicalnet_resnet10_23datasets"
- "medicalnet_resnet50_23datasets"
- "resnet50"
is_fake_3d: if True use 2.5D approach for a 3D perceptual loss.
fake_3d_ratio: ratio of how many slices per axis are used in the 2.5D approach.
cache_dir: path to cache directory to save the pretrained network weights.
Expand All @@ -70,7 +76,7 @@ class PerceptualLoss(nn.Module):
def __init__(
self,
spatial_dims: int,
network_type: str = PercetualNetworkType.alex,
network_type: str = PerceptualNetworkType.alex,
is_fake_3d: bool = True,
fake_3d_ratio: float = 0.5,
cache_dir: str | None = None,
Expand All @@ -93,10 +99,10 @@ def __init__(
if channel_wise and "medicalnet_" not in network_type:
raise ValueError("Channel-wise loss is only compatible with MedicalNet networks.")

if network_type.lower() not in list(PercetualNetworkType):
if network_type.lower() not in list(PerceptualNetworkType):
raise ValueError(
"Unrecognised criterion entered for Adversarial Loss. Must be one in: %s"
% ", ".join(PercetualNetworkType)
% ", ".join(PerceptualNetworkType)
)

if cache_dir:
Expand Down
Loading