Meehai commited on
Commit
f518336
·
1 Parent(s): 7013b7b
scripts/dronescapes_viewer/dronescapes_viewer.ipynb CHANGED
The diff for this file is too large to render. See raw diff
 
scripts/dronescapes_viewer/dronescapes_viewer.py CHANGED
@@ -15,6 +15,7 @@ import torch as tr
15
  from media_processing_lib.collage_maker import collage_fn
16
  from media_processing_lib.image import image_add_title, image_write
17
  import matplotlib.pyplot as plt
 
18
 
19
  from dronescapes_representations import get_dronescapes_task_types
20
 
@@ -23,7 +24,12 @@ def plot_one(data: dict[str, tr.Tensor], title: str, name_to_task: dict[str, Rep
23
  def vre_plot_fn(rgb: tr.Tensor, x: tr.Tensor, node: Representation) -> np.ndarray:
24
  node.data = ReprOut(rgb.cpu().detach().numpy()[None], MemoryData(x.cpu().detach().numpy()[None]), [0])
25
  return node.make_images()[0]
26
- img_data = {k: vre_plot_fn(data["rgb"], v, name_to_task[k]) for k, v in data.items()}
 
 
 
 
 
27
  img_data = reorder_dict(img_data, order) if order is not None else img_data
28
  titles = [title if len(title) < 40 else f"{title[0:19]}..{title[-19:]}" for title in img_data]
29
  collage = collage_fn(list(img_data.values()), titles=titles, size_px=40)
@@ -33,7 +39,8 @@ def plot_one(data: dict[str, tr.Tensor], title: str, name_to_task: dict[str, Rep
33
  data_path = "../../data/test_set"
34
  stats_path = "../../data/train_set/.task_statistics.npz"
35
  dronescapes_task_types = get_dronescapes_task_types(include_semantics_original=False, include_gt=True, include_ci=False)
36
- reader = MultiTaskDataset(data_path, task_names=list(dronescapes_task_types),
 
37
  task_types=dronescapes_task_types, handle_missing_data="fill_nan",
38
  normalization="min_max", cache_task_stats=True, batch_size_stats=300,
39
  statistics=np.load(stats_path, allow_pickle=True)["arr_0"].item())
@@ -50,4 +57,5 @@ collage = plot_one(data, title=name, name_to_task=reader.name_to_task)
50
  print(lo(collage))
51
  # plt.figure(figsize=(20, 10))
52
  # plt.imshow(collage)
53
- image_write(collage, f"collage_{name[0:-4]}.png")
 
 
15
  from media_processing_lib.collage_maker import collage_fn
16
  from media_processing_lib.image import image_add_title, image_write
17
  import matplotlib.pyplot as plt
18
+ from datetime import datetime
19
 
20
  from dronescapes_representations import get_dronescapes_task_types
21
 
 
24
  def vre_plot_fn(rgb: tr.Tensor, x: tr.Tensor, node: Representation) -> np.ndarray:
25
  node.data = ReprOut(rgb.cpu().detach().numpy()[None], MemoryData(x.cpu().detach().numpy()[None]), [0])
26
  return node.make_images()[0]
27
+ img_data = {}
28
+ keys = np.random.permutation(list(data.keys()))
29
+ for k in keys:
30
+ start = datetime.now()
31
+ img_data[k] = vre_plot_fn(data["rgb"], data[k], name_to_task[k])
32
+ print(k, (datetime.now() - start).total_seconds())
33
  img_data = reorder_dict(img_data, order) if order is not None else img_data
34
  titles = [title if len(title) < 40 else f"{title[0:19]}..{title[-19:]}" for title in img_data]
35
  collage = collage_fn(list(img_data.values()), titles=titles, size_px=40)
 
39
  data_path = "../../data/test_set"
40
  stats_path = "../../data/train_set/.task_statistics.npz"
41
  dronescapes_task_types = get_dronescapes_task_types(include_semantics_original=False, include_gt=True, include_ci=False)
42
+ task_names = ["rgb", "semantic_mask2former_r50_mapillary_converted", "semantic_mask2former_swin_coco_converted"]
43
+ reader = MultiTaskDataset(data_path, task_names=task_names,
44
  task_types=dronescapes_task_types, handle_missing_data="fill_nan",
45
  normalization="min_max", cache_task_stats=True, batch_size_stats=300,
46
  statistics=np.load(stats_path, allow_pickle=True)["arr_0"].item())
 
57
  print(lo(collage))
58
  # plt.figure(figsize=(20, 10))
59
  # plt.imshow(collage)
60
+ image_write(collage, out_path := f"collage_{name[0:-4]}.png")
61
+ print(f"Stored at '{out_path}'")