CoolFace
Apppublic

HexB/CodeFormer

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
__init__.py24 linesDownload Raw Back to parsing
1import torch2 3from facelib.utils import load_file_from_url4from .bisenet import BiSeNet5from .parsenet import ParseNet6 7 8def init_parsing_model(model_name='bisenet', half=False, device='cuda'):9    if model_name == 'bisenet':10        model = BiSeNet(num_class=19)11        model_url = 'https://github.com/sczhou/CodeFormer/releases/download/v0.1.0/parsing_bisenet.pth'12    elif model_name == 'parsenet':13        model = ParseNet(in_size=512, out_size=512, parsing_ch=19)14        model_url = 'https://github.com/sczhou/CodeFormer/releases/download/v0.1.0/parsing_parsenet.pth'15    else:16        raise NotImplementedError(f'{model_name} is not implemented.')17 18    model_path = load_file_from_url(url=model_url, model_dir='weights/facelib', progress=True, file_name=None)19    load_net = torch.load(model_path, map_location=lambda storage, loc: storage)20    model.load_state_dict(load_net, strict=True)21    model.eval()22    model = model.to(device)23    return model24