Using imread in python 3

Question:

I have installed EmoPy in google collab,

pip install EmoPy

and tried to execute the following code.

showing error in imread command.Please help me out

from EmoPy.src.fermodel import FERModel
from pkg_resources import resource_filename


target_emotions = ['calm', 'anger', 'happiness']
model = FERModel(target_emotions, verbose=True)

print('Predicting on happy image...')
model.predict(resource_filename('EmoPy.examples','image_data/sample_happy_image.png'))

print('Predicting on disgust image...')
model.predict(resource_filename('EmoPy.examples','image_data/sample_disgust_image.png'))

print('Predicting on anger image...')
model.predict(resource_filename('EmoPy.examples','image_data/sample_anger_image2.png'))

AttributeError: module 'scipy.misc' has no attribute 'imread'
Asked By: poorna

||

Answers:

imread is deprecated in SciPy 1.0.0, and will be removed in 1.2.0. I think you are using version 1.2 or later. There are two ways to solve this:

  1. Uninstall your scipy and install version 1.1.0 using the following commands
pip uninstall scipy 
pip install scipy==1.1.0
  1. Instead of using imread from scipy use it from imageio (imageio.imread instead of scipy.misc.imread) as mentioned in the documentation. But of course you need to import imageio into your environment

I would recommend the first option since I don’t see you explicitly using scipy.misc.imread in your code, so you have to change it internally where ever it is being called. The first solution is quite neat and clean, where you just downgrade the version and it’s all done.

Or alternatively, you can use imread from OpenCV2, cv2.imread

Answered By: Albert H M