-
Notifications
You must be signed in to change notification settings - Fork 61
/
demo.py
45 lines (41 loc) · 1.56 KB
/
demo.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
33
34
35
36
37
38
39
40
41
42
43
44
45
# Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# NVIDIA CORPORATION & AFFILIATES and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and related documentation without an express
# license agreement from NVIDIA CORPORATION & AFFILIATES is strictly prohibited.
"""
require diffusers-0.11.1
"""
import os
import clip
import torch
from PIL import Image
from default_config import cfg as config
from models.lion import LION
from utils.vis_helper import plot_points
from huggingface_hub import hf_hub_download
model_path = './lion_ckpt/text2shape/chair/checkpoints/model.pt'
model_config = './lion_ckpt/text2shape/chair/cfg.yml'
config.merge_from_file(model_config)
lion = LION(config)
lion.load_model(model_path)
if config.clipforge.enable:
input_t = ["a swivel chair, five wheels"]
device_str = 'cuda'
clip_model, clip_preprocess = clip.load(
config.clipforge.clip_model, device=device_str)
text = clip.tokenize(input_t).to(device_str)
clip_feat = []
clip_feat.append(clip_model.encode_text(text).float())
clip_feat = torch.cat(clip_feat, dim=0)
print('clip_feat', clip_feat.shape)
else:
clip_feat = None
output = lion.sample(1 if clip_feat is None else clip_feat.shape[0], clip_feat=clip_feat)
pts = output['points']
img_name = "/tmp/tmp.png"
plot_points(pts, output_name=img_name)
img = Image.open(img_name)
img.show()