-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathpush_to_hf.py
32 lines (24 loc) · 855 Bytes
/
push_to_hf.py
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
31
32
from guided_diffusion.models import Model
import torch
import yaml
from utils import dict2namespace
def load_pretrained_diffusion_model(config):
model = Model(config)
ckpt = "checkpoints/celeba_hq.ckpt"
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
config.device = device
model.load_state_dict(torch.load(ckpt, map_location=device))
model.to(device)
model.eval()
for param in model.parameters():
param.requires_grad = False
model = torch.nn.DataParallel(model)
return model, device
with open( "data/celeba_hq.yml", "r") as f:
config1 = yaml.safe_load(f)
config = dict2namespace(config1)
model, device = load_pretrained_diffusion_model(config)
# push to hub
model.push_to_hub("nielsr/bird-demo")
# reload
model = Model.from_pretrained("nielsr/bird-demo")