Skip to content

Commit b520dd7

Browse files
authored
Merge pull request #304 from JdeRobot/issue-303
Update examples
2 parents 608d4db + 53ce66f commit b520dd7

File tree

4 files changed

+77
-6
lines changed

4 files changed

+77
-6
lines changed

examples/convert_dataset_ontology.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,16 @@ def parse_args():
3030
required=True,
3131
help="Directory to save the new dataset",
3232
)
33-
return parser.parse_args()
33+
parser.add_argument(
34+
"--resize",
35+
type=str,
36+
required=False,
37+
help="Resize images to a specific size (e.g. 512x512)",
38+
)
39+
40+
args = parser.parse_args()
41+
args.resize = tuple(map(int, args.resize.split("x"))) if args.resize else None
42+
return args
3443

3544

3645
def main():
@@ -44,7 +53,12 @@ def main():
4453
with open(args.ontology_translation, "r", encoding="utf-8") as f:
4554
ontology_translation = json.load(f)
4655

47-
dataset.export(args.outdir, new_ontology, ontology_translation)
56+
dataset.export(
57+
args.outdir,
58+
resize=args.resize,
59+
new_ontology=new_ontology,
60+
ontology_translation=ontology_translation,
61+
)
4862

4963

5064
if __name__ == "__main__":

examples/gaia_image.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ def parse_args() -> argparse.Namespace:
2525
required=False,
2626
help="Resize images to a specific size (e.g. 512x512)",
2727
)
28+
parser.add_argument(
29+
"--split",
30+
type=str,
31+
required=False,
32+
help="What split to export (train, val, test). Export all splits if not specified",
33+
)
2834

2935
args = parser.parse_args()
3036
args.resize = tuple(map(int, args.resize.split("x"))) if args.resize else None
@@ -36,6 +42,9 @@ def main():
3642
args = parse_args()
3743

3844
dataset = GaiaImageSegmentationDataset(dataset_fname=args.dataset)
45+
if args.split:
46+
dataset.dataset = dataset.dataset[dataset.dataset["split"] == args.split]
47+
dataset.has_label_count = False
3948
dataset.export(outdir=args.outdir, resize=args.resize)
4049

4150

examples/goose_image.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import argparse
2+
import json
23

34
from detectionmetrics.datasets.goose import GOOSEImageSegmentationDataset
45

@@ -32,10 +33,19 @@ def parse_args() -> argparse.Namespace:
3233
required=True,
3334
help="Directory where dataset will be stored in common format",
3435
)
36+
parser.add_argument(
37+
"--new_ontology",
38+
type=str,
39+
help="New ontology JSON file name",
40+
)
41+
parser.add_argument(
42+
"--ontology_translation",
43+
type=str,
44+
help="Ontology translation JSON file name",
45+
)
3546
parser.add_argument(
3647
"--resize",
3748
type=str,
38-
required=False,
3949
help="Resize images to a specific size (e.g. 512x512)",
4050
)
4151

@@ -48,12 +58,26 @@ def main():
4858
"""Main function"""
4959
args = parse_args()
5060

61+
new_ontology, ontology_translation = None, None
62+
if args.new_ontology is not None:
63+
with open(args.new_ontology, "r", encoding="utf-8") as f:
64+
new_ontology = json.load(f)
65+
66+
if args.ontology_translation is not None:
67+
with open(args.ontology_translation, "r", encoding="utf-8") as f:
68+
ontology_translation = json.load(f)
69+
5170
dataset = GOOSEImageSegmentationDataset(
5271
train_dataset_dir=args.train_dataset_dir,
5372
val_dataset_dir=args.val_dataset_dir,
5473
test_dataset_dir=args.test_dataset_dir,
5574
)
56-
dataset.export(args.outdir, resize=args.resize)
75+
dataset.export(
76+
args.outdir,
77+
resize=args.resize,
78+
new_ontology=new_ontology,
79+
ontology_translation=ontology_translation,
80+
)
5781

5882

5983
if __name__ == "__main__":

examples/rellis3d_image.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import argparse
2+
import json
23

34
from detectionmetrics.datasets.rellis3d import Rellis3DImageSegmentationDataset
45

@@ -34,10 +35,19 @@ def parse_args() -> argparse.Namespace:
3435
required=True,
3536
help="Directory where dataset will be stored in common format",
3637
)
38+
parser.add_argument(
39+
"--new_ontology",
40+
type=str,
41+
help="New ontology JSON file name",
42+
)
43+
parser.add_argument(
44+
"--ontology_translation",
45+
type=str,
46+
help="Ontology translation JSON file name",
47+
)
3748
parser.add_argument(
3849
"--resize",
3950
type=str,
40-
required=False,
4151
help="Resize images to a specific size (e.g. 512x512)",
4252
)
4353

@@ -50,12 +60,26 @@ def main():
5060
"""Main function"""
5161
args = parse_args()
5262

63+
new_ontology, ontology_translation = None, None
64+
if args.new_ontology is not None:
65+
with open(args.new_ontology, "r", encoding="utf-8") as f:
66+
new_ontology = json.load(f)
67+
68+
if args.ontology_translation is not None:
69+
with open(args.ontology_translation, "r", encoding="utf-8") as f:
70+
ontology_translation = json.load(f)
71+
5372
dataset = Rellis3DImageSegmentationDataset(
5473
dataset_dir=args.dataset_dir,
5574
split_dir=args.split_dir,
5675
ontology_fname=args.ontology_fname,
5776
)
58-
dataset.export(args.outdir, resize=args.resize)
77+
dataset.export(
78+
args.outdir,
79+
resize=args.resize,
80+
new_ontology=new_ontology,
81+
ontology_translation=ontology_translation,
82+
)
5983

6084

6185
if __name__ == "__main__":

0 commit comments

Comments
 (0)