Pytorch InsightFace

August 4, 2019 ยท View on GitHub

Pretrained ResNet models from deepinsight/insightface ported to pytorch.

ModelLFW(%)CFP-FP(%)AgeDB-30(%)MegaFace(%)
iresnet3499.6592.1297.7096.70
iresnet5099.8092.7497.7697.64
iresnet10099.7798.2798.2898.47

Installation

pip install git+https://github.com/nizhib/pytorch-insightface

Usage

import torch
from imageio import imread
from torchvision import transforms

import insightface

embedder = insightface.iresnet100(pretrained=True)
embedder.eval()

mean = [0.5] * 3
std = [0.5 * 256 / 255] * 3
preprocess = transforms.Compose([
    transforms.ToTensor(),
    transforms.Normalize(mean, std)
])

face = imread('resource/sample.jpg')

tensor = preprocess(face)

with torch.no_grad():
    features = embedder(tensor.unsqueeze(0))[0]

print(features[:5])

Recreating the weights locally

Download the original insightface zoo weights and place *.params and *.json files to resource/{model}.

Run python scripts/convert.py to convert and test pytorch weights.