Datasets:
Tasks:
Image Classification
Sub-tasks:
multi-class-image-classification
Languages:
English
Size:
1M<n<10M
ArXiv:
License:
Update ForNet.py
Browse filesadd fg_in_nonant and fg_size_fact
ForNet.py
CHANGED
@@ -1073,6 +1073,8 @@ class RecombineDataset(Dataset):
|
|
1073 |
mask_smoothing_sigma,
|
1074 |
rel_jut_out,
|
1075 |
orig_img_prob,
|
|
|
|
|
1076 |
**kwargs,
|
1077 |
):
|
1078 |
"""Create the ForNet recombination dataset.
|
@@ -1099,6 +1101,7 @@ class RecombineDataset(Dataset):
|
|
1099 |
"orig",
|
1100 |
], f"Invalid background_combination {background_combination}"
|
1101 |
assert fg_size_mode in ["range", "min", "max", "mean"], f"Invalid fg_size_mode {fg_size_mode}"
|
|
|
1102 |
self.background_combination = background_combination
|
1103 |
self.fg_scale_jitter = fg_scale_jitter
|
1104 |
self.pruning_ratio = pruning_ratio
|
@@ -1110,6 +1113,8 @@ class RecombineDataset(Dataset):
|
|
1110 |
self.epochs = 0
|
1111 |
self._epoch = 0
|
1112 |
self.cls_to_idx = {}
|
|
|
|
|
1113 |
|
1114 |
bg_rat_indices = super()._getitem(0)["bg_rat_idx_file"]
|
1115 |
self.train = "train" in bg_rat_indices.split("/")[-1]
|
@@ -1177,6 +1182,9 @@ class RecombineDataset(Dataset):
|
|
1177 |
bg_img = bg_item["bg"].convert("RGB")
|
1178 |
bg_size = bg_img.size
|
1179 |
bg_area = bg_size[0] * bg_size[1]
|
|
|
|
|
|
|
1180 |
orig_fg_ratio = fg_item["fg/bg_area"]
|
1181 |
bg_fg_ratio = bg_item["fg/bg_area"]
|
1182 |
|
@@ -1198,6 +1206,7 @@ class RecombineDataset(Dataset):
|
|
1198 |
goal_fg_ratio_lower * (1 - self.fg_scale_jitter), goal_fg_ratio_upper * (1 + self.fg_scale_jitter)
|
1199 |
)
|
1200 |
/ fg_size_factor
|
|
|
1201 |
)
|
1202 |
|
1203 |
goal_shape_y = round(np.sqrt(bg_area * fg_scale * fg_img.size[1] / fg_img.size[0]))
|
@@ -1228,6 +1237,12 @@ class RecombineDataset(Dataset):
|
|
1228 |
y_min = -self.rel_jut_out * fg_img.size[1]
|
1229 |
y_max = bg_size[1] - fg_img.size[1] * (1 - self.rel_jut_out)
|
1230 |
|
|
|
|
|
|
|
|
|
|
|
|
|
1231 |
if x_min > x_max:
|
1232 |
x_min = x_max = (x_min + x_max) / 2
|
1233 |
if y_min > y_max:
|
@@ -1262,6 +1277,8 @@ _CONFIG_HASH_IGNORE_KWARGS = [
|
|
1262 |
"mask_smoothing_sigma",
|
1263 |
"rel_jut_out",
|
1264 |
"orig_img_prob",
|
|
|
|
|
1265 |
]
|
1266 |
|
1267 |
|
@@ -1278,6 +1295,8 @@ class ForNetConfig(datasets.BuilderConfig):
|
|
1278 |
mask_smoothing_sigma,
|
1279 |
rel_jut_out,
|
1280 |
orig_img_prob,
|
|
|
|
|
1281 |
**kwargs,
|
1282 |
):
|
1283 |
"""BuilderConfig for ForNet.
|
@@ -1294,6 +1313,8 @@ class ForNetConfig(datasets.BuilderConfig):
|
|
1294 |
self.mask_smoothing_sigma = mask_smoothing_sigma
|
1295 |
self.rel_jut_out = rel_jut_out
|
1296 |
self.orig_img_prob = orig_img_prob
|
|
|
|
|
1297 |
|
1298 |
def __str__(self):
|
1299 |
return f"ForNetConfig(name={self.name}, version={self.version}, data_dir={self.data_dir}, data_files={self.data_files}, description={self.description}, background_combination={self.background_combination}, fg_scale_jitter={self.fg_scale_jitter}, pruning_ratio={self.pruning_ratio}, fg_size_mode={self.fg_size_mode}, fg_bates_n={self.fg_bates_n}, mask_smoothing_sigma={self.mask_smoothing_sigma}, rel_jut_out={self.rel_jut_out}, orig_img_prob={self.orig_img_prob})"
|
@@ -1608,6 +1629,8 @@ class ForNet(datasets.GeneratorBasedBuilder):
|
|
1608 |
mask_smoothing_sigma=self.config.mask_smoothing_sigma,
|
1609 |
rel_jut_out=self.config.rel_jut_out,
|
1610 |
orig_img_prob=self.config.orig_img_prob,
|
|
|
|
|
1611 |
**dataset_kwargs,
|
1612 |
)
|
1613 |
|
|
|
1073 |
mask_smoothing_sigma,
|
1074 |
rel_jut_out,
|
1075 |
orig_img_prob,
|
1076 |
+
fg_in_nonant=None,
|
1077 |
+
size_fact=1.0,
|
1078 |
**kwargs,
|
1079 |
):
|
1080 |
"""Create the ForNet recombination dataset.
|
|
|
1101 |
"orig",
|
1102 |
], f"Invalid background_combination {background_combination}"
|
1103 |
assert fg_size_mode in ["range", "min", "max", "mean"], f"Invalid fg_size_mode {fg_size_mode}"
|
1104 |
+
assert fg_in_nonant is None or -1 <= fg_in_nonant < 9, f"fg_in_nonant={fg_in_nonant} not in [0, 8] or None"
|
1105 |
self.background_combination = background_combination
|
1106 |
self.fg_scale_jitter = fg_scale_jitter
|
1107 |
self.pruning_ratio = pruning_ratio
|
|
|
1113 |
self.epochs = 0
|
1114 |
self._epoch = 0
|
1115 |
self.cls_to_idx = {}
|
1116 |
+
self.fg_in_nonant = fg_in_nonant
|
1117 |
+
self.size_fact = size_fact
|
1118 |
|
1119 |
bg_rat_indices = super()._getitem(0)["bg_rat_idx_file"]
|
1120 |
self.train = "train" in bg_rat_indices.split("/")[-1]
|
|
|
1182 |
bg_img = bg_item["bg"].convert("RGB")
|
1183 |
bg_size = bg_img.size
|
1184 |
bg_area = bg_size[0] * bg_size[1]
|
1185 |
+
if self.fg_in_nonant is not None:
|
1186 |
+
bg_area = bg_area / 9
|
1187 |
+
|
1188 |
orig_fg_ratio = fg_item["fg/bg_area"]
|
1189 |
bg_fg_ratio = bg_item["fg/bg_area"]
|
1190 |
|
|
|
1206 |
goal_fg_ratio_lower * (1 - self.fg_scale_jitter), goal_fg_ratio_upper * (1 + self.fg_scale_jitter)
|
1207 |
)
|
1208 |
/ fg_size_factor
|
1209 |
+
* self.size_fact
|
1210 |
)
|
1211 |
|
1212 |
goal_shape_y = round(np.sqrt(bg_area * fg_scale * fg_img.size[1] / fg_img.size[0]))
|
|
|
1237 |
y_min = -self.rel_jut_out * fg_img.size[1]
|
1238 |
y_max = bg_size[1] - fg_img.size[1] * (1 - self.rel_jut_out)
|
1239 |
|
1240 |
+
if self.fg_in_nonant is not None and self.fg_in_nonant >= 0:
|
1241 |
+
x_min = (self.fg_in_nonant % 3) * bg_size[0] / 3
|
1242 |
+
x_max = ((self.fg_in_nonant % 3) + 1) * bg_size[0] / 3 - fg_img.size[0]
|
1243 |
+
y_min = (self.fg_in_nonant // 3) * bg_size[1] / 3
|
1244 |
+
y_max = ((self.fg_in_nonant // 3) + 1) * bg_size[1] / 3 - fg_img.size[1]
|
1245 |
+
|
1246 |
if x_min > x_max:
|
1247 |
x_min = x_max = (x_min + x_max) / 2
|
1248 |
if y_min > y_max:
|
|
|
1277 |
"mask_smoothing_sigma",
|
1278 |
"rel_jut_out",
|
1279 |
"orig_img_prob",
|
1280 |
+
"fg_in_nonant",
|
1281 |
+
"size_fact",
|
1282 |
]
|
1283 |
|
1284 |
|
|
|
1295 |
mask_smoothing_sigma,
|
1296 |
rel_jut_out,
|
1297 |
orig_img_prob,
|
1298 |
+
fg_in_nonant=None,
|
1299 |
+
size_fact=1.0,
|
1300 |
**kwargs,
|
1301 |
):
|
1302 |
"""BuilderConfig for ForNet.
|
|
|
1313 |
self.mask_smoothing_sigma = mask_smoothing_sigma
|
1314 |
self.rel_jut_out = rel_jut_out
|
1315 |
self.orig_img_prob = orig_img_prob
|
1316 |
+
self.fg_in_nonant = fg_in_nonant
|
1317 |
+
self.size_fact = size_fact
|
1318 |
|
1319 |
def __str__(self):
|
1320 |
return f"ForNetConfig(name={self.name}, version={self.version}, data_dir={self.data_dir}, data_files={self.data_files}, description={self.description}, background_combination={self.background_combination}, fg_scale_jitter={self.fg_scale_jitter}, pruning_ratio={self.pruning_ratio}, fg_size_mode={self.fg_size_mode}, fg_bates_n={self.fg_bates_n}, mask_smoothing_sigma={self.mask_smoothing_sigma}, rel_jut_out={self.rel_jut_out}, orig_img_prob={self.orig_img_prob})"
|
|
|
1629 |
mask_smoothing_sigma=self.config.mask_smoothing_sigma,
|
1630 |
rel_jut_out=self.config.rel_jut_out,
|
1631 |
orig_img_prob=self.config.orig_img_prob,
|
1632 |
+
fg_in_nonant=self.config.fg_in_nonant,
|
1633 |
+
size_fact=self.config.size_fact,
|
1634 |
**dataset_kwargs,
|
1635 |
)
|
1636 |
|