sample
Browse files
demo/examples/{CLOTHES_0_0.png → DIRTY_0_0.png}
RENAMED
File without changes
|
demo/examples/ECHOES_0_0.jpeg
DELETED
Git LFS Details
|
demo/examples/FASCINATING_0_1.jpeg
DELETED
Git LFS Details
|
demo/examples/FINNAL_0_1.jpeg
DELETED
Git LFS Details
|
demo/examples/PRESERVE_0_0.jpeg
DELETED
Git LFS Details
|
sgm/modules/diffusionmodules/sampling.py
CHANGED
@@ -251,38 +251,11 @@ class EulerEDMSampler(EDMSampler):
|
|
251 |
|
252 |
return x
|
253 |
|
254 |
-
def
|
255 |
-
"""
|
256 |
-
PASCAL VOC 分割数据集的类别标签颜色映射label colormap
|
257 |
-
|
258 |
-
返回:
|
259 |
-
可视化分割结果的颜色映射Colormap
|
260 |
-
"""
|
261 |
-
colormap = np.zeros((256, 3), dtype=int)
|
262 |
-
ind = np.arange(256, dtype=int)
|
263 |
-
|
264 |
-
for shift in reversed(range(8)):
|
265 |
-
for channel in range(3):
|
266 |
-
colormap[:, channel] |= ((ind >> channel) & 1) << shift
|
267 |
-
ind >>= 3
|
268 |
-
|
269 |
-
return colormap
|
270 |
-
|
271 |
-
def save_segment_map(self, H, W, attn_maps, tokens=None, save_name=None):
|
272 |
-
|
273 |
-
colormap = self.create_pascal_label_colormap()
|
274 |
|
275 |
sections = []
|
276 |
for i in range(len(tokens)):
|
277 |
attn_map = attn_maps[i]
|
278 |
-
attn_map_t = np.tile(attn_map[None], (1,3,1,1)) # b, 3, h, w
|
279 |
-
attn_map_t = torch.from_numpy(attn_map_t)
|
280 |
-
attn_map_t = F.interpolate(attn_map_t, (W, H))
|
281 |
-
|
282 |
-
color = torch.from_numpy(colormap[i+1][None,:,None,None] / 255.0)
|
283 |
-
colored_attn_map = attn_map_t * color
|
284 |
-
colored_attn_map = colored_attn_map.to(device=image_.device)
|
285 |
-
|
286 |
sections.append(attn_map)
|
287 |
|
288 |
section = np.stack(sections)
|
@@ -370,8 +343,7 @@ class EulerEDMSampler(EDMSampler):
|
|
370 |
local_loss = torch.zeros(1)
|
371 |
if save_attn:
|
372 |
attn_map = model.model.diffusion_model.save_attn_map(save_name=name, tokens=batch["label"][0])
|
373 |
-
|
374 |
-
self.save_segment_map(H, W, attn_map, tokens=batch["label"][0], save_name=name)
|
375 |
|
376 |
d = to_d(x, sigma_hat, denoised)
|
377 |
dt = append_dims(next_sigma - sigma_hat, x.ndim)
|
@@ -552,8 +524,7 @@ class EulerEDMDualSampler(EulerEDMSampler):
|
|
552 |
local_loss = torch.zeros(1)
|
553 |
if save_attn:
|
554 |
attn_map = model.model.diffusion_model.save_attn_map(save_name=name, save_single=True)
|
555 |
-
|
556 |
-
self.save_segment_map(H, W, attn_map, tokens=batch["label"][0], save_name=name)
|
557 |
|
558 |
d = to_d(x, sigma_hat, denoised)
|
559 |
dt = append_dims(next_sigma - sigma_hat, x.ndim)
|
|
|
251 |
|
252 |
return x
|
253 |
|
254 |
+
def save_segment_map(self, attn_maps, tokens=None, save_name=None):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
255 |
|
256 |
sections = []
|
257 |
for i in range(len(tokens)):
|
258 |
attn_map = attn_maps[i]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
259 |
sections.append(attn_map)
|
260 |
|
261 |
section = np.stack(sections)
|
|
|
343 |
local_loss = torch.zeros(1)
|
344 |
if save_attn:
|
345 |
attn_map = model.model.diffusion_model.save_attn_map(save_name=name, tokens=batch["label"][0])
|
346 |
+
self.save_segment_map(attn_map, tokens=batch["label"][0], save_name=name)
|
|
|
347 |
|
348 |
d = to_d(x, sigma_hat, denoised)
|
349 |
dt = append_dims(next_sigma - sigma_hat, x.ndim)
|
|
|
524 |
local_loss = torch.zeros(1)
|
525 |
if save_attn:
|
526 |
attn_map = model.model.diffusion_model.save_attn_map(save_name=name, save_single=True)
|
527 |
+
self.save_segment_map(attn_map, tokens=batch["label"][0], save_name=name)
|
|
|
528 |
|
529 |
d = to_d(x, sigma_hat, denoised)
|
530 |
dt = append_dims(next_sigma - sigma_hat, x.ndim)
|