From d79159daccc7c52f97517c198c92497ca89e586a Mon Sep 17 00:00:00 2001 From: Antony Chan Date: Tue, 7 Jan 2025 09:00:23 -0800 Subject: [PATCH] Load test images from `scipy.datasets` The API `scipy.misc.accent()` is deprecated. Use the new API `scipy.datasets.accent()`. --- README.md | 8 ++++---- doc/source/index.rst | 6 +++--- proximal/examples/basic_denoise.py | 2 +- proximal/examples/test_mask.py | 4 ++-- proximal/examples/test_warp.py | 4 ++-- proximal/tests/base_test.py | 2 +- proximal/tests/test_halide.py | 9 ++++----- proximal/utils/utils.py | 2 +- pyproject.toml | 3 +++ 9 files changed, 21 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index a8fa746..e83da76 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ ProxImaL ===================== ![Build Status](https://github.com/comp-imaging/ProxImaL/actions/workflows/python-package.yml/badge.svg) -ProxImaL is a Python-embedded modeling language for image optimization problems. -It allows you to express your problem in a natural way that follows the math, +ProxImaL is a Python-embedded modeling language for image optimization problems. +It allows you to express your problem in a natural way that follows the math, and automatically determines an efficient method for solving the problem. ProxImaL makes it easy to experiment with many different priors and other problem reformulations, without worrying about the details of how the problem is solved. @@ -17,7 +17,7 @@ import scipy.misc import matplotlib.pyplot as plt # Generate data. -I = scipy.misc.ascent() +I = scipy.datasets.ascent() np.random.seed(1) b = I + 10*np.random.randn(*I.shape) @@ -53,5 +53,5 @@ See [the accompanying paper](https://stevendiamond.me/pdf/proximal.pdf) for a fu A tutorial and other documentation can be found at [proximal-lang.org](http://www.proximal-lang.org/). -This git repository holds the latest development version of ProxImaL. For installation instructions, +This git repository holds the latest development version of ProxImaL. For installation instructions, see the [install guide](http://www.proximal-lang.org/en/latest/install/index.html) at [proximal-lang.org](http://www.proximal-lang.org/). diff --git a/doc/source/index.rst b/doc/source/index.rst index aeca12a..7f59e02 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -6,8 +6,8 @@ Welcome to ProxImaL ===================== -ProxImaL is a Python-embedded modeling language for image optimization problems. -It allows you to express your problem in a natural way that follows the math, +ProxImaL is a Python-embedded modeling language for image optimization problems. +It allows you to express your problem in a natural way that follows the math, and automatically determines an efficient method for solving the problem. ProxImaL makes it easy to experiment with many different priors and other problem reformulations, without worrying about the details of how the problem is solved. @@ -22,7 +22,7 @@ For example, the following code denoises an image using simple sparse gradient a import matplotlib.pyplot as plt # Generate data. - I = scipy.misc.ascent() + I = scipy.datasets.ascent() np.random.seed(1) b = I + 10*np.random.randn(*I.shape) diff --git a/proximal/examples/basic_denoise.py b/proximal/examples/basic_denoise.py index 8b22acb..3a7cdf2 100644 --- a/proximal/examples/basic_denoise.py +++ b/proximal/examples/basic_denoise.py @@ -9,7 +9,7 @@ from proximal.utils.utils import Impl # Generate data. -I = scipy.misc.ascent() +I = scipy.datasets.ascent() np.random.seed(1) b = I + 10 * np.random.randn(*I.shape) diff --git a/proximal/examples/test_mask.py b/proximal/examples/test_mask.py index 869c568..6adfafb 100644 --- a/proximal/examples/test_mask.py +++ b/proximal/examples/test_mask.py @@ -47,7 +47,7 @@ # Error print('Maximum error {0}'.format( - np.linalg.norm(output_ref.ravel() - output.ravel(), np.Inf))) + np.linalg.norm(output_ref.ravel() - output.ravel(), np.inf))) plt.subplot(223) plt.imshow(output_ref, interpolation="nearest", clim=(0.0, 1.0), cmap='gray') @@ -73,6 +73,6 @@ # Error print('Maximum error {0}'.format( - np.linalg.norm(output_ref.ravel() - output_trans.ravel(), np.Inf))) + np.linalg.norm(output_ref.ravel() - output_trans.ravel(), np.inf))) plt.show() \ No newline at end of file diff --git a/proximal/examples/test_warp.py b/proximal/examples/test_warp.py index 587b8a8..8062fbd 100644 --- a/proximal/examples/test_warp.py +++ b/proximal/examples/test_warp.py @@ -70,7 +70,7 @@ plt.title('Output from halide') # Error -delta = np.linalg.norm(output_ref.ravel() - output.ravel(), np.Inf) +delta = np.linalg.norm(output_ref.ravel() - output.ravel(), np.inf) norm = np.amax((output_ref.max(), output.max())) print('Relative error {0}'.format(delta / norm)) @@ -111,7 +111,7 @@ plt.title('Output trans from CV2') # Error -delta = np.linalg.norm(output_ref_trans.ravel() - output_trans.ravel(), np.Inf) +delta = np.linalg.norm(output_ref_trans.ravel() - output_trans.ravel(), np.inf) norm = np.amax((output_ref_trans.max(), output_trans.max())) print('Relative error trans {0}'.format(delta / norm)) plt.show() diff --git a/proximal/tests/base_test.py b/proximal/tests/base_test.py index d723247..7544e8e 100644 --- a/proximal/tests/base_test.py +++ b/proximal/tests/base_test.py @@ -20,7 +20,7 @@ def assertItemsAlmostEqual(self, assert a.shape == b.shape - norm_infinity_b = np.linalg.norm(b.ravel(), np.Inf) + norm_infinity_b = np.linalg.norm(b.ravel(), np.inf) if norm_infinity_b == 0: # b is a zero matrix / vector diff --git a/proximal/tests/test_halide.py b/proximal/tests/test_halide.py index ceecbe1..ab054d4 100644 --- a/proximal/tests/test_halide.py +++ b/proximal/tests/test_halide.py @@ -1,6 +1,5 @@ -import os import numpy as np -from scipy.misc import ascent +from scipy.datasets import ascent from scipy.signal import convolve2d import proximal as px @@ -17,7 +16,7 @@ def test_compile(self): """Test compilation """ Halide('A_conv', reconfigure=True, recompile=True, verbose=False) - + def _get_testvector(self): # Load image @@ -28,7 +27,7 @@ def _get_testvector(self): K /= K.size return np_img, K - + def test_run(self): """ Test running @@ -43,7 +42,7 @@ def test_run(self): output_ref = convolve2d(np_img, K, mode='same', boundary='wrap') self.assertItemsAlmostEqual(output, output_ref) - + def _test_algo(self, algo, check_convergence=True): """ Ensure all internal buffers of the algortihms are Fortran-style ordered. """ diff --git a/proximal/utils/utils.py b/proximal/utils/utils.py index 8dcd135..ede324e 100644 --- a/proximal/utils/utils.py +++ b/proximal/utils/utils.py @@ -2,7 +2,7 @@ # Imports import numpy as np -from scipy.misc import ascent, face +from scipy.datasets import ascent, face import cv2 import os from numpy.fft import fftn, ifftn, fft2, ifft2 diff --git a/pyproject.toml b/pyproject.toml index 042886f..87c52d4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,6 +26,9 @@ test = [ "pytest", "pytest-cov", "ruff", + + # Required by scipy.datasets.accent() + "pooch", ] [project.urls]