TNauen commited on
Commit
5e0bd35
·
verified ·
1 Parent(s): a763881

fix error of sometimes having ints in cls_to_idx maps

Browse files
Files changed (1) hide show
  1. ForNet.py +15 -6
ForNet.py CHANGED
@@ -1134,9 +1134,17 @@ class RecombineDataset(Dataset):
1134
  for in_cls in bg_rat_indices:
1135
  if in_cls not in self.cls_to_idx:
1136
  self.cls_to_idx[in_cls] = []
1137
- for idx, rat in bg_rat_indices[in_cls]:
1138
- if rat < self.pruning_ratio:
1139
- self.cls_to_idx[in_cls].append(idx)
 
 
 
 
 
 
 
 
1140
  except (TypeError, KeyError, OSError):
1141
  logger.warning(
1142
  f"Could not load background ratio indices from {bg_rat_indices}. Will do pruning and background selection on the fly. This will take more time in the first few epochs"
@@ -1476,7 +1484,6 @@ class ForNet(datasets.GeneratorBasedBuilder):
1476
  "bg_rat_idx_file": datasets.Value("string"),
1477
  }
1478
  ),
1479
- supervised_keys=("image", "label"),
1480
  homepage=_HOMEPAGE,
1481
  citation=_CITATION,
1482
  )
@@ -1541,6 +1548,9 @@ class ForNet(datasets.GeneratorBasedBuilder):
1541
  class_to_zipfile[name.split("/")[-2]] = f
1542
  file_ending = "pkl" if name.endswith(".pkl") else "pkl.gz"
1543
  name_start = "/".join(name.split("/")[:-2])
 
 
 
1544
  if len(name_start) > 0:
1545
  name_start += "/"
1546
  logger.info(f"Loading extra information: {hf_indices}, {fg_bg_ratios}")
@@ -1629,7 +1639,7 @@ class ForNet(datasets.GeneratorBasedBuilder):
1629
  in_cls = data["path"].split("/")[0]
1630
  if in_cls not in cls_to_idx:
1631
  cls_to_idx[in_cls] = []
1632
- cls_to_idx[in_cls].append(foraug_idx)
1633
  yield foraug_idx, data
1634
  foraug_idx += 1
1635
  tqdm.write(f"Done generating {split} examples. Saving cls_to_idx file at '{cls_to_idx_loc}'.")
@@ -1793,4 +1803,3 @@ def _zip_loader(
1793
  "fg/bg_area": fg_bg_ratios[patch_name],
1794
  }
1795
  )
1796
-
 
1134
  for in_cls in bg_rat_indices:
1135
  if in_cls not in self.cls_to_idx:
1136
  self.cls_to_idx[in_cls] = []
1137
+ for data in bg_rat_indices[in_cls]:
1138
+ if isinstance(data, int):
1139
+ self.cls_to_idx[in_cls].append(data)
1140
+ elif isinstance(data, list):
1141
+ idx, rat = data
1142
+ if rat < self.pruning_ratio:
1143
+ self.cls_to_idx[in_cls].append(idx)
1144
+ else:
1145
+ raise TypeError(
1146
+ f"expected entries to be [int, float] (or int), but got {data} ({type(data )}"
1147
+ )
1148
  except (TypeError, KeyError, OSError):
1149
  logger.warning(
1150
  f"Could not load background ratio indices from {bg_rat_indices}. Will do pruning and background selection on the fly. This will take more time in the first few epochs"
 
1484
  "bg_rat_idx_file": datasets.Value("string"),
1485
  }
1486
  ),
 
1487
  homepage=_HOMEPAGE,
1488
  citation=_CITATION,
1489
  )
 
1548
  class_to_zipfile[name.split("/")[-2]] = f
1549
  file_ending = "pkl" if name.endswith(".pkl") else "pkl.gz"
1550
  name_start = "/".join(name.split("/")[:-2])
1551
+ else:
1552
+ name_start = ""
1553
+ file_ending = "pkl" if patch_files[0].startswith("train") else "pkl.gz"
1554
  if len(name_start) > 0:
1555
  name_start += "/"
1556
  logger.info(f"Loading extra information: {hf_indices}, {fg_bg_ratios}")
 
1639
  in_cls = data["path"].split("/")[0]
1640
  if in_cls not in cls_to_idx:
1641
  cls_to_idx[in_cls] = []
1642
+ cls_to_idx[in_cls].append((foraug_idx, data["fg/bg_area"]))
1643
  yield foraug_idx, data
1644
  foraug_idx += 1
1645
  tqdm.write(f"Done generating {split} examples. Saving cls_to_idx file at '{cls_to_idx_loc}'.")
 
1803
  "fg/bg_area": fg_bg_ratios[patch_name],
1804
  }
1805
  )