Skip to content

Commit 19dbebf

Browse files
committed
Updated cityscapes mock dataset code
1 parent 41d6c47 commit 19dbebf

File tree

1 file changed

+38
-25
lines changed

1 file changed

+38
-25
lines changed

test/builtin_dataset_mocks.py

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,15 +1361,21 @@ class CityScapesMockData:
13611361
def generate(cls, root, config):
13621362

13631363
mode = config.mode.capitalize()
1364-
split = config.split
1364+
req_split = config.split
13651365

1366-
if split in ["train", "train_extra"]:
1366+
if req_split in ["train", "train_extra"]:
13671367
cities = ["bochum", "bremen", "jena"]
13681368
num_samples = 3
13691369
else:
13701370
cities = ["frankfurt", "munster"]
13711371
num_samples = 2
13721372

1373+
if mode == "Fine":
1374+
splits = ["train", "test", "val"]
1375+
else:
1376+
splits = ["train", "train_extra", "val"]
1377+
1378+
# Below values are just example values and not some special values
13731379
polygon_target = {
13741380
"imgHeight": 1024,
13751381
"imgWidth": 2048,
@@ -1400,37 +1406,44 @@ def generate(cls, root, config):
14001406

14011407
gt_dir = root / f"gt{mode}"
14021408

1403-
for city in cities:
1409+
for split in splits:
1410+
for city in cities:
1411+
1412+
def make_images(file_name_fn, size=10):
1413+
create_image_folder(
1414+
root=gt_dir / split,
1415+
name=city,
1416+
file_name_fn=file_name_fn,
1417+
size=size,
1418+
num_examples=num_samples,
1419+
)
1420+
1421+
make_images(lambda idx: f"{city}_000000_{idx:06d}_gt{mode}_instanceIds.png")
1422+
make_images(lambda idx: f"{city}_000000_{idx:06d}_gt{mode}_labelIds.png")
1423+
make_images(lambda idx: f"{city}_000000_{idx:06d}_gt{mode}_color.png", size=(4, 10, 10))
14041424

1405-
def make_images(file_name_fn, size=10):
1425+
for idx in range(num_samples):
1426+
polygon_target_name = gt_dir / split / city / f"{city}_000000_{idx:06d}_gt{mode}_polygons.json"
1427+
with open(polygon_target_name, "w") as outfile:
1428+
json.dump(polygon_target, outfile)
1429+
1430+
# Create leftImg8bit folder
1431+
for city in cities:
14061432
create_image_folder(
1407-
root=gt_dir / split,
1433+
root=root / "leftImg8bit" / split,
14081434
name=city,
1409-
file_name_fn=file_name_fn,
1410-
size=size,
1435+
file_name_fn=lambda idx: f"{city}_000000_{idx:06d}_leftImg8bit.png",
14111436
num_examples=num_samples,
14121437
)
14131438

1414-
make_images(lambda idx: f"{city}_000000_{idx:06d}_gt{mode}_instanceIds.png")
1415-
make_images(lambda idx: f"{city}_000000_{idx:06d}_gt{mode}_labelIds.png")
1416-
make_images(lambda idx: f"{city}_000000_{idx:06d}_gt{mode}_color.png", size=(4, 10, 10))
1417-
1418-
for idx in range(num_samples):
1419-
polygon_target_name = gt_dir / split / city / f"{city}_000000_{idx:06d}_gt{mode}_polygons.json"
1420-
with open(polygon_target_name, "w") as outfile:
1421-
json.dump(polygon_target, outfile)
1439+
for zip_name, folder_name in cls._ARCHIVE_NAMES[(mode, req_split)]:
1440+
# Create dummy README and license.txt
1441+
for filename in ["README", "license.txt"]:
1442+
with (root / filename).open("w") as handler:
1443+
handler.write("Content\n")
14221444

1423-
# Create leftImg8bit folder
1424-
for city in cities:
1425-
create_image_folder(
1426-
root=root / "leftImg8bit" / split,
1427-
name=city,
1428-
file_name_fn=lambda idx: f"{city}_000000_{idx:06d}_leftImg8bit.png",
1429-
num_examples=num_samples,
1430-
)
1445+
make_zip(root, zip_name, folder_name, root / "README", root / "license.txt")
14311446

1432-
for zip_name, folder_name in cls._ARCHIVE_NAMES[(mode, split)]:
1433-
make_zip(root, zip_name, folder_name)
14341447
return len(cities) * num_samples
14351448

14361449

0 commit comments

Comments
 (0)