Repository: airctic/icevision

Issue:
RandomSplitter as the new default for parser.parse
## 🚀 Feature
Randomly splitting data in [0.8, 0.2] can be the default for `parser.parse`



Discussion:

Resolving patch:
diff --git a/docs/autogen.py b/docs/autogen.py
--- a/docs/autogen.py
+++ b/docs/autogen.py
@@ -11,6 +11,7 @@
 PAGES = {
     "parser.md": [
         "icevision.parsers.Parser",
+        "icevision.parsers.Parser.parse",
         "icevision.parsers.FasterRCNN",
         "icevision.parsers.MaskRCNN",
         "icevision.parsers.mixins.ImageidMixin",
diff --git a/icevision/parsers/combined_parser.py b/icevision/parsers/combined_parser.py
--- a/icevision/parsers/combined_parser.py
+++ b/icevision/parsers/combined_parser.py
@@ -12,7 +12,7 @@ def __init__(self, *parsers: Parser):
         self.parsers = parsers
 
     def parse(self, data_splitter=None, idmap: IDMap = None, show_pbar: bool = True):
-        data_splitter = data_splitter or SingleSplitSplitter()
+        data_splitter = data_splitter or RandomSplitter([0.8, 0.2])
         idmap = idmap or IDMap()
 
         parsers_records = [
diff --git a/icevision/parsers/parser.py b/icevision/parsers/parser.py
--- a/icevision/parsers/parser.py
+++ b/icevision/parsers/parser.py
@@ -82,8 +82,18 @@ def parse(
         idmap: IDMap = None,
         show_pbar: bool = True,
     ) -> List[List[RecordType]]:
+        """Loops through all data points parsing the required fields.
+
+        # Arguments
+            data_splitter: How to split the parsed data, defaults to a [0.8, 0.2] random split.
+            idmap: Maps from filenames to unique ids, pass an `IDMap()` if you need this information.
+            show_pbar: Whether or not to show a progress bar while parsing the data.
+
+        # Returns
+            A list of records for each split defined by `data_splitter`.
+        """
         idmap = idmap or IDMap()
-        data_splitter = data_splitter or SingleSplitSplitter()
+        data_splitter = data_splitter or RandomSplitter([0.8, 0.2])
         records = self.parse_dicted(show_pbar=show_pbar, idmap=idmap)
         splits = data_splitter(idmap=idmap)
         return [[{"imageid": id, **records[id]} for id in ids] for ids in splits]


Test patch:
diff --git a/tests/conftest.py b/tests/conftest.py
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -19,7 +19,8 @@ def coco_imageid_map():
 @pytest.fixture(scope="module")
 def records(coco_imageid_map):
     parser = test_utils.sample_combined_parser()
-    return parser.parse(idmap=coco_imageid_map)[0]
+    data_splitter = SingleSplitSplitter()
+    return parser.parse(idmap=coco_imageid_map, data_splitter=data_splitter)[0]
 
 
 @pytest.fixture(scope="module")
diff --git a/tests/parsers/test_coco_parser.py b/tests/parsers/test_coco_parser.py
--- a/tests/parsers/test_coco_parser.py
+++ b/tests/parsers/test_coco_parser.py
@@ -6,7 +6,7 @@
 
 def test_info_parser():
     parser = test_utils.sample_image_info_parser()
-    infos = parser.parse()[0]
+    infos = parser.parse(data_splitter=SingleSplitSplitter())[0]
     assert len(infos) == 6
     expected = {
         "imageid": 0,
@@ -19,7 +19,7 @@ def test_info_parser():
 
 def test_coco_annotation_parser():
     parser = test_utils.sample_annotation_parser()
-    annotations = parser.parse()[0]
+    annotations = parser.parse(data_splitter=SingleSplitSplitter())[0]
     annotation = annotations[0]
     assert len(annotations) == 5
     assert annotation["imageid"] == 0
diff --git a/tests/parsers/test_voc_parsers.py b/tests/parsers/test_voc_parsers.py
--- a/tests/parsers/test_voc_parsers.py
+++ b/tests/parsers/test_voc_parsers.py
@@ -7,7 +7,7 @@ def test_voc_annotation_parser(samples_source, voc_class_map):
         images_dir=samples_source / "voc/JPEGImages",
         class_map=voc_class_map,
     )
-    records = annotation_parser.parse()[0]
+    records = annotation_parser.parse(data_splitter=SingleSplitSplitter())[0]
 
     assert len(records) == 2
 
@@ -38,7 +38,7 @@ def test_voc_mask_parser(samples_source):
     mask_parser = parsers.VocMaskParser(
         masks_dir=samples_source / "voc/SegmentationClass"
     )
-    records = mask_parser.parse()[0]
+    records = mask_parser.parse(data_splitter=SingleSplitSplitter())[0]
 
     record = records[0]
     expected = {
@@ -61,7 +61,7 @@ def test_voc_combined_parser(samples_source, voc_class_map):
     )
 
     combined_parser = parsers.CombinedParser(annotation_parser, mask_parser)
-    records = combined_parser.parse()[0]
+    records = combined_parser.parse(data_splitter=SingleSplitSplitter())[0]
 
     assert len(records) == 1