IrvingMeng / MagFace

MagFace: A Universal Representation for Face Recognition and Quality Assessment, CVPR2021, Oral
Apache License 2.0
615 stars 87 forks source link

Documentation for usage - Cuda error #46

Open oliversunde opened 2 years ago

oliversunde commented 2 years ago

Hey, I have for some hours now tried to use MagFace with no luck. I want to take a lot of images, check the image quality regarding biometric features and print that data. However, I get the RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.

Is there a tutorial/documentation for how to use MagFace with all prerequisites?

Thank you

IrvingMeng commented 2 years ago

Hi,

You can add the param '--cpu-mode' to run the code on a CPU-only machine. For example, use python3 gen_feat.py --cpu-mode ... instead of python3 gen_feat.py ... in this example.

oliversunde commented 2 years ago

Thank you Irving!

How do you calculate the feat.list?

IrvingMeng commented 2 years ago

feat.list is generated by the command python3 gen_feat.py --inf_list toy_imgs/img.list --feat_list toy_imgs/feat.list --resume magface_epoch_00025.pth --cpu-mode

oliversunde commented 2 years ago

Thank you so so so much Irving! I have managed to calculate the feat.list, The script generates the mean quality score and I have a folder with 500 images where I want to get each single image's quality score. Is it possible to edit the

python3 gen_feat.py --inf_list toy_imgs/img.list --feat_list toy_imgs/feat.list --resume magface_epoch_00025.pth --cpu-mode to make it print that score on the run or is it another way around?

IrvingMeng commented 2 years ago

The script does not generate the mean quality score. It generates the feature embedding for each image. Here is an example : https://github.com/IrvingMeng/MagFace/blob/main/inference/toy_imgs/feat.list#L1-L10

oliversunde commented 2 years ago

Extract Features: [0/1] Time 8.675 ( 8.675) Data 0.133 ( 0.133)

What does "Data" in this section mean?

IrvingMeng commented 2 years ago

The duration for loading data[1].

[1] https://github.com/IrvingMeng/MagFace/blob/main/inference/gen_feat.py#L134-L135

oliversunde commented 2 years ago

Thank you so much Irving!

I am printing "mag" in ln4 which produces the 10 feature magnitudes - how do I collect an image's quality measurement? I get the pink visual recognition after ln9, but I am not really understanding it unfortunately Further I am getting this error in the "ln6" part of the script:


TypeError Traceback (most recent call last)

in 6 imgname = '/'.join(imgnames[ele].split('/')[-2:]) 7 img = cv2.imread(imgname) ----> 8 canvas[int(i / NW) * H: (int(i / NW) + 1) * H, (i % NW) * W: ((i % NW) + 1) * W, :] = img TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
IrvingMeng commented 2 years ago

Magnitudes are quality measurements. That is well described in our paper.

For the error, the TypeError states that int() gets NoneType inputs. This shouldn't be hard to debug. You just need to check whether the inputs are valid.