pose-tensorflow icon indicating copy to clipboard operation
pose-tensorflow copied to clipboard

replacing deprecated imresize

Open cxrodgers opened this issue 5 years ago • 4 comments

In scipy v1.3, the scipy.misc.imread and scipy.misc.imresize functions are no longer available. These are used throughout this package, especially in loading data in pose_dataset.py.

There's an easy replacement for imread : imageio.imread

For imresize, there are several choices:

  • scipy.ndimage.zoom
  • skimage.transform.resize
  • PIL.Image.resize

These differ slightly in their implementation details (e.g., type of interpolation, anti-aliasing filters). Any preferences for which would be best?

My feeling is that scipy.ndimage.zoom is the best because it doesn't require adding a dependency (skimage or PIL). Also, the function signature is the same as the old scipy.misc.imresize, so it's a drop-in replacement.

cxrodgers avatar Jul 01 '19 21:07 cxrodgers

Here is a commit in my own fork that demonstrates the change: https://github.com/cxrodgers/PoseTF/commit/f36d9f17a3fa784c98055ee5df49b4419a9a2b3f

I can turn this into a PR if people like this approach

cxrodgers avatar Jul 01 '19 22:07 cxrodgers

My feeling is that scipy.ndimage.zoom is the best because it doesn't require adding a dependency (skimage or PIL). Also, the function signature is the same as the old scipy.misc.imresize, so it's a drop-in replacement.

not quite correct. It does not have 'interp' keyword argument which is used in util/visualize.py But anyway, unfortunately this repository is abandoned as many others intended to have papers as outputs...

DenisPolygalov avatar Sep 24 '19 05:09 DenisPolygalov

I see. I don't use util/visualize.py so I didn't know about that.

Here is the code I'm currently using in pose_dataset.py. Perhaps it will be useful for others.

        # Resize the image
        if scale == 1:
            img = image
        else:
            # Zoom each color channel separately
            img = np.array([
                scipy.ndimage.zoom(image[:, :, channel], scale, mode='reflect')
                for channel in range(image.shape[2])])
            img = np.moveaxis(img, 0, -1)

cxrodgers avatar Sep 24 '19 14:09 cxrodgers

I solve it by uninstalling scipy, and: pip install scipy==1.21

pouryajafarzadeh avatar Oct 24 '20 05:10 pouryajafarzadeh