File size: 926 Bytes
1ea89dd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
dependencies = ["torch", "huggingface_hub"]

import os
import json

import torch
import huggingface_hub

from unik3d.models import UniK3D as UniK3D_

BACKBONES = ["vitl", "vitb", "vits"]


def UniK3D(backbone="vitl", pretrained=True):
    assert backbone in BACKBONES, f"backbone must be one of {BACKBONES}"
    repo_dir = os.path.dirname(os.path.realpath(__file__))
    with open(os.path.join(repo_dir, "configs", f"config_{backbone}.json")) as f:
        config = json.load(f)
    
    model = UniK3D_(config)
    if pretrained:
        path = huggingface_hub.hf_hub_download(repo_id=f"lpiccinelli/unik3d-{backbone}", filename=f"pytorch_model.bin", repo_type="model")
        info = model.load_state_dict(torch.load(path), strict=False)
        print(f"UniK3D-{backbone} is loaded with:")
        print(f"\t missing keys: {info.missing_keys}")
        print(f"\t additional keys: {info.unexpected_keys}")

    return model