IrvingMeng / MagFace

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

onnx conversion #32

Open fisakhan opened 2 years ago

fisakhan commented 2 years ago

I converted the the torch model (magface_epoch_00025.pth) to onnx (magface_epoch_00025.onnx) and used in opencv but the extracted embedding does not match with that of torch version. What am I doing woring?

I converted the pre-trained model to onnx model using the following code:

onnx_model_path = 'magface_epoch_00025.onnx'
# Create some sample input in the shape this model expects 
# This is needed because the conversion forward pass the network once 
dummy_input = torch.randn(1, 3, 112, 112, device='cuda')
torch.onnx.export(model.module, dummy_input, onnx_model_path, verbose=True)

I then try to use it in opencv dnn with the following code:

net =  cv2.dnn.readNetFromONNX(onnx_model_path) 
image = cv2.imread(image_path)
blob = cv2.dnn.blobFromImage(image, 1.0, (112,112),(0, 0, 0), swapRB=True, crop=False)
net.setInput(blob)
featcv = net.forward()
IrvingMeng commented 2 years ago

Hi,

I am not familiar with the onnx conversion so unable to solve the issue. Sorry for not helping :(

Best, Qiang

tonhathuy commented 2 years ago

I converted this model to onnx and tensorRT , checkout my repo.