hairymax / Face-AntiSpoofing

Face Anti-Spoofing project. Lanit-Tercom summer school 2022
28 stars 5 forks source link

error 'bool' object is not subscriptable ,.. #1

Closed danii92 closed 1 year ago

danii92 commented 1 year ago

dear:

thank you for sharing this project,

1- I have an error show when i try to run --> python video_predict.py path/to/video.mp4 path/to/out_video.mp4 --model_path path/to/model.onnx which is 'bool' object is not subscriptable.

2- i am wondering about the purpose of [0] on line 42 in video_predict.py and [0][0] on line 45 in video_predict.py

3- if i remove the [0] from previews lines ..the code run successfully but i get wrong prediction (real 0.0 all time even with spoofing pic)

please i am waiting your advice..thanks

hairymax commented 1 year ago

Hi, @danii92 You should look into the AntiSpoof class from the src/FaceAntiSpoofing.py module. Line 42 in video_predict.py calls anti_spoof (AntiSpoof object) that takes a list of images and returns a list with class probabilities for each image, each element of the list is an array, the shape of which is equal to (1,N), where N - is the number of classes.

  1. This command cannot execute correctly, you must pass your arguments, This is just an example of writing a command. Have you tried changing the arguments to your own? Call of AntiSpoof object returns False (bool object) in case if onnx session is not initialized. It happens, when model_path is not correct

  2. In our case in video_predict.py, we are passing a list with only one image (every video frame), but it still returns a list (with only one element). Thats why [0] is needed. Because the shape of the array with predictions is (1,N), we use pred[0] and since we only display the probability that the face is real, we take the zero element - pred[0][0].

  3. Better deal with point 2 first. btw, prediction for spoof pic should be close to 0.0, for real - close to 1.0

danii92 commented 1 year ago

Hi Maxim

Thank you for clarifications and fast interactive.

now the model work without errors after set the right arguments as you mention on point 1.

but i still get wrong predictions sometimes either in (real , spoof), do you suggest any parameter tuning to make model more accurate or at least make it more prone to predict "spoof", and predict "real" when it has just very high probability.

thanks @hairymax and best regards

hairymax commented 1 year ago

Hello again @danii92 The simplest way is to consider the prediction correct only above a certain threshold. Look at the changes in the video_predict.py file - https://github.com/hairymax/Face-AntiSpoofing/commit/c328f2fae5f795146f4d1814da35c73ba5457360 Now you can pass the threshold parameter

danii92 commented 1 year ago

Hi Maxim:

I really appreciate your kind support..

thanks for (adding a threshold option), do you have any idea how can i modify code to detect (real, fake) faces on real time camera?

hairymax commented 1 year ago

I think I can close this issue, The answer to the last question is here https://github.com/hairymax/Face-AntiSpoofing/issues/2