From ca17f2cfa6fffd7029cd41051609299dcd3f7b26 Mon Sep 17 00:00:00 2001 From: Jirka Date: Thu, 18 Apr 2024 14:19:07 +0200 Subject: [PATCH 01/19] rename existing `examples/` --- README.md | 2 +- {examples => _examples}/bert_score-own_model.py | 0 {examples => _examples}/detection_map.py | 0 {examples => _examples}/plotting.py | 0 .../rouge_score-own_normalizer_and_tokenizer.py | 0 5 files changed, 1 insertion(+), 1 deletion(-) rename {examples => _examples}/bert_score-own_model.py (100%) rename {examples => _examples}/detection_map.py (100%) rename {examples => _examples}/plotting.py (100%) rename {examples => _examples}/rouge_score-own_normalizer_and_tokenizer.py (100%) diff --git a/README.md b/README.md index 2144d89e010..d5531a36f4d 100644 --- a/README.md +++ b/README.md @@ -334,7 +334,7 @@ fig3, ax3 = acc.plot(values)

-For examples of plotting different metrics try running [this example file](examples/plotting.py). +For examples of plotting different metrics try running [this example file](_examples/plotting.py). ## Contribute! diff --git a/examples/bert_score-own_model.py b/_examples/bert_score-own_model.py similarity index 100% rename from examples/bert_score-own_model.py rename to _examples/bert_score-own_model.py diff --git a/examples/detection_map.py b/_examples/detection_map.py similarity index 100% rename from examples/detection_map.py rename to _examples/detection_map.py diff --git a/examples/plotting.py b/_examples/plotting.py similarity index 100% rename from examples/plotting.py rename to _examples/plotting.py diff --git a/examples/rouge_score-own_normalizer_and_tokenizer.py b/_examples/rouge_score-own_normalizer_and_tokenizer.py similarity index 100% rename from examples/rouge_score-own_normalizer_and_tokenizer.py rename to _examples/rouge_score-own_normalizer_and_tokenizer.py From be4925c324856aec1797b0ecb54d17bc6c4a4cbc Mon Sep 17 00:00:00 2001 From: Jirka Date: Thu, 18 Apr 2024 15:56:39 +0200 Subject: [PATCH 02/19] sphinx gallery init --- docs/source/conf.py | 21 +++---- docs/source/index.rst | 1 + examples/README.rst | 4 ++ examples/image/README.rst | 4 ++ .../image/plot_ spatial_correlation_coef.py | 55 +++++++++++++++++++ requirements/_docs.txt | 2 +- 6 files changed, 74 insertions(+), 13 deletions(-) create mode 100644 examples/README.rst create mode 100644 examples/image/README.rst create mode 100644 examples/image/plot_ spatial_correlation_coef.py diff --git a/docs/source/conf.py b/docs/source/conf.py index f147c0393a0..6d39b20fb77 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -128,14 +128,14 @@ def _set_root_image_path(page_path: str) -> None: "sphinx.ext.autosummary", "sphinx.ext.napoleon", "sphinx.ext.mathjax", - "myst_parser", "sphinx.ext.autosectionlabel", - "nbsphinx", + "sphinx.ext.githubpages", + 'sphinx_gallery.gen_gallery', "sphinx_autodoc_typehints", "sphinx_paramlinks", - "sphinx.ext.githubpages", - "lai_sphinx_theme.extensions.lightning", + "myst_parser", "matplotlib.sphinxext.plot_directive", + "lai_sphinx_theme.extensions.lightning", ] # Set that source code from plotting is always included @@ -146,13 +146,10 @@ def _set_root_image_path(page_path: str) -> None: # Add any paths that contain templates here, relative to this directory. templates_path = ["_templates"] -# https://berkeley-stat159-f17.github.io/stat159-f17/lectures/14-sphinx..html#conf.py-(cont.) -# https://stackoverflow.com/questions/38526888/embed-ipython-notebook-in-sphinx-document -# I execute the notebooks manually in advance. If notebooks test the code, -# they should be run at build time. -nbsphinx_execute = "never" -nbsphinx_allow_errors = True -nbsphinx_requirejs_path = "" +sphinx_gallery_conf = { + 'examples_dirs': os.path.join(_PATH_ROOT, 'examples'), # path to your example scripts + 'gallery_dirs': 'gallery', # path to where to save gallery generated output +} myst_update_mathjax = False @@ -162,7 +159,7 @@ def _set_root_image_path(page_path: str) -> None: ".rst": "restructuredtext", ".txt": "markdown", ".md": "markdown", - ".ipynb": "nbsphinx", + # ".ipynb": "nbsphinx", } # The master toctree document. diff --git a/docs/source/index.rst b/docs/source/index.rst index a51a1184a78..da35a23cb33 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -129,6 +129,7 @@ Or directly from conda pages/quickstart all-metrics + gallery/index pages/overview pages/plotting pages/implement diff --git a/examples/README.rst b/examples/README.rst new file mode 100644 index 00000000000..652ef87baf6 --- /dev/null +++ b/examples/README.rst @@ -0,0 +1,4 @@ +TorchMetrics' gallery +===================== + +Below is a gallery of examples \ No newline at end of file diff --git a/examples/image/README.rst b/examples/image/README.rst new file mode 100644 index 00000000000..0950d082886 --- /dev/null +++ b/examples/image/README.rst @@ -0,0 +1,4 @@ +Image domain +============ + +Samples from image domain \ No newline at end of file diff --git a/examples/image/plot_ spatial_correlation_coef.py b/examples/image/plot_ spatial_correlation_coef.py new file mode 100644 index 00000000000..f8a581265d4 --- /dev/null +++ b/examples/image/plot_ spatial_correlation_coef.py @@ -0,0 +1,55 @@ +""" +Spatial Correlation Coefficient +=============================== + +The Spatial Correlation Coefficient can be applied to compare the spatial structure of two images, + which can be valuable in various domains such as medical imaging, remote sensing, + and quality assessment in manufacturing or design processes. + +Let's consider a use case in medical imaging where Spatial Correlation Coefficient is used to compare + the spatial correlation between a reference image and a reconstructed medical scan. + This can be particularly relevant in evaluating the accuracy of image reconstruction techniques + or assessing the quality of medical imaging data. +""" + +# %% +# Here's a hypothetical Python example demonstrating the usage of the Spatial Correlation Coefficient to compare two medical images: + +import numpy as np +import matplotlib.pyplot as plt +from skimage.transform import radon, iradon, rescale +from skimage.data import shepp_logan_phantom +from torchmetrics.image import SpatialCorrelationCoefficient + +# Create a Shepp-Logan phantom image +phantom = shepp_logan_phantom() +phantom = rescale(phantom, scale=512/400) # Rescaling to 512x512 + +# Simulate projection data (sinogram) using Radon transform +theta = np.linspace(0., 180., max(phantom.shape), endpoint=False) +sinogram = radon(phantom, theta=theta) + +# Perform reconstruction using the inverse Radon transform +reconstruction = iradon(sinogram, theta=theta, circle=True) + +# Display the results +fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(10, 4)) +ax1.set_title("Original") +ax1.imshow(phantom, cmap=plt.cm.Greys_r) +ax2.set_title("Radon transform (Sinogram)") +ax2.imshow(sinogram, cmap=plt.cm.Greys_r, + extent=(0, 180, 0, sinogram.shape[0]), aspect='equal') +ax3.set_title("Reconstruction from sinogram") +ax3.imshow(reconstruction, cmap=plt.cm.Greys_r) +fig.tight_layout() + +# Convert the images to PyTorch tensors +phantom_tensor = torch.from_numpy(phantom).float().unsqueeze(0).unsqueeze(0) +reconstructed_tensor = torch.from_numpy(reconstruction).float().unsqueeze(0).unsqueeze(0) + +# Calculating the Spatial Correlation Coefficient +scc = SpatialCorrelationCoefficient() +score = scc(preds=reconstructed_tensor, target=phantom_tensor) + +print(f"Spatial Correlation Coefficient between the images: {score}") +fig.suptitle(f"Spatial Correlation Coefficient: {score:.5}", y=-0.01) \ No newline at end of file diff --git a/requirements/_docs.txt b/requirements/_docs.txt index ea8bbcd7978..b5e2f7df469 100644 --- a/requirements/_docs.txt +++ b/requirements/_docs.txt @@ -1,6 +1,5 @@ sphinx ==5.3.0 myst-parser ==1.0.0 -nbsphinx ==0.9.3 pandoc ==2.3 docutils ==0.19 sphinxcontrib-fulltoc >=1.0 @@ -10,6 +9,7 @@ sphinx-autodoc-typehints ==1.23.0 sphinx-paramlinks ==0.6.0 sphinx-togglebutton ==0.3.2 sphinx-copybutton ==0.5.2 +sphinx-gallery ==0.15.0 lightning >=1.8.0, <2.3.0 lightning-utilities ==0.11.2 From 31f09ac63cf1cbe39d0a52761fa311b5b56f35ff Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 18 Apr 2024 13:58:27 +0000 Subject: [PATCH 03/19] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/source/conf.py | 6 +++--- examples/README.rst | 2 +- examples/image/README.rst | 2 +- examples/image/plot_ spatial_correlation_coef.py | 16 +++++++--------- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 6d39b20fb77..df860ecb7b3 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -130,7 +130,7 @@ def _set_root_image_path(page_path: str) -> None: "sphinx.ext.mathjax", "sphinx.ext.autosectionlabel", "sphinx.ext.githubpages", - 'sphinx_gallery.gen_gallery', + "sphinx_gallery.gen_gallery", "sphinx_autodoc_typehints", "sphinx_paramlinks", "myst_parser", @@ -147,8 +147,8 @@ def _set_root_image_path(page_path: str) -> None: templates_path = ["_templates"] sphinx_gallery_conf = { - 'examples_dirs': os.path.join(_PATH_ROOT, 'examples'), # path to your example scripts - 'gallery_dirs': 'gallery', # path to where to save gallery generated output + "examples_dirs": os.path.join(_PATH_ROOT, "examples"), # path to your example scripts + "gallery_dirs": "gallery", # path to where to save gallery generated output } myst_update_mathjax = False diff --git a/examples/README.rst b/examples/README.rst index 652ef87baf6..4c7624c2864 100644 --- a/examples/README.rst +++ b/examples/README.rst @@ -1,4 +1,4 @@ TorchMetrics' gallery ===================== -Below is a gallery of examples \ No newline at end of file +Below is a gallery of examples diff --git a/examples/image/README.rst b/examples/image/README.rst index 0950d082886..56dbd3a2513 100644 --- a/examples/image/README.rst +++ b/examples/image/README.rst @@ -1,4 +1,4 @@ Image domain ============ -Samples from image domain \ No newline at end of file +Samples from image domain diff --git a/examples/image/plot_ spatial_correlation_coef.py b/examples/image/plot_ spatial_correlation_coef.py index f8a581265d4..623983266ff 100644 --- a/examples/image/plot_ spatial_correlation_coef.py +++ b/examples/image/plot_ spatial_correlation_coef.py @@ -1,5 +1,4 @@ -""" -Spatial Correlation Coefficient +"""Spatial Correlation Coefficient =============================== The Spatial Correlation Coefficient can be applied to compare the spatial structure of two images, @@ -15,18 +14,18 @@ # %% # Here's a hypothetical Python example demonstrating the usage of the Spatial Correlation Coefficient to compare two medical images: -import numpy as np import matplotlib.pyplot as plt -from skimage.transform import radon, iradon, rescale +import numpy as np from skimage.data import shepp_logan_phantom +from skimage.transform import iradon, radon, rescale from torchmetrics.image import SpatialCorrelationCoefficient # Create a Shepp-Logan phantom image phantom = shepp_logan_phantom() -phantom = rescale(phantom, scale=512/400) # Rescaling to 512x512 +phantom = rescale(phantom, scale=512 / 400) # Rescaling to 512x512 # Simulate projection data (sinogram) using Radon transform -theta = np.linspace(0., 180., max(phantom.shape), endpoint=False) +theta = np.linspace(0.0, 180.0, max(phantom.shape), endpoint=False) sinogram = radon(phantom, theta=theta) # Perform reconstruction using the inverse Radon transform @@ -37,8 +36,7 @@ ax1.set_title("Original") ax1.imshow(phantom, cmap=plt.cm.Greys_r) ax2.set_title("Radon transform (Sinogram)") -ax2.imshow(sinogram, cmap=plt.cm.Greys_r, - extent=(0, 180, 0, sinogram.shape[0]), aspect='equal') +ax2.imshow(sinogram, cmap=plt.cm.Greys_r, extent=(0, 180, 0, sinogram.shape[0]), aspect="equal") ax3.set_title("Reconstruction from sinogram") ax3.imshow(reconstruction, cmap=plt.cm.Greys_r) fig.tight_layout() @@ -52,4 +50,4 @@ score = scc(preds=reconstructed_tensor, target=phantom_tensor) print(f"Spatial Correlation Coefficient between the images: {score}") -fig.suptitle(f"Spatial Correlation Coefficient: {score:.5}", y=-0.01) \ No newline at end of file +fig.suptitle(f"Spatial Correlation Coefficient: {score:.5}", y=-0.01) From 03aefb228e4b5999457f9aadd0676a77bf319582 Mon Sep 17 00:00:00 2001 From: Jirka Date: Thu, 18 Apr 2024 16:06:00 +0200 Subject: [PATCH 04/19] linting --- ...ion_coef.py => plot_spatial_correlation_coef.py} | 7 +++++-- pyproject.toml | 13 +++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) rename examples/image/{plot_ spatial_correlation_coef.py => plot_spatial_correlation_coef.py} (94%) diff --git a/examples/image/plot_ spatial_correlation_coef.py b/examples/image/plot_spatial_correlation_coef.py similarity index 94% rename from examples/image/plot_ spatial_correlation_coef.py rename to examples/image/plot_spatial_correlation_coef.py index 623983266ff..5a0ee5a1469 100644 --- a/examples/image/plot_ spatial_correlation_coef.py +++ b/examples/image/plot_spatial_correlation_coef.py @@ -1,4 +1,5 @@ -"""Spatial Correlation Coefficient +""" +Spatial Correlation Coefficient =============================== The Spatial Correlation Coefficient can be applied to compare the spatial structure of two images, @@ -12,10 +13,12 @@ """ # %% -# Here's a hypothetical Python example demonstrating the usage of the Spatial Correlation Coefficient to compare two medical images: +# Here's a hypothetical Python example demonstrating the usage of the Spatial Correlation Coefficient +# to compare two medical images: import matplotlib.pyplot as plt import numpy as np +import torch from skimage.data import shepp_logan_phantom from skimage.transform import iradon, radon, rescale from torchmetrics.image import SpatialCorrelationCoefficient diff --git a/pyproject.toml b/pyproject.toml index efc34e27a8f..d38a46742c1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,18 +55,23 @@ unfixable = ["F401"] [tool.ruff.lint.per-file-ignores] "setup.py" = ["ANN202", "ANN401"] "docs/source/conf.py" = ["A001", "D103"] +"examples/*" = [ + "D205", # 1 blank line required between summary line and description + "D212", # [*] Multi-line docstring summary should start at the first line + "D415", # First line should end with a period, question mark, or exclamation point +] "src/**" = [ "ANN401", - "S310", # todo: Audit URL open for permitted schemes. Allowing use of `file:` or custom schemes is often unexpected. # todo - ] + "S310", # todo: Audit URL open for permitted schemes. Allowing use of `file:` or custom schemes is often unexpected. +] "tests/**" = [ "ANN001", "ANN201", "ANN202", "ANN401", "S101", - "S301", # todo: `pickle` and modules that wrap it can be unsafe when used to deserialize untrusted data, possible security issue # todo - ] + "S301", # todo: `pickle` and modules that wrap it can be unsafe when used to deserialize untrusted data, possible security issue +] [tool.ruff.lint.pydocstyle] # Use Google-style docstrings. From 00eced837bb5a460d26b65ba0b60869859191741 Mon Sep 17 00:00:00 2001 From: Jirka Date: Fri, 19 Apr 2024 00:11:28 +0200 Subject: [PATCH 05/19] bash --- docs/source/conf.py | 9 +++++++++ examples/image/plot_spatial_correlation_coef.py | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/docs/source/conf.py b/docs/source/conf.py index df860ecb7b3..252f6f957c1 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -149,6 +149,15 @@ def _set_root_image_path(page_path: str) -> None: sphinx_gallery_conf = { "examples_dirs": os.path.join(_PATH_ROOT, "examples"), # path to your example scripts "gallery_dirs": "gallery", # path to where to save gallery generated output + 'filename_pattern': '.', + 'ignore_pattern': r'__init__\.py', + 'example_extensions': {'.py'}, + 'line_numbers': True, + 'promote_jupyter_magic': True, + 'compress_images': ('images', 'thumbnails'), + 'matplotlib_animations': True, + 'abort_on_example_error': True, + # 'only_warn_on_example_error': True } myst_update_mathjax = False diff --git a/examples/image/plot_spatial_correlation_coef.py b/examples/image/plot_spatial_correlation_coef.py index 5a0ee5a1469..26a1207e640 100644 --- a/examples/image/plot_spatial_correlation_coef.py +++ b/examples/image/plot_spatial_correlation_coef.py @@ -12,6 +12,14 @@ or assessing the quality of medical imaging data. """ +#%% +# Installing dependencies +# +# .. code-block:: bash +# +# %%bash +# pip install -q "scikit-image" + # %% # Here's a hypothetical Python example demonstrating the usage of the Spatial Correlation Coefficient # to compare two medical images: From ceba92337946082d8852141922ba12ec1f6f6f5e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 18 Apr 2024 22:12:34 +0000 Subject: [PATCH 06/19] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/source/conf.py | 16 ++++++++-------- examples/image/plot_spatial_correlation_coef.py | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 252f6f957c1..bae3367a1db 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -149,14 +149,14 @@ def _set_root_image_path(page_path: str) -> None: sphinx_gallery_conf = { "examples_dirs": os.path.join(_PATH_ROOT, "examples"), # path to your example scripts "gallery_dirs": "gallery", # path to where to save gallery generated output - 'filename_pattern': '.', - 'ignore_pattern': r'__init__\.py', - 'example_extensions': {'.py'}, - 'line_numbers': True, - 'promote_jupyter_magic': True, - 'compress_images': ('images', 'thumbnails'), - 'matplotlib_animations': True, - 'abort_on_example_error': True, + "filename_pattern": ".", + "ignore_pattern": r"__init__\.py", + "example_extensions": {".py"}, + "line_numbers": True, + "promote_jupyter_magic": True, + "compress_images": ("images", "thumbnails"), + "matplotlib_animations": True, + "abort_on_example_error": True, # 'only_warn_on_example_error': True } diff --git a/examples/image/plot_spatial_correlation_coef.py b/examples/image/plot_spatial_correlation_coef.py index 26a1207e640..4def7ed4122 100644 --- a/examples/image/plot_spatial_correlation_coef.py +++ b/examples/image/plot_spatial_correlation_coef.py @@ -12,7 +12,7 @@ or assessing the quality of medical imaging data. """ -#%% +# %% # Installing dependencies # # .. code-block:: bash From 6eaabba136f0b0362e29f9ae9c1a87dff9d5f988 Mon Sep 17 00:00:00 2001 From: Jirka Date: Fri, 19 Apr 2024 00:18:38 +0200 Subject: [PATCH 07/19] conf --- docs/source/conf.py | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 252f6f957c1..3cd717815ed 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -154,7 +154,6 @@ def _set_root_image_path(page_path: str) -> None: 'example_extensions': {'.py'}, 'line_numbers': True, 'promote_jupyter_magic': True, - 'compress_images': ('images', 'thumbnails'), 'matplotlib_animations': True, 'abort_on_example_error': True, # 'only_warn_on_example_error': True From 35d8b6233a56585e8a48588dc0be3f42c65484ac Mon Sep 17 00:00:00 2001 From: Jirka Date: Fri, 19 Apr 2024 00:33:28 +0200 Subject: [PATCH 08/19] ignore --- .gitignore | 1 + examples/image/plot_spatial_correlation_coef.py | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index cbe31a9b316..d29d7fc696b 100644 --- a/.gitignore +++ b/.gitignore @@ -60,6 +60,7 @@ coverage.xml docs/_build/ docs/source/api/ docs/source/generated/ +docs/source/gallery/ docs/source/*.md docs/source/_static/fetched-s3-assets diff --git a/examples/image/plot_spatial_correlation_coef.py b/examples/image/plot_spatial_correlation_coef.py index 4def7ed4122..f6063030b9c 100644 --- a/examples/image/plot_spatial_correlation_coef.py +++ b/examples/image/plot_spatial_correlation_coef.py @@ -17,8 +17,7 @@ # # .. code-block:: bash # -# %%bash -# pip install -q "scikit-image" +# ! pip install -q "scikit-image" # %% # Here's a hypothetical Python example demonstrating the usage of the Spatial Correlation Coefficient From 1a73270069337722e154ee8be773409cc5632302 Mon Sep 17 00:00:00 2001 From: Jirka Date: Fri, 19 Apr 2024 01:05:26 +0200 Subject: [PATCH 09/19] skimage --- ...ial_correlation_coef.py => spatial_correlation_coef.py} | 7 ------- requirements/_docs.txt | 7 ++++++- 2 files changed, 6 insertions(+), 8 deletions(-) rename examples/image/{plot_spatial_correlation_coef.py => spatial_correlation_coef.py} (95%) diff --git a/examples/image/plot_spatial_correlation_coef.py b/examples/image/spatial_correlation_coef.py similarity index 95% rename from examples/image/plot_spatial_correlation_coef.py rename to examples/image/spatial_correlation_coef.py index f6063030b9c..5a0ee5a1469 100644 --- a/examples/image/plot_spatial_correlation_coef.py +++ b/examples/image/spatial_correlation_coef.py @@ -12,13 +12,6 @@ or assessing the quality of medical imaging data. """ -# %% -# Installing dependencies -# -# .. code-block:: bash -# -# ! pip install -q "scikit-image" - # %% # Here's a hypothetical Python example demonstrating the usage of the Spatial Correlation Coefficient # to compare two medical images: diff --git a/requirements/_docs.txt b/requirements/_docs.txt index b5e2f7df469..ffc04ade92d 100644 --- a/requirements/_docs.txt +++ b/requirements/_docs.txt @@ -23,4 +23,9 @@ pydantic > 1.0.0, < 3.0.0 -r image.txt -r multimodal.txt -r text.txt --r text_test.txt + +# Gallery extra requirements +# -------------------------- +# todo: untill this hase reolution - https://github.com/sphinx-gallery/sphinx-gallery/issues/1290 +# Image +scikit-image >=0.19.0, <=0.21.0 From 7796fb063e2e9341c818f24f1ebb83c4be47a3fd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 18 Apr 2024 23:05:53 +0000 Subject: [PATCH 10/19] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- requirements/_docs.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/_docs.txt b/requirements/_docs.txt index ffc04ade92d..1945c2ad258 100644 --- a/requirements/_docs.txt +++ b/requirements/_docs.txt @@ -26,6 +26,6 @@ pydantic > 1.0.0, < 3.0.0 # Gallery extra requirements # -------------------------- -# todo: untill this hase reolution - https://github.com/sphinx-gallery/sphinx-gallery/issues/1290 +# todo: until this hase reolution - https://github.com/sphinx-gallery/sphinx-gallery/issues/1290 # Image scikit-image >=0.19.0, <=0.21.0 From 9c4b425760d8f7b39190ad7ba89b3122da060294 Mon Sep 17 00:00:00 2001 From: Jirka Date: Fri, 19 Apr 2024 01:30:53 +0200 Subject: [PATCH 11/19] thumbnail --- docs/source/conf.py | 1 + examples/image/spatial_correlation_coef.py | 15 +++++---------- pyproject.toml | 1 + requirements/_docs.txt | 4 ++-- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index a8968afc28c..979fc2b0a7c 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -157,6 +157,7 @@ def _set_root_image_path(page_path: str) -> None: "matplotlib_animations": True, "abort_on_example_error": True, # 'only_warn_on_example_error': True + "thumbnail_size": (224, 224), } myst_update_mathjax = False diff --git a/examples/image/spatial_correlation_coef.py b/examples/image/spatial_correlation_coef.py index 5a0ee5a1469..9d24cb1e6aa 100644 --- a/examples/image/spatial_correlation_coef.py +++ b/examples/image/spatial_correlation_coef.py @@ -2,19 +2,14 @@ Spatial Correlation Coefficient =============================== -The Spatial Correlation Coefficient can be applied to compare the spatial structure of two images, - which can be valuable in various domains such as medical imaging, remote sensing, - and quality assessment in manufacturing or design processes. - -Let's consider a use case in medical imaging where Spatial Correlation Coefficient is used to compare - the spatial correlation between a reference image and a reconstructed medical scan. - This can be particularly relevant in evaluating the accuracy of image reconstruction techniques - or assessing the quality of medical imaging data. +The Spatial Correlation Coefficient can be applied to compare the spatial structure of two images, which can be valuable in various domains such as medical imaging, remote sensing, and quality assessment in manufacturing or design processes. + +Let's consider a use case in medical imaging where Spatial Correlation Coefficient is used to compare the spatial correlation between a reference image and a reconstructed medical scan. +This can be particularly relevant in evaluating the accuracy of image reconstruction techniques or assessing the quality of medical imaging data. """ # %% -# Here's a hypothetical Python example demonstrating the usage of the Spatial Correlation Coefficient -# to compare two medical images: +# Here's a hypothetical Python example demonstrating the usage of the Spatial Correlation Coefficient to compare two medical images: import matplotlib.pyplot as plt import numpy as np diff --git a/pyproject.toml b/pyproject.toml index d38a46742c1..a53281d17ee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -56,6 +56,7 @@ unfixable = ["F401"] "setup.py" = ["ANN202", "ANN401"] "docs/source/conf.py" = ["A001", "D103"] "examples/*" = [ + "E501", # Line too long (XXX > 120) "D205", # 1 blank line required between summary line and description "D212", # [*] Multi-line docstring summary should start at the first line "D415", # First line should end with a period, question mark, or exclamation point diff --git a/requirements/_docs.txt b/requirements/_docs.txt index ffc04ade92d..4f6e7627c8f 100644 --- a/requirements/_docs.txt +++ b/requirements/_docs.txt @@ -26,6 +26,6 @@ pydantic > 1.0.0, < 3.0.0 # Gallery extra requirements # -------------------------- -# todo: untill this hase reolution - https://github.com/sphinx-gallery/sphinx-gallery/issues/1290 +# todo: until this hase reolution - https://github.com/sphinx-gallery/sphinx-gallery/issues/1290 # Image -scikit-image >=0.19.0, <=0.21.0 +scikit-image ~=0.21 From 5d40d6ea37058f4054a0ba7fba6ead71fb99ac35 Mon Sep 17 00:00:00 2001 From: Jirka Date: Fri, 19 Apr 2024 14:03:25 +0200 Subject: [PATCH 12/19] notes --- examples/README.rst | 4 +++- examples/image/README.rst | 2 +- examples/image/spatial_correlation_coef.py | 6 ++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/examples/README.rst b/examples/README.rst index 4c7624c2864..8df126e4d02 100644 --- a/examples/README.rst +++ b/examples/README.rst @@ -1,4 +1,6 @@ TorchMetrics' gallery ===================== -Below is a gallery of examples +Welcome to a comprehensive guide on leveraging TorchMetrics, that facilitates the precise and consistent evaluation of machine learning models. As an integral tool for developers and researchers, TorchMetrics offers an array of metrics critical for assessing model performance across a variety of applications. Whether you are fine-tuning a neural network, comparing model iterations, or tracking performance improvements, this page provides a gallery of real-world applications where Torch Metrics can be effectively implemented. + +By touring through this application gallery, users can gain insights into how TorchMetrics is utilized across different sectors and scale settings, empowering them with the knowledge to implement metrics effectively in their own projects. Whether your interest lies in academic research or commercial product development, the examples provided here will help demonstrate the versatility and utility of Torch Metrics in enhancing machine learning model assessment. diff --git a/examples/image/README.rst b/examples/image/README.rst index 56dbd3a2513..2dd804e9691 100644 --- a/examples/image/README.rst +++ b/examples/image/README.rst @@ -1,4 +1,4 @@ Image domain ============ -Samples from image domain +Image-domain metrics are pivotal for gauging the performance of models in tasks like object detection, and segmentation. TorchMetrics provides a suite of specialized metrics designed for these purposes. Using these image-specific metrics from Torch Metrics helps in developing more precise and robust image-based models, ensuring that performance evaluations are both meaningful and directly applicable to practical vision tasks. diff --git a/examples/image/spatial_correlation_coef.py b/examples/image/spatial_correlation_coef.py index 9d24cb1e6aa..d5a5296aa82 100644 --- a/examples/image/spatial_correlation_coef.py +++ b/examples/image/spatial_correlation_coef.py @@ -18,17 +18,21 @@ from skimage.transform import iradon, radon, rescale from torchmetrics.image import SpatialCorrelationCoefficient +# %% # Create a Shepp-Logan phantom image phantom = shepp_logan_phantom() phantom = rescale(phantom, scale=512 / 400) # Rescaling to 512x512 +# %% # Simulate projection data (sinogram) using Radon transform theta = np.linspace(0.0, 180.0, max(phantom.shape), endpoint=False) sinogram = radon(phantom, theta=theta) +# %% # Perform reconstruction using the inverse Radon transform reconstruction = iradon(sinogram, theta=theta, circle=True) +# %% # Display the results fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(10, 4)) ax1.set_title("Original") @@ -39,10 +43,12 @@ ax3.imshow(reconstruction, cmap=plt.cm.Greys_r) fig.tight_layout() +# %% # Convert the images to PyTorch tensors phantom_tensor = torch.from_numpy(phantom).float().unsqueeze(0).unsqueeze(0) reconstructed_tensor = torch.from_numpy(reconstruction).float().unsqueeze(0).unsqueeze(0) +# %% # Calculating the Spatial Correlation Coefficient scc = SpatialCorrelationCoefficient() score = scc(preds=reconstructed_tensor, target=phantom_tensor) From 73c8e72e4e224ee2dbf40816c41c93f15e3da5c0 Mon Sep 17 00:00:00 2001 From: Jirka Date: Fri, 19 Apr 2024 14:42:05 +0200 Subject: [PATCH 13/19] (400, 280) --- docs/source/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 979fc2b0a7c..c77c267cdd6 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -157,7 +157,7 @@ def _set_root_image_path(page_path: str) -> None: "matplotlib_animations": True, "abort_on_example_error": True, # 'only_warn_on_example_error': True - "thumbnail_size": (224, 224), + "thumbnail_size": (400, 280), } myst_update_mathjax = False From 098ffc80d49c925025cebc64cc87b381be060f93 Mon Sep 17 00:00:00 2001 From: Jirka Date: Mon, 29 Apr 2024 14:37:15 +0200 Subject: [PATCH 14/19] Disable Gallery build --- .github/workflows/docs-build.yml | 3 +++ docs/source/conf.py | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docs-build.yml b/.github/workflows/docs-build.yml index 154dc88b413..5aeef255bfe 100644 --- a/.github/workflows/docs-build.yml +++ b/.github/workflows/docs-build.yml @@ -65,6 +65,9 @@ jobs: - name: Full build for deployment if: github.event_name != 'pull_request' run: echo "SPHINX_FETCH_ASSETS=1" >> $GITHUB_ENV + - name: Disable Gallery build + if: matrix.target != 'html' + run: echo "SPHINX_ENABLE_GALLERY=0" >> $GITHUB_ENV - name: make ${{ matrix.target }} working-directory: ./docs run: make ${{ matrix.target }} --debug --jobs $(nproc) SPHINXOPTS="-W --keep-going" diff --git a/docs/source/conf.py b/docs/source/conf.py index c77c267cdd6..97d38270e78 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -30,6 +30,7 @@ SPHINX_MOCK_REQUIREMENTS = int(os.environ.get("SPHINX_MOCK_REQUIREMENTS", True)) SPHINX_FETCH_ASSETS = int(os.environ.get("SPHINX_FETCH_ASSETS", False)) SPHINX_PIN_RELEASE_VERSIONS = int(os.getenv("SPHINX_PIN_RELEASE_VERSIONS", False)) +SPHINX_ENABLE_GALLERY = int(os.getenv("SPHINX_ENABLE_GALLERY", True)) html_favicon = "_static/images/icon.svg" @@ -130,13 +131,14 @@ def _set_root_image_path(page_path: str) -> None: "sphinx.ext.mathjax", "sphinx.ext.autosectionlabel", "sphinx.ext.githubpages", - "sphinx_gallery.gen_gallery", "sphinx_autodoc_typehints", "sphinx_paramlinks", "myst_parser", "matplotlib.sphinxext.plot_directive", "lai_sphinx_theme.extensions.lightning", ] +if SPHINX_ENABLE_GALLERY: + extensions.append("sphinx_gallery.gen_gallery") # Set that source code from plotting is always included plot_include_source = True From 8068775073b7256c2bb996fb625bba00e2c3b755 Mon Sep 17 00:00:00 2001 From: Jirka Date: Tue, 30 Apr 2024 01:47:27 +0200 Subject: [PATCH 15/19] dummy file --- docs/source/conf.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/source/conf.py b/docs/source/conf.py index 97d38270e78..eebb46ccfb6 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -139,6 +139,10 @@ def _set_root_image_path(page_path: str) -> None: ] if SPHINX_ENABLE_GALLERY: extensions.append("sphinx_gallery.gen_gallery") +else: + # write a dummy file as placeholder + with open(os.path.join(_PATH_HERE, "gallery", "index.rst"), "w") as fopen: + fopen.write("Gallery is disabled") # Set that source code from plotting is always included plot_include_source = True From 434bf3a4bac925ee911b3f2a9b0e1bee7d80a618 Mon Sep 17 00:00:00 2001 From: Jirka Date: Tue, 30 Apr 2024 02:03:05 +0200 Subject: [PATCH 16/19] makedirs --- docs/source/conf.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index eebb46ccfb6..fe3339e0773 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -141,7 +141,9 @@ def _set_root_image_path(page_path: str) -> None: extensions.append("sphinx_gallery.gen_gallery") else: # write a dummy file as placeholder - with open(os.path.join(_PATH_HERE, "gallery", "index.rst"), "w") as fopen: + path_gallery = os.path.join(_PATH_HERE, "gallery") + os.makedirs(path_gallery, exist_ok=True) + with open(os.path.join(path_gallery, "index.rst"), "w") as fopen: fopen.write("Gallery is disabled") # Set that source code from plotting is always included From 510d06c6aadaa25f453e2e3d7a2febfa327b17c7 Mon Sep 17 00:00:00 2001 From: Jirka Date: Tue, 30 Apr 2024 15:08:57 +0200 Subject: [PATCH 17/19] header --- docs/source/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index fe3339e0773..b67f99b1cf0 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -144,7 +144,7 @@ def _set_root_image_path(page_path: str) -> None: path_gallery = os.path.join(_PATH_HERE, "gallery") os.makedirs(path_gallery, exist_ok=True) with open(os.path.join(path_gallery, "index.rst"), "w") as fopen: - fopen.write("Gallery is disabled") + fopen.write("Gallery is disabled\n===================") # Set that source code from plotting is always included plot_include_source = True From 529cfc90a564d19b43d7d62b9eaa9656af2f6ace Mon Sep 17 00:00:00 2001 From: Jirka Date: Tue, 30 Apr 2024 21:21:05 +0200 Subject: [PATCH 18/19] _samples --- .azure/gpu-unittests.yml | 2 +- README.md | 2 +- {_examples => _samples}/bert_score-own_model.py | 0 {_examples => _samples}/detection_map.py | 0 {_examples => _samples}/plotting.py | 0 .../rouge_score-own_normalizer_and_tokenizer.py | 0 6 files changed, 2 insertions(+), 2 deletions(-) rename {_examples => _samples}/bert_score-own_model.py (100%) rename {_examples => _samples}/detection_map.py (100%) rename {_examples => _samples}/plotting.py (100%) rename {_examples => _samples}/rouge_score-own_normalizer_and_tokenizer.py (100%) diff --git a/.azure/gpu-unittests.yml b/.azure/gpu-unittests.yml index 4182b74797c..a827a6aa71d 100644 --- a/.azure/gpu-unittests.yml +++ b/.azure/gpu-unittests.yml @@ -219,7 +219,7 @@ jobs: echo "Processing $fn example..." python $fn done - workingDirectory: "examples/" + workingDirectory: "_samples/" # skip for PR if there is nothing to test, note that outside PR there is default 'unittests' condition: and(succeeded(), ne(variables['TEST_DIRS'], '')) displayName: "Examples" diff --git a/README.md b/README.md index 7e957fa1223..e614376b23d 100644 --- a/README.md +++ b/README.md @@ -335,7 +335,7 @@ fig3, ax3 = acc.plot(values)

-For examples of plotting different metrics try running [this example file](_examples/plotting.py). +For examples of plotting different metrics try running [this example file](_samples/plotting.py). ## Contribute! diff --git a/_examples/bert_score-own_model.py b/_samples/bert_score-own_model.py similarity index 100% rename from _examples/bert_score-own_model.py rename to _samples/bert_score-own_model.py diff --git a/_examples/detection_map.py b/_samples/detection_map.py similarity index 100% rename from _examples/detection_map.py rename to _samples/detection_map.py diff --git a/_examples/plotting.py b/_samples/plotting.py similarity index 100% rename from _examples/plotting.py rename to _samples/plotting.py diff --git a/_examples/rouge_score-own_normalizer_and_tokenizer.py b/_samples/rouge_score-own_normalizer_and_tokenizer.py similarity index 100% rename from _examples/rouge_score-own_normalizer_and_tokenizer.py rename to _samples/rouge_score-own_normalizer_and_tokenizer.py From 6a57e5a966946f91dbcfdf81b657944292006be2 Mon Sep 17 00:00:00 2001 From: Jirka Borovec <6035284+Borda@users.noreply.github.com> Date: Sat, 4 May 2024 14:26:20 +0200 Subject: [PATCH 19/19] Update requirements/_docs.txt Co-authored-by: Daniel Stancl <46073029+stancld@users.noreply.github.com> --- requirements/_docs.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/_docs.txt b/requirements/_docs.txt index 4f6e7627c8f..2cab3cff11c 100644 --- a/requirements/_docs.txt +++ b/requirements/_docs.txt @@ -26,6 +26,6 @@ pydantic > 1.0.0, < 3.0.0 # Gallery extra requirements # -------------------------- -# todo: until this hase reolution - https://github.com/sphinx-gallery/sphinx-gallery/issues/1290 +# todo: until this has resolution - https://github.com/sphinx-gallery/sphinx-gallery/issues/1290 # Image scikit-image ~=0.21