insightface人脸识别算法的应用
在研究 stable-diffusion
的一些 ai
功能时,发现了 insightface
这个开源的人脸检测识别、比对算法模型库。
github
源码
python
类库 : https://pypi.org/project/insightface/
在对它应用时发现一些环境兼容性的问题,因此作一下笔记。
insightface 安装
insightface
目前 python
官方的版本是 0.7.3
pip install insightface
命令即可安装
环境兼容性问题
由于 0.7.3
版本大概两年前,彼时 numpy
版本应该是 1.22.3
,
因此它使用了 numpy.ini
这个属性,但目前 numpy
版本已经迭代到 1.26
以上,
numpy.int
在NumPy 1.20
中已弃用,在NumPy 1.24
中已被删除,所以没有numpy.int
因此,insightface
实际使用时会报错:
Traceback (most recent call last):
File "/data/work/py/sd-api/main.py", line 80, in <module>
start(sys.argv[1:])
File "/data/work/py/sd-api/main.py", line 72, in start
img2img.img2img(filename)
File "/data/work/py/sd-api/img2img.py", line 150, in img2img
cv2.imwrite(faceSaveName, face_analyser.draw_on(faceCheckImg, faces))
File "/home/xiao/anaconda3/envs/sd/lib/python3.10/site-packages/insightface/app/face_analysis.py", line 84, in draw_on
box = face.bbox.astype(np.int)
File "/home/xiao/anaconda3/envs/sd/lib/python3.10/site-packages/numpy/__init__.py", line 324, in __getattr__
raise AttributeError(__former_attrs__[attr])
AttributeError: module 'numpy' has no attribute 'int'.
`np.int` was a deprecated alias for the builtin `int`. To avoid this error in existing code, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations. Did you mean: 'inf'?
解决办法,要么根据提示,将代码中对应的 numpy.ini
修改成 numpy.ini_
,
即修改 insightface
源码。
……