CoolFace
Apppublic

otmanheddouch/house_design

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
__init__.py28 linesDownload Raw Back to uniformer
1# Uniformer2# From https://github.com/Sense-X/UniFormer3# # Apache-2.0 license4 5import os6 7from annotator.uniformer.mmseg.apis import init_segmentor, inference_segmentor, show_result_pyplot8from annotator.uniformer.mmseg.core.evaluation import get_palette9from annotator.util import annotator_ckpts_path10 11 12checkpoint_file = "https://huggingface.co/lllyasviel/ControlNet/resolve/main/annotator/ckpts/upernet_global_small.pth"13 14 15class UniformerDetector:16    def __init__(self):17        modelpath = os.path.join(annotator_ckpts_path, "upernet_global_small.pth")18        if not os.path.exists(modelpath):19            from basicsr.utils.download_util import load_file_from_url20            load_file_from_url(checkpoint_file, model_dir=annotator_ckpts_path)21        config_file = os.path.join(os.path.dirname(annotator_ckpts_path), "uniformer", "exp", "upernet_global_small", "config.py")22        self.model = init_segmentor(config_file, modelpath).cuda()23 24    def __call__(self, img):25        result = inference_segmentor(self.model, img)26        res_img = show_result_pyplot(self.model, img, result, get_palette('ade'), opacity=1)27        return res_img28