在python3中使用imread

2024-10-02 20:44:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我在google collab中安装了EmoPy

pip install EmoPy

并尝试执行以下代码。你知道吗

显示imread中的错误命令。请帮帮我

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'

Tags: sampleimagedatamodelpngonfilenameexamples
2条回答

imread在scipy1.0.0中被弃用,并将在1.2.0中删除。我认为您使用的是1.2版或更高版本。有两种方法可以解决这个问题:

  1. 卸载scipy并使用以下命令安装1.1.0版
pip uninstall scipy 
pip install scipy==1.1.0
  1. 不要使用imreadfromm scipy,而是使用imageioimageio.imread而不是scipy.misc.imread)from documentation中提到的。当然,您需要将imageio导入到您的环境中

我建议使用第一个选项,因为我没有看到您在代码中显式地使用scipy.misc.imread,所以您必须在调用它的任何地方对其进行内部更改。第一个解决方案非常简洁明了,只要将版本降级就可以了。你知道吗

希望这有帮助!你知道吗

或者,您也可以从OpenCV2、cv2.imread使用imread

相关问题 更多 >