Spaces:
Runtime error
Runtime error
HongFangzhou
commited on
Commit
β’
7c8c180
1
Parent(s):
fe189ee
update app.py
Browse files
app.py
CHANGED
@@ -52,7 +52,8 @@ def add_text(rgb, caption):
|
|
52 |
return rgb
|
53 |
|
54 |
config = "3DTopia/configs/default.yaml"
|
55 |
-
local_ckpt = "3DTopia/checkpoints/3dtopia_diffusion_state_dict.ckpt"
|
|
|
56 |
if os.path.exists(local_ckpt):
|
57 |
ckpt = local_ckpt
|
58 |
else:
|
@@ -62,56 +63,65 @@ configs = OmegaConf.load(config)
|
|
62 |
os.makedirs("tmp", exist_ok=True)
|
63 |
print("download finish")
|
64 |
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
print("download finish")
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
|
116 |
print("download finish")
|
117 |
def marching_cube(b, text, global_info):
|
|
|
52 |
return rgb
|
53 |
|
54 |
config = "3DTopia/configs/default.yaml"
|
55 |
+
# local_ckpt = "3DTopia/checkpoints/3dtopia_diffusion_state_dict.ckpt"
|
56 |
+
local_ckpt = "/data/3DTopia_all/3DTopia_code/checkpoints/model.safetensors"
|
57 |
if os.path.exists(local_ckpt):
|
58 |
ckpt = local_ckpt
|
59 |
else:
|
|
|
63 |
os.makedirs("tmp", exist_ok=True)
|
64 |
print("download finish")
|
65 |
|
66 |
+
import sys
|
67 |
+
import traceback
|
68 |
+
|
69 |
+
try:
|
70 |
+
if ckpt.endswith(".ckpt"):
|
71 |
+
model = get_obj_from_str(configs.model["target"]).load_from_checkpoint(ckpt, map_location='cpu', strict=False, **configs.model.params)
|
72 |
+
elif ckpt.endswith(".safetensors"):
|
73 |
+
print("download finish")
|
74 |
+
model = get_obj_from_str(configs.model["target"])(**configs.model.params)
|
75 |
+
print("download finish")
|
76 |
+
model_ckpt = load_file(ckpt)
|
77 |
+
print("download finish")
|
78 |
+
model.load_state_dict(model_ckpt)
|
79 |
+
print("download finish")
|
80 |
+
else:
|
81 |
+
raise NotImplementedError
|
82 |
+
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
|
83 |
+
model = model.to(device)
|
84 |
print("download finish")
|
85 |
+
sampler = DDIMSampler(model)
|
86 |
+
|
87 |
+
img_size = configs.model.params.unet_config.params.image_size
|
88 |
+
channels = configs.model.params.unet_config.params.in_channels
|
89 |
+
shape = [channels, img_size, img_size * 3]
|
90 |
+
|
91 |
+
pose_folder = '3DTopia/assets/sample_data/pose'
|
92 |
+
poses_fname = sorted([os.path.join(pose_folder, f) for f in os.listdir(pose_folder)])
|
93 |
+
batch_rays_list = []
|
94 |
+
H = 128
|
95 |
+
ratio = 512 // H
|
96 |
+
for p in poses_fname:
|
97 |
+
c2w = np.loadtxt(p).reshape(4, 4)
|
98 |
+
c2w[:3, 3] *= 2.2
|
99 |
+
c2w = np.array([
|
100 |
+
[1, 0, 0, 0],
|
101 |
+
[0, 0, -1, 0],
|
102 |
+
[0, 1, 0, 0],
|
103 |
+
[0, 0, 0, 1]
|
104 |
+
]) @ c2w
|
105 |
+
|
106 |
+
k = np.array([
|
107 |
+
[560 / ratio, 0, H * 0.5],
|
108 |
+
[0, 560 / ratio, H * 0.5],
|
109 |
+
[0, 0, 1]
|
110 |
+
])
|
111 |
+
|
112 |
+
rays_o, rays_d = get_rays(H, H, torch.Tensor(k), torch.Tensor(c2w[:3, :4]))
|
113 |
+
coords = torch.stack(torch.meshgrid(torch.linspace(0, H-1, H), torch.linspace(0, H-1, H), indexing='ij'), -1)
|
114 |
+
coords = torch.reshape(coords, [-1,2]).long()
|
115 |
+
rays_o = rays_o[coords[:, 0], coords[:, 1]]
|
116 |
+
rays_d = rays_d[coords[:, 0], coords[:, 1]]
|
117 |
+
batch_rays = torch.stack([rays_o, rays_d], 0)
|
118 |
+
batch_rays_list.append(batch_rays)
|
119 |
+
batch_rays_list = torch.stack(batch_rays_list, 0)
|
120 |
+
except Exception as e:
|
121 |
+
print(e)
|
122 |
+
print(traceback.format_exc())
|
123 |
+
print(sys.exc_info()[2])
|
124 |
+
|
125 |
|
126 |
print("download finish")
|
127 |
def marching_cube(b, text, global_info):
|