Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'NoneType' object has no attribute 'shape' #1

Open
kommandant-gm opened this issue Nov 19, 2019 · 20 comments
Open

AttributeError: 'NoneType' object has no attribute 'shape' #1

kommandant-gm opened this issue Nov 19, 2019 · 20 comments

Comments

@kommandant-gm
Copy link

kommandant-gm commented Nov 19, 2019

Hi when i try to run this error comes out :
AttributeError: 'NoneType' object has no attribute 'shape'

@FaceGg
Copy link
Owner

FaceGg commented Nov 19, 2019

Hi when i try to run this error comes out :
AttributeError: 'NoneType' object has no attribute 'shape'

@kommandant-gm you need have a video named '1.mp4' . at line 90 of the 'demo.py', vs = cv2.VideoCapture('1.mp4'), we use opencv to open a video, you can change the '1.mp4' into name of your video

@kommandant-gm
Copy link
Author

So basically i can use my own video dataset and change the named to 1.mp4 ? am i correct ? Do u might have any reference ?

@FaceGg
Copy link
Owner

FaceGg commented Nov 19, 2019

@kommandant-gm
Yes, this video is to test the effect, not the training data, so you can call it any name

@kommandant-gm
Copy link
Author

can i follow ur method using opencv as well ? or do i just need to record the face and named it 1.mp4 ?

@FaceGg
Copy link
Owner

FaceGg commented Nov 19, 2019

@kommandant-gm
You can take a video yourself or download one from the Internet.If your computer has a camera, you can also test the real-time video.If there is one or more face in the video, the program will first detect the face, and then judge is real or fake. if there is no face, program will do nothing.

@kommandant-gm
Copy link
Author

Thanks for your assist. I understand about the video problem where i can record myself but may i ask one more how do i get real time video to work ? any specific steps that i have to do ? I do have camera as im using laptop. just the problem when i try to run the file the error pop out

@FaceGg
Copy link
Owner

FaceGg commented Nov 19, 2019

@kommandant-gm
it is easy.
'demo.py'
line 89 #vs = VideoStream(src=0).start()
line 90 vs = cv2.VideoCapture('1.mp4')
line 94 #frame = vs.read()
line 95 frame = vs.read()[1]
change them into
line 89 vs = VideoStream(src=0).start()
line 90 #vs = cv2.VideoCapture('1.mp4')
line 94 frame = vs.read()
line 95 #frame = vs.read()[1]

@kommandant-gm
Copy link
Author

I have changed the step accordingly but these is the error that pop out

https://drive.google.com/open?id=1ZIcLjt4qPB_Y68jbn5gCvOu-OoSF1PJ1

@FaceGg
Copy link
Owner

FaceGg commented Nov 19, 2019

@kommandant-gm
This means the program can't find the camera. You can check if your camera driver is installed correctly or not , and make sure the program has permission to turn on your camera

@kommandant-gm
Copy link
Author

i tried previously doing the face allignment detection project that u post as well and it works just fine. it can open up the camera on my laptop and detect face.

But now i cant open up for this project. Is there any setting that i need configure ?

@FaceGg
Copy link
Owner

FaceGg commented Nov 19, 2019

@kommandant-gm i just run it , have no problem. you can show me the codes form line 89 to line 100

@kommandant-gm
Copy link
Author

yes this the new error pop out

Traceback (most recent call last):
File "C:/Users/User/Desktop/Face-anti-spoofing-master/demo.py", line 102, in
detections = net.forward()
cv2.error: OpenCV(4.1.1) C:\projects\opencv-python\opencv\modules\dnn\src\layers\convolution_layer.cpp:306: error: (-2:Unspecified error) Number of input channels should be multiple of 3 but got 1 in function 'cv::dnn::ConvolutionLayerImpl::getMemoryShapes'

Code from like 89 to 105 :

print("[INFO] starting video stream...")
vs = VideoStream(src=0).start() #vs = cv2.VideoCapture('1.mp4')

time.sleep(2.0)

while True:
    frame = vs.read()  # frame = vs.read()[1]
    frame = vs.read()[1]
    frame = imutils.resize(frame, width=600)
    #frame = imutils.rotate(frame, -90)
    (h, w) = frame.shape[:2]
    blob = cv2.dnn.blobFromImage(cv2.resize(frame, (300, 300)), 1.0,(300, 300), (104.0, 177.0, 123.0))
    net.setInput(blob)
    start = time.time()
    detections = net.forward()
    end = time.time()

    print('detect times : %.3f ms'%((end - start)*1000))

@FaceGg
Copy link
Owner

FaceGg commented Nov 19, 2019

@kommandant-gm
ok ,I know what the problem is. i have changed the codes of 'demo.py', you can try the new

@kommandant-gm
Copy link
Author

kommandant-gm commented Nov 19, 2019

Hi it works now. but it show my face is fake. how do i train own dataset ?
Apparently if my face arent that close to camera it will detect as fake

@FaceGg
Copy link
Owner

FaceGg commented Nov 19, 2019

@kommandant-gm
You can try to get close to the camera, if the face is too small ,it will think it is fake . also you can change the thresholds at line 86. About the training codes ,i am sorry about that it will not be open-sourcing now.

@kommandant-gm
Copy link
Author

I see appreciate much of your help but may i know does these project use CNN for training dataset ?

@FaceGg
Copy link
Owner

FaceGg commented Nov 19, 2019

@kommandant-gm
yes , using CNN is an inevitable trend.

@kommandant-gm
Copy link
Author

Hi, forgot to ask you something about the project i noticed that in the frame beside the true/fake there are numbers. Is it represent the accuracy ?

@FaceGg
Copy link
Owner

FaceGg commented Nov 20, 2019

@kommandant-gm
This is a binary classification, the outputs of model is that output[0] is the probability of fake face , the output[1] is the probability of real face , We focus on the probability of fake face, so we judge if output[0] > thresh( line 86 ), we think that it is a fake face .

@kommandant-gm
Copy link
Author

Hi i have question again sorry. How does the program actually detect it as real or fake ? Is it liveliness detection ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants