Dealing with Python error "Attribute Error: module'scipy.misc' has no attribute'imresize'" in deep learning

Purpose

misc.imresize()

so,

AttributeError: module 'scipy.misc' has no attribute 'imresize'

May appear.

This is simple, You can see the countermeasures by going around, but I don't like that kind of activity. If I can afford it, I will do some research. This time, I will write an article about what I learned.

Related environmental information

Name: scipy Version: 1.4.1 Summary: SciPy: Scientific Library for Python Home-page: https://www.scipy.org

Errors and countermeasures

Cause

This is related to the common scipy version upgrade, "What was working with the old version of sicpy becomes an error with scipy version 1.3.0 or later" series? is.

Countermeasure 1 (I think Countermeasure 2 is better)

** Set scipy to 1.2.0 ** I get a warning saying "Remove in 1.3.0", but it works.

block_1_hobo_org.py:23: DeprecationWarning: `imresize` is deprecated!
`imresize` is deprecated in SciPy 1.0.0, and will be removed in 1.3.0.
Use Pillow instead: ``numpy.array(Image.fromarray(arr).resize())``.
  obs = (misc.imresize(obs, (110, 84))) #===

Measure 2

Shown at the same time as the above warning  numpy.array(Image.fromarray(arr).resize()) use.

Precautions when using measure 2

** (First, there's just no function called imresize. Another one, It ’s a simple and very easy story to use resize, so As an easy thing, calm down. .. .. .. ) **

Note 1: Specifying the size with ** resize is tuple. ** ** Note 2: ** imresize and resize seem to have the reverse order of hight and width. ** **

In particular, ** imresize (xxx, (110, 42)) ** resize((42,110)) I think you should write it in reverse. Please note that some sites may be incorrect in the explanation on the net.

Supplement (listing help for imresize and resie)

** Pay attention to the order of width and height **

imresize help

(As an aside, the command is, for example, "python -m pydoc PIL.Image.Image.resize". ** Image.Image ** ... I think you can understand it. .)

C:XXXX>python -m pydoc PIL.Image.Image.resize
Help on function resize in PIL.Image.Image:

PIL.Image.Image.resize = resize(self, size, resample=0, box=None)
    Returns a resized copy of this image.

    :param size: The requested size in pixels, as a 2-tuple:
       (width, height).
    :param resample: An optional resampling filter.  This can be
       one of :py:attr:`PIL.Image.NEAREST`, :py:attr:`PIL.Image.BOX`,
       :py:attr:`PIL.Image.BILINEAR`, :py:attr:`PIL.Image.HAMMING`,
       :py:attr:`PIL.Image.BICUBIC` or :py:attr:`PIL.Image.LANCZOS`.
       If omitted, or if the image has mode "1" or "P", it is
       set :py:attr:`PIL.Image.NEAREST`.
       See: :ref:`concept-filters`.
    :param box: An optional 4-tuple of floats giving the region
       of the source image which should be scaled.
       The values should be within (0, 0, width, height) rectangle.
       If omitted or None, the entire source is used.
    :returns: An :py:class:`~PIL.Image.Image` object.

resie help

(As an aside, the command is, for example, "python -m pydoc scipy.misc.imresize".)

C:XXXXX>python -m pydoc scipy.misc.imresize
Help on function imresize in scipy.misc:

scipy.misc.imresize = imresize(*args, **kwds)
    `imresize` is deprecated!
    `imresize` is deprecated in SciPy 1.0.0, and will be removed in 1.3.0.
    Use Pillow instead: ``numpy.array(Image.fromarray(arr).resize())``.


        Resize an image.

        This function is only available if Python Imaging Library (PIL) is installed.

        .. warning::

            This function uses `bytescale` under the hood to rescale images to use
            the full (0, 255) range if ``mode`` is one of ``None, 'L', 'P', 'l'``.
            It will also cast data for 2-D images to ``uint32`` for ``mode=None``
            (which is the default).

        Parameters
        ----------
        arr : ndarray
            The array of image to be resized.
        size : int, float or tuple
            * int   - Percentage of current size.
            * float - Fraction of current size.
            * tuple - Size of the output image (height, width).

        interp : str, optional

Summary

I got an error Guguru ... I have no choice but to do that, but I don't like it. I looked it up and made an article. .. .. .. (It's a contradiction because I'm writing an article with the intention of being confused and useful, but it's a stepping stone for the future ...)

Related (person)

[Correspondence to Python error "Import Error: cannot import name'imread' from'scipy.misc'" in deep learning] (https://qiita.com/enoughspacefor/items/c490ec7195cf66fa286f) Learn Python carefully using both English and Japanese.

from now on

If you have any comments, please let us know. : candy: Will study,,,,

Recommended Posts

Dealing with Python error "Attribute Error: module'scipy.misc' has no attribute'imresize'" in deep learning
Parallel processing with no deep meaning in Python
Dealing with Python (bash, Windows10) error "bash: / c / Users / XYZZZ / AppData / Local / Microsoft / WindowsApps / python3: Permission denied" in deep learning
[Dlib] Attribute Error: module'dlib' has no attribute ...
Dealing with Tensorflow error "Import Error: DLL load failed: Specified module not found" in deep learning
Until dealing with python in Atom
Dealing with tensorflow suddenly stopped working using GPU in deep learning
[Python] Attribute Error:'list' object has no attribute'replace'
Tips for dealing with binaries in Python
Dealing with "years and months" in Python
[Wandb] Attribute Error: module'wandb' has no attribute'init'
Import Error in Python3: No module named'xxxxx'
Dealing with CUDA error "At tempting to fetch value instead of handling error Internal: failed to get device attribute 13 for device 0: CUDA_ERROR_UNKNOWN: unknown error" in deep learning
AttributeError: module'urllib' has no attribute'request' error in urllib.request
ModuleNotFoundError: No module named'_bz2' error in pyenv Python
Precautions when dealing with control structures in Python 2.6
How to deal with module'tensorflow' has no attribute'〇〇'
Python: Deep Learning in Natural Language Processing: Basics
Character encoding when dealing with files in Python 3
Python Deep Learning
Deep learning × Python
[Python] Dealing with multiple call errors in ray.init
Solution when module'XXX' has no attribute'XXX' in Python
First deep learning in C #-Imitating implementation in Python-
[Note] Anaconda & VScode has trouble with python import error
Precautions when dealing with ROS MultiArray types in Python
Deep Learning Experienced in Python Chapter 2 (Materials for Journals)
Japanese output when dealing with python in visual studio
Learning Python with ChemTHEATER 03
"Object-oriented" learning with python
Learning Python with ChemTHEATER 05-1
Learning Python with ChemTHEATER 02
Learning Python with ChemTHEATER 01
Python: Deep Learning Tuning
Easy deep learning web app with NNC and Python + Flask
Sine curve estimation with self-made deep learning module (python) + LSTM
Try deep learning with TensorFlow
Scraping with selenium in Python
Working with LibreOffice in Python
Scraping with chromedriver in python
Debugging with pdb in Python
Reinforcement learning starting with Python
Machine learning with Python! Preparation
Working with sounds in Python
Scraping with Selenium in Python
Try Deep Learning with FPGA
Scraping with Tor in Python
Tweet with image in Python
Combined with permutations in Python
Error when playing with python
Slice error in python (´ ; ω ; `)
Beginning with Python machine learning
Python Iteration Learning with Cheminformatics
Generate Pokemon with Deep Learning
How to deal with python installation error in pyenv (BUILD FAILED)
With deep learning, you can exceed 100% recovery rate in horse racing
Why ModuleNotFoundError: No module named'dataset.mnist' appears in "Deep Learning from scratch".
Multi Layer Perceptron for Deep Learning (Deep Learning with Python; MPS Yokohama Deep Learning Series)
Under investigation about PYNQ-Let's do deep learning with FPGA using Python-