name 'MTCNN' is not defined in mtcnn in python
Asked Answered
N

2

5

I installed the mtcnn package, as can be seen:

# confirm mtcnn was installed correctly
import mtcnn
# print version
print(mtcnn.__version__)

Result:

0.0.9

Then I use the following:

# 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']

Result:

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
Nonprofessional answered 15/8, 2019 at 20:14 Comment(0)
H
6

The Documentation is a good place to start: https://github.com/ipazc/mtcnn

from mtcnn.mtcnn import MTCNN
import cv2


model = MTCNN()
Hackbut answered 15/8, 2019 at 20:26 Comment(4)
It works. But now I get additional error for the next line: NameError: name 'pixels' is not definedNonprofessional
Did you define Pixels anywhere beforehand?Hackbut
Go to the documentation and follow the tutorial there. This file: github.com/ipazc/mtcnn/blob/master/example.py is the best example you are going to get on how to use that package. The code you have above seems like it doesn't really make any sense. You don't have pixels defined anywhere and you aren't importing MTCNN properly. I don't know what you are trying to do, but if you are having issues loading the package and are having trouble understanding the concept of assigning assigning values to variables, I think you might want to consider taking a python basics refresher course.Hackbut
someone know how to set the margin?Intinction
G
5

Sometimes what people do is name the file they are working on as mtcnn.py which causes this error. Changing the name of the file mtcnn.py to something else will work.

Gasholder answered 8/9, 2020 at 22:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.