在本地运行 python 项目 face_classification 时遇到的一些问题

项目地址:https://github.com/oarriaga/face_classification

本文记录描述的是在 Windows 10 1909 版本下,python 3.8.2 64-bit,编辑运行 face_classification 项目过程。因为项目有些时间没有更新了,所以似乎跟引用组件的最新版本会有些不匹配,在运行过程中摸索修改。

1、下载整个项目文件后,在 src 目录中,执行命令:python3 video_emotion_color_demo.py。若没有安装 python 环境,windows 会自动打开商店页面提示获取安装。

2、运行后发现很多引用缺失,大概需要安装以下包引用:

pip install opencv-python
pip install keras
pip install tensorflow
pip install pandas
pip install matplotlib
pip install imageio

转自:https://blog.csdn.net/Aria_Miazzy/article/details/94740245

以上引用的最后一个是为了修改适配新的版本,下面说明。

3、修改1:在 src/utils/preprocessor.py 文件中,

from scipy.misc import imresize

此行代码会报错,需要更换为:

#from scipy.misc import imresize
from imageio import imread

转自:https://blog.csdn.net/weixin_41112983/article/details/101453753

 

4、修改2:因为刚刚注释了 imresize 的引用,所以下面代码:

def _imresize(image_array, size):
        return imresize(image_array, size)

需要更换为:

def _imresize(image_array, size):
        #return imresize(image_array, size)
        return np.array(Image.fromarray(image_array), size)

转自:https://blog.csdn.net/discoverer100/article/details/95534621

5、修改3:在 src/utils/inference.py 文件中,因为 keras 的方法参数升级,以下代码:

def load_image(image_path, grayscale=False, target_size=None):
    pil_image = image.load_img(image_path, grayscale, target_size)
    return image.img_to_array(pil_image)

需要更换为:

def load_image(image_path, grayscale=False, target_size=None):
    color_mode = 'grayscale'
    if grayscale == False:
        color_mode = 'rgb'
    else:
        grayscale = False
    pil_image = image.load_img(image_path, grayscale, color_mode, target_size)
    return image.img_to_array(pil_image)

转自:https://blog.csdn.net/qq_25982223/article/details/89602505

6、在运行后发现 tensorflow 的一些警告信息:Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found

应该是需要对 cuda 库的引用,不过不影响正常执行,如果需要的话,可以自行安装:

https://developer.nvidia.com/cuda-10.1-download-archive-update2?target_os=Windows&target_arch=x86_64&target_version=10&target_type=exelocal

转自:https://learnku.com/articles/40393

7、以上就可以正常运行项目的部分测试了:

(1) - python3 video_emotion_color_demo.py:视频表情识别

(2) - python3 video_emotion_gender_demo.py:视频表情性别识别

(3) - python3 image_emotion_gender_demo.py [图片文件地址]:对单张图片进行表情性别识别(输出文件在 images/predicted_test_image.png)

8、对于另外两个:image_gradcam_demo.py 和 video_gradcam_demo.py 执行还有错误,是跟 TensoFlow 相关的内容了,因为不太了解,暂无法解决。

相关思路:

1、https://github.com/oarriaga/face_classification/issues/62

2、https://github.com/tensorflow/tensorflow/issues/33135

原文地址:https://www.cnblogs.com/xwgli/p/12702344.html