From 1fbc39d696c5ae32d9bbe3080ede56e1cf94da8b Mon Sep 17 00:00:00 2001 From: Arjun Desai Date: Thu, 3 Aug 2023 00:35:55 -0500 Subject: [PATCH 1/2] upgrade torchmetrics to 1.0 --- .github/workflows/ci.yaml | 8 ---- meddlr/metrics/image.py | 61 ++++++----------------------- meddlr/metrics/lpip.py | 11 +----- meddlr/metrics/metric.py | 10 +---- meddlr/metrics/sem_seg.py | 40 ++++--------------- meddlr/metrics/ssfd.py | 10 +---- setup.py | 2 +- tests/engine/test_model_zoo.py | 2 +- tests/modeling/layers/test_build.py | 2 +- 9 files changed, 29 insertions(+), 117 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 17b61b30..45da0364 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -49,14 +49,6 @@ jobs: python-version: "3.9" torchmetrics-version: "latest" ignore-lpips: "true" - - os: ubuntu-latest - python-version: "3.9" - torchmetrics-version: "0.6.0" - ignore-lpips: "false" - - os: ubuntu-latest - python-version: "3.9" - torchmetrics-version: "0.7.3" - ignore-lpips: "false" env: TORCHMETRICS: ${{ matrix.torchmetrics-version }} IGNORE_LPIPS: ${{ matrix.ignore-lpips }} diff --git a/meddlr/metrics/image.py b/meddlr/metrics/image.py index 71393f0b..ec5fd8b4 100644 --- a/meddlr/metrics/image.py +++ b/meddlr/metrics/image.py @@ -57,19 +57,13 @@ def __init__( im_type: str = None, channel_names: Sequence[str] = None, reduction="none", - compute_on_step: bool = False, - dist_sync_on_step: bool = False, - process_group: bool = None, - dist_sync_fn: bool = None, + **kwargs, ): super().__init__( channel_names=channel_names, units="dB", reduction=reduction, - compute_on_step=compute_on_step, - dist_sync_on_step=dist_sync_on_step, - process_group=process_group, - dist_sync_fn=dist_sync_fn, + **kwargs, ) self.im_type = im_type @@ -105,19 +99,13 @@ def __init__( im_type: str = None, channel_names: Sequence[str] = None, reduction="none", - compute_on_step: bool = False, - dist_sync_on_step: bool = False, - process_group: bool = None, - dist_sync_fn: bool = None, + **kwargs, ): super().__init__( channel_names=channel_names, units="", reduction=reduction, - compute_on_step=compute_on_step, - dist_sync_on_step=dist_sync_on_step, - process_group=process_group, - dist_sync_fn=dist_sync_fn, + **kwargs, ) self.im_type = im_type @@ -153,19 +141,13 @@ def __init__( im_type: str = None, channel_names: Sequence[str] = None, reduction="none", - compute_on_step: bool = False, - dist_sync_on_step: bool = False, - process_group: bool = None, - dist_sync_fn: bool = None, + **kwargs, ): super().__init__( channel_names=channel_names, units="", reduction=reduction, - compute_on_step=compute_on_step, - dist_sync_on_step=dist_sync_on_step, - process_group=process_group, - dist_sync_fn=dist_sync_fn, + **kwargs, ) self.im_type = im_type @@ -201,19 +183,13 @@ def __init__( im_type: str = None, channel_names: Sequence[str] = None, reduction="none", - compute_on_step: bool = False, - dist_sync_on_step: bool = False, - process_group: bool = None, - dist_sync_fn: bool = None, + **kwargs, ): super().__init__( channel_names=channel_names, units="", reduction=reduction, - compute_on_step=compute_on_step, - dist_sync_on_step=dist_sync_on_step, - process_group=process_group, - dist_sync_fn=dist_sync_fn, + **kwargs, ) self.im_type = im_type @@ -252,19 +228,13 @@ def __init__( im_type: str = None, channel_names: Sequence[str] = None, reduction="none", - compute_on_step: bool = False, - dist_sync_on_step: bool = False, - process_group: bool = None, - dist_sync_fn: bool = None, + **kwargs, ): super().__init__( channel_names=channel_names, units="", reduction=reduction, - compute_on_step=compute_on_step, - dist_sync_on_step=dist_sync_on_step, - process_group=process_group, - dist_sync_fn=dist_sync_fn, + **kwargs, ) self.im_type = im_type @@ -301,19 +271,13 @@ def __init__( im_type: str = "magnitude", channel_names: Sequence[str] = None, reduction="none", - compute_on_step: bool = False, - dist_sync_on_step: bool = False, - process_group: bool = None, - dist_sync_fn: bool = None, + **kwargs, ): super().__init__( channel_names=channel_names, units="", reduction=reduction, - compute_on_step=compute_on_step, - dist_sync_on_step=dist_sync_on_step, - process_group=process_group, - dist_sync_fn=dist_sync_fn, + **kwargs, ) self.method = method self.im_type = im_type @@ -522,7 +486,6 @@ def compute_vifp_mscale( num = 0.0 den = 0.0 for scale in range(1, 5): - N = 2 ** (4 - scale + 1) + 1 sd = N / 5.0 diff --git a/meddlr/metrics/lpip.py b/meddlr/metrics/lpip.py index a79ac77f..e1575840 100644 --- a/meddlr/metrics/lpip.py +++ b/meddlr/metrics/lpip.py @@ -36,10 +36,7 @@ def __init__( pretrained: bool = True, channel_names: Sequence[str] = None, reduction="none", - compute_on_step: bool = False, - dist_sync_on_step: bool = False, - process_group: bool = None, - dist_sync_fn: bool = None, + **kwargs, ): """ Args: @@ -72,10 +69,7 @@ def __init__( channel_names=channel_names, units="", reduction=reduction, - compute_on_step=compute_on_step, - dist_sync_on_step=dist_sync_on_step, - process_group=process_group, - dist_sync_fn=dist_sync_fn, + **kwargs, ) valid_net_type = ("vgg", "alex", "squeeze") @@ -92,7 +86,6 @@ def __init__( self.mode = mode def func(self, preds: torch.Tensor, targets: torch.Tensor): - if self.mode == "grayscale": loss_shape = (targets.shape[0], targets.shape[1]) elif self.mode == "rgb": diff --git a/meddlr/metrics/metric.py b/meddlr/metrics/metric.py index f3692b3f..dee4e6dd 100644 --- a/meddlr/metrics/metric.py +++ b/meddlr/metrics/metric.py @@ -46,17 +46,11 @@ def __init__( channel_names: Sequence[str] = None, units: str = None, reduction="none", - compute_on_step: bool = False, - dist_sync_on_step: bool = False, - process_group: bool = None, - dist_sync_fn: bool = None, + **kwargs, ): self.units = units super().__init__( - compute_on_step=compute_on_step, - dist_sync_on_step=dist_sync_on_step, - process_group=process_group, - dist_sync_fn=dist_sync_fn, + **kwargs, ) self.reduction = reduction diff --git a/meddlr/metrics/sem_seg.py b/meddlr/metrics/sem_seg.py index 7ac781db..ff4860ee 100644 --- a/meddlr/metrics/sem_seg.py +++ b/meddlr/metrics/sem_seg.py @@ -22,19 +22,13 @@ def __init__( self, channel_names: Sequence[str] = None, reduction="none", - compute_on_step: bool = False, - dist_sync_on_step: bool = False, - process_group: bool = None, - dist_sync_fn: bool = None, + **kwargs, ): super().__init__( channel_names=channel_names, units="", reduction=reduction, - compute_on_step=compute_on_step, - dist_sync_on_step=dist_sync_on_step, - process_group=process_group, - dist_sync_fn=dist_sync_fn, + **kwargs, ) def func(self, preds, targets) -> torch.Tensor: @@ -58,19 +52,13 @@ def __init__( self, channel_names: Sequence[str] = None, reduction="none", - compute_on_step: bool = False, - dist_sync_on_step: bool = False, - process_group: bool = None, - dist_sync_fn: bool = None, + **kwargs, ): super().__init__( channel_names=channel_names, units="", reduction=reduction, - compute_on_step=compute_on_step, - dist_sync_on_step=dist_sync_on_step, - process_group=process_group, - dist_sync_fn=dist_sync_fn, + **kwargs, ) def func(self, preds, targets) -> torch.Tensor: @@ -91,19 +79,13 @@ def __init__( self, channel_names: Sequence[str] = None, reduction="none", - compute_on_step: bool = False, - dist_sync_on_step: bool = False, - process_group: bool = None, - dist_sync_fn: bool = None, + **kwargs, ): super().__init__( channel_names=channel_names, units="", reduction=reduction, - compute_on_step=compute_on_step, - dist_sync_on_step=dist_sync_on_step, - process_group=process_group, - dist_sync_fn=dist_sync_fn, + **kwargs, ) def func(self, preds, targets) -> torch.Tensor: @@ -130,10 +112,7 @@ def __init__( connectivity: int = 1, channel_names: Sequence[str] = None, reduction="none", - compute_on_step: bool = False, - dist_sync_on_step: bool = False, - process_group: bool = None, - dist_sync_fn: bool = None, + **kwargs, ): """ Args: @@ -145,10 +124,7 @@ def __init__( channel_names=channel_names, units="", reduction=reduction, - compute_on_step=compute_on_step, - dist_sync_on_step=dist_sync_on_step, - process_group=process_group, - dist_sync_fn=dist_sync_fn, + **kwargs, ) self.connectivity = connectivity diff --git a/meddlr/metrics/ssfd.py b/meddlr/metrics/ssfd.py index 019ec093..9b3a7363 100644 --- a/meddlr/metrics/ssfd.py +++ b/meddlr/metrics/ssfd.py @@ -37,10 +37,7 @@ def __init__( layer_names: Sequence[str] = ("block4_relu2",), channel_names: Sequence[str] = None, reduction="none", - compute_on_step: bool = False, - dist_sync_on_step: bool = False, - process_group: bool = None, - dist_sync_fn: bool = None, + **kwargs, ): """ Args: @@ -58,10 +55,7 @@ def __init__( channel_names=channel_names, units="", reduction=reduction, - compute_on_step=compute_on_step, - dist_sync_on_step=dist_sync_on_step, - process_group=process_group, - dist_sync_fn=dist_sync_fn, + **kwargs, ) valid_modes = ("grayscale", "rgb") diff --git a/setup.py b/setup.py index 08293124..11bb3083 100644 --- a/setup.py +++ b/setup.py @@ -198,7 +198,7 @@ def get_git_branch(): "silx", "tqdm", "omegaconf", - "torchmetrics>=0.5.1", + "torchmetrics>=1.0.0", "iopath", "packaging", ] diff --git a/tests/engine/test_model_zoo.py b/tests/engine/test_model_zoo.py index ef705831..cdbcd496 100644 --- a/tests/engine/test_model_zoo.py +++ b/tests/engine/test_model_zoo.py @@ -48,7 +48,7 @@ def test_get_model_from_zoo(): model2 = get_model_from_zoo(_SAMPLE_MODEL_CFG, force_download=True) assert isinstance(model2, nn.Module) - assert type(model2) == type(model) + assert type(model2) == type(model) # noqa: E721 cfg = get_cfg().merge_from_file(path_mgr.get_local_path(_SAMPLE_MODEL_CFG)) model2 = get_model_from_zoo(cfg, _SAMPLE_MODEL_WEIGHTS) diff --git a/tests/modeling/layers/test_build.py b/tests/modeling/layers/test_build.py index 4ae6919a..506ca95f 100644 --- a/tests/modeling/layers/test_build.py +++ b/tests/modeling/layers/test_build.py @@ -258,7 +258,7 @@ def tensor_to_shape(x): return x layer = layer_info.build() - assert type(layer) == type(expected_layer) + assert type(layer) == type(expected_layer) # noqa: E721 layer_shape = tensor_to_shape(layer.__dict__) expected = tensor_to_shape(expected_layer.__dict__) From bfc66978528757e8745c47a043c6d928fff0440c Mon Sep 17 00:00:00 2001 From: Arjun Desai Date: Thu, 3 Aug 2023 00:41:56 -0500 Subject: [PATCH 2/2] upgrade minimum python version --- .github/workflows/ci.yaml | 4 ++-- setup.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 45da0364..78b3baf7 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -41,12 +41,12 @@ jobs: strategy: matrix: os: [ubuntu-latest] - python-version: ["3.7", "3.8", "3.9"] + python-version: ["3.8", "3.9", "3.10"] torchmetrics-version: ["latest"] ignore-lpips: ["false"] include: - os: ubuntu-latest - python-version: "3.9" + python-version: "3.10" torchmetrics-version: "latest" ignore-lpips: "true" env: diff --git a/setup.py b/setup.py index 11bb3083..b6d264a4 100644 --- a/setup.py +++ b/setup.py @@ -180,7 +180,7 @@ def get_git_branch(): AUTHOR = "The Meddlr Team" EMAIL = "arjundd@stanford.edu" URL = "https://github.com/ad12/meddlr" -REQUIRES_PYTHON = ">=3.6" +REQUIRES_PYTHON = ">=3.8" REQUIRED = [ "pyxb", # need to install before ismrmrd