在 python 3 中使用 imread
Using imread in python 3
我已经在 google 协作中安装了 EmoPy,
pip install EmoPy
并尝试执行以下代码。
imread 显示错误command.Please 帮帮我
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'
imread
在 SciPy 1.0.0 中已弃用,并将在 1.2.0 中删除。我认为您使用的是 1.2 或更高版本。有两种方法可以解决这个问题:
- 使用以下命令卸载您的 scipy 并安装版本 1.1.0
pip uninstall scipy
pip install scipy==1.1.0
- 而不是使用 scipy 中的
imread
,而是使用 imageio
中的它(imageio.imread
而不是 scipy.misc.imread
),如 documentation 中所述.但是当然你需要导入 imageio
到你的环境
我会推荐第一个选项,因为我没有看到您在代码中明确使用 scipy.misc.imread
,因此您必须在调用它的地方进行内部更改。第一个解决方案非常简洁明了,只需降级版本即可。
希望对您有所帮助!
或者,您可以使用 OpenCV2 中的 imread,cv2.imread
我已经在 google 协作中安装了 EmoPy,
pip install EmoPy
并尝试执行以下代码。
imread 显示错误command.Please 帮帮我
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'
imread
在 SciPy 1.0.0 中已弃用,并将在 1.2.0 中删除。我认为您使用的是 1.2 或更高版本。有两种方法可以解决这个问题:
- 使用以下命令卸载您的 scipy 并安装版本 1.1.0
pip uninstall scipy
pip install scipy==1.1.0
- 而不是使用 scipy 中的
imread
,而是使用imageio
中的它(imageio.imread
而不是scipy.misc.imread
),如 documentation 中所述.但是当然你需要导入imageio
到你的环境
我会推荐第一个选项,因为我没有看到您在代码中明确使用 scipy.misc.imread
,因此您必须在调用它的地方进行内部更改。第一个解决方案非常简洁明了,只需降级版本即可。
希望对您有所帮助!
或者,您可以使用 OpenCV2 中的 imread,cv2.imread