Skip to content

Commit 3faaca5

Browse files
committed
Adds external dependency to relevant files, excludes from min tests and uses optional_import to import it
1 parent 89c4e83 commit 3faaca5

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

docs/source/installation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,10 @@ Since MONAI v0.2.0, the extras syntax such as `pip install 'monai[nibabel]'` is
254254
- The options are
255255

256256
```
257-
[nibabel, skimage, pillow, tensorboard, gdown, ignite, torchvision, itk, tqdm, lmdb, psutil, cucim, openslide, pandas, einops, transformers, mlflow, clearml, matplotlib, tensorboardX, tifffile, imagecodecs, pyyaml, fire, jsonschema, ninja, pynrrd, pydicom, h5py, nni, optuna, onnx, onnxruntime, zarr]
257+
[nibabel, skimage, pillow, tensorboard, gdown, ignite, torchvision, itk, tqdm, lmdb, psutil, cucim, openslide, pandas, einops, transformers, mlflow, clearml, matplotlib, tensorboardX, tifffile, imagecodecs, pyyaml, fire, jsonschema, ninja, pynrrd, pydicom, h5py, nni, optuna, onnx, onnxruntime, zarr, lpips]
258258
```
259259

260260
which correspond to `nibabel`, `scikit-image`, `pillow`, `tensorboard`,
261-
`gdown`, `pytorch-ignite`, `torchvision`, `itk`, `tqdm`, `lmdb`, `psutil`, `cucim`, `openslide-python`, `pandas`, `einops`, `transformers`, `mlflow`, `clearml`, `matplotlib`, `tensorboardX`, `tifffile`, `imagecodecs`, `pyyaml`, `fire`, `jsonschema`, `ninja`, `pynrrd`, `pydicom`, `h5py`, `nni`, `optuna`, `onnx`, `onnxruntime`, and `zarr` respectively.
261+
`gdown`, `pytorch-ignite`, `torchvision`, `itk`, `tqdm`, `lmdb`, `psutil`, `cucim`, `openslide-python`, `pandas`, `einops`, `transformers`, `mlflow`, `clearml`, `matplotlib`, `tensorboardX`, `tifffile`, `imagecodecs`, `pyyaml`, `fire`, `jsonschema`, `ninja`, `pynrrd`, `pydicom`, `h5py`, `nni`, `optuna`, `onnx`, `onnxruntime`, `zarr` and `lpips` respectively.
262262

263263
- `pip install 'monai[all]'` installs all the optional dependencies.

monai/losses/perceptual.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313

1414
import torch
1515
import torch.nn as nn
16-
from lpips import LPIPS
16+
17+
from monai.utils import optional_import
18+
19+
LPIPS, _ = optional_import("lpips", name="LPIPS")
1720
from torchvision.models import ResNet50_Weights, resnet50
1821
from torchvision.models.feature_extraction import create_feature_extractor
1922

setup.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ all =
8080
onnx>=1.13.0
8181
onnxruntime; python_version <= '3.10'
8282
zarr
83+
lpips==0.1.4
8384
nibabel =
8485
nibabel
8586
ninja =
@@ -145,6 +146,8 @@ onnx =
145146
onnxruntime; python_version <= '3.10'
146147
zarr =
147148
zarr
149+
lpips =
150+
lpips==0.1.4
148151
# # workaround https://github.com/Project-MONAI/MONAI/issues/5882
149152
# MetricsReloaded =
150153
# MetricsReloaded @ git+https://github.com/Project-MONAI/MetricsReloaded@monai-support#egg=MetricsReloaded

tests/min_tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ def run_testsuit():
204204
"test_spatial_combine_transforms",
205205
"test_bundle_workflow",
206206
"test_zarr_avg_merger",
207+
"test_perceptual_loss",
207208
]
208209
assert sorted(exclude_cases) == sorted(set(exclude_cases)), f"Duplicated items in {exclude_cases}"
209210

0 commit comments

Comments
 (0)