ZYMPKU commited on
Commit
f0def4f
1 Parent(s): bf50ebc
demo/examples/{CLOTHES_0_0.png → DIRTY_0_0.png} RENAMED
File without changes
demo/examples/ECHOES_0_0.jpeg DELETED

Git LFS Details

  • SHA256: 0ade75487cac60d88684e41b8ddfcd492f386f22eeb8bb67f1d99a2514803477
  • Pointer size: 131 Bytes
  • Size of remote file: 286 kB
demo/examples/FASCINATING_0_1.jpeg DELETED

Git LFS Details

  • SHA256: af5ea76ba8c5827f9ec83bc2b6a096511bc619975db5fc8f6e742ba1bb687570
  • Pointer size: 131 Bytes
  • Size of remote file: 311 kB
demo/examples/FINNAL_0_1.jpeg DELETED

Git LFS Details

  • SHA256: e6dc56ca1ba9a1fc5e6899a9629a06d843ca10a96f5eca095c0cf1af9e38191a
  • Pointer size: 131 Bytes
  • Size of remote file: 176 kB
demo/examples/PRESERVE_0_0.jpeg DELETED

Git LFS Details

  • SHA256: e5608fe1a2ccd04f18ba8a24172bd484bf2a628e21756fb5121283cad9618f60
  • Pointer size: 131 Bytes
  • Size of remote file: 296 kB
sgm/modules/diffusionmodules/sampling.py CHANGED
@@ -251,38 +251,11 @@ class EulerEDMSampler(EDMSampler):
251
 
252
  return x
253
 
254
- def create_pascal_label_colormap(self):
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
- H, W = batch["target_size_as_tuple"][0]
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
- H, W = batch["target_size_as_tuple"][0]
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)