-
Notifications
You must be signed in to change notification settings - Fork 117
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
What is the workflow to add a new model? #121
Comments
Hi! I can't figure out what have you missed, looks like you have done everything needed to add model. I have just committed code to support Though converting adaface model to compatible onnx took few more steps:
|
Here's conversion code: import os
import numpy as np
import torch
import onnx
import net
adaface_models = {
"ir_101": "./pretrained/adaface_ir101_webface12m.ckpt",
}
def load_pretrained_model(architecture="ir_101"):
# load model and pretrained statedict
assert architecture in adaface_models.keys()
model = net.build_model(architecture)
statedict = torch.load(
adaface_models[architecture])["state_dict"]
model_statedict = {
key[6:]: val
for key, val in statedict.items()
if key.startswith("model.")
}
model.load_state_dict(model_statedict)
model.eval()
return model
def to_input(pil_rgb_image):
np_img = np.array(pil_rgb_image)
brg_img = ((np_img[:, :, ::-1] / 255.0) - 0.5) / 0.5
tensor = torch.tensor([brg_img.transpose(2, 0, 1)]).float()
return tensor
if __name__ == "__main__":
model = load_pretrained_model("ir_101")
model.eval()
x = torch.randn(112, 112, 3)
x = to_input(x)
input_names = ['input']
output_names = ['output']
dynamic_axes = {out: {0: '?'} for out in output_names}
dynamic_axes[input_names[0]] = {
0: '?',
}
# # * For onnx model
torch.onnx.export(
model,
x,
"adaface_ir101_webface12m.onnx",
input_names=["input"],
output_names=["output"],
do_constant_folding=True,
keep_initializers_as_inputs=False,
verbose=False,
dynamic_axes=dynamic_axes,
opset_version=13,
export_params=True,
) Based on this comment: mk-minchul/AdaFace#43 (comment) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello!
Thanks for the incredible work here!
I am wondering how to add a new model to the project. I'm currently looking to work with AdaFace. I have a ONNX file that is derived from their checkpoint for R100-WebFace12M and I have tried adding it as a new model. I noticed that ArcFace expects the ONNX inputs to be under
input.1
so I modified the ONNX inputs for that as well. The outputs are 512 dimensions just as in ArcFace.By the way, AdaFace clarifies:
The main issue is that I can't run it as if it was a custom trained ArcFace model because it requires a mean of 0.5 and std of 0.5. Although that is very similar to the 127.5 that is ArcFace's default for this project.So I thought I would add another entry toconfig.py
like this:Where I declare the function
adaface_torch
inmodel_zoo/face_processors.py
as:And add it to the
func_map
inmodel_zoo/getter.py
to look like:At this point, it errors out when loading the workers with a
NameError
foradaface_torch
. I am not sure where it needs to be defined so I was wondering if you could shed a light on the general workflow needed to add additional models.The text was updated successfully, but these errors were encountered: