python 中的 mtcnn 中未定义名称“MTCNN”

Avi*_*Avi 5 python-2.7 conv-neural-network generative-adversarial-network

我安装了mtcnn包,可以看到:

# confirm mtcnn was installed correctly
import mtcnn
# print version
print(mtcnn.__version__)
Run Code Online (Sandbox Code Playgroud)

结果:

0.0.9
Run Code Online (Sandbox Code Playgroud)

然后我使用以下内容:

# prepare model
model = MTCNN()
# detect face in the image
faces = model.detect_faces(pixels)
# extract details of the face
x1, y1, width, height = faces[0]['box']
Run Code Online (Sandbox Code Playgroud)

结果:

1 # prepare model
----> 2 model = MTCNN()
      3 # detect face in the image
      4 faces = model.detect_faces(pixels)
      5 # extract details of the face

NameError: name 'MTCNN' is not defined
Run Code Online (Sandbox Code Playgroud)

use*_*123 6

该文档是一个很好的起点: https: //github.com/ipazc/mtcnn

from mtcnn.mtcnn import MTCNN
import cv2


model = MTCNN()
Run Code Online (Sandbox Code Playgroud)


小智 5

有时,人们所做的是将他们正在处理的文件命名为 mtcnn.py ,这会导致此错误。将文件 mtcnn.py 的名称更改为其他名称即可。