class documentation
class COCOParser(BaseParser):
Constructor: COCOParser(dataset, dataset_type, task_name, full_warnings)
Parse a directory with COCO annotations into LDF.
Expected formats:
dataset_dir/
├── train/
│ ├── data/
│ │ ├── img1.jpg
│ │ ├── img2.jpg
│ │ └── ...
│ └── labels.json
├── validation/
│ ├── data/
│ └── labels.json
└── test/
├── data/
└── labels.json
This is default format returned when using FiftyOne package.
or:
dataset_dir/
├── train/
│ ├── img1.jpg
│ ├── img2.jpg
│ └── ...
│ └── _annotations.coco.json
├── valid/
└── test/
This is one of the formats that Roboflow can generate.
| Class Method | discover |
Return present and valid split directories keyed by their canonical split names. |
| Class Method | validate |
Validate whether the dataset directory has the expected format. |
| Static Method | validate |
Validate whether a split directory has the expected format. |
| Method | from |
Parse all COCO splits in a source dataset directory. |
| Method | from |
Parse COCO annotations into LDF records. |
| Static Method | _detect |
Detect whether a dataset uses FiftyOne or Roboflow layout. |
| Static Method | _is |
Check if JSON file has required COCO format fields. |
| Method | _finalize |
Undocumented |
| Method | _parse |
Undocumented |
| Method | _resolve |
Undocumented |
Inherited from BaseParser:
| Method | __init__ |
Create a parser for a target dataset. |
| Method | get |
Return parser issue messages collected during the last parse. |
| Method | parse |
Parse an entire dataset directory into the target dataset. |
| Method | parse |
Parse one split subdirectory into the target dataset. |
| Method | reset |
Clear collected parser issue messages. |
| Static Method | _apply |
Distribute images across splits based on requested counts. |
| Static Method | _apply |
Apply count-based split requests to existing splits. |
| Static Method | _canonicalize |
All current parsers use train and test split names whereas validation splits can vary in name between val valid and validation. |
| Static Method | _compare |
Compare sets of files by stem. |
| Static Method | _get |
Return unique images yielded by a dataset generator. |
| Static Method | _list |
List OpenCV-supported images in a directory. |
| Static Method | _sample |
Sample from each original split independently. |
| Method | _get |
Return parser issue messages collected during the last parse. |
| Method | _log |
Undocumented |
| Method | _parse |
Parse data in one split subdirectory. |
| Method | _remove |
Remove records that are not assigned to any split. |
| Method | _reset |
Clear collected parser issue messages and warning counters. |
| Method | _warn |
Undocumented |
| Method | _wrap |
Add configured task names to generated records. |
| Constant | _CANONICAL |
Undocumented |
| Constant | _SKIPPED |
Undocumented |
| Constant | _SPLIT |
Undocumented |
| Instance Variable | _dataset |
Undocumented |
| Instance Variable | _dataset |
Undocumented |
| Instance Variable | _full |
Undocumented |
| Instance Variable | _logged |
Undocumented |
| Instance Variable | _parser |
Undocumented |
| Instance Variable | _seen |
Undocumented |
| Instance Variable | _skipped |
Undocumented |
| Instance Variable | _suppressed |
Undocumented |
| Instance Variable | _task |
Undocumented |
@classmethod
@override
def discover_dir_splits(cls, dataset_dir: @override
Path) -> dict[ str, dict[ str, Any]]:
¶
Return present and valid split directories keyed by their canonical split names.
Validate whether the dataset directory has the expected format.
| Parameters | |
datasetPath | Source dataset directory. |
| Returns | |
bool | Whether the dataset is in the expected format. |
Validate whether a split directory has the expected format.
| Parameters | |
splitPath | Path to a split directory. |
| Returns | |
dict[ | Keyword arguments for from_split, or None if the split is not in the expected format. |
def from_dir(self, dataset_dir:
Path, use_keypoint_ann: bool = False, keypoint_ann_paths: dict[ str, str] | None = None, split_val_to_test: bool = True) -> tuple[ list[ Path], list[ Path], list[ Path]]:
¶
Parse all COCO splits in a source dataset directory.
| Parameters | |
datasetPath | Source dataset directory. |
usebool | Whether to use separate COCO keypoint annotation files for FiftyOne-style datasets. |
keypointdict[ | Optional paths to keypoint annotation files, relative to dataset_dir and keyed by "train", "val", and "test". |
splitbool | Whether to split validation images 50 ⁄ 50 into validation and test when no test annotations are available. |
| Returns | |
tuple[ | Added images for the train, validation, and test splits. |
| Raises | |
ValueError | If the dataset directory, train split, validation split, or present test split is not in a recognized COCO layout. |
Parse COCO annotations into LDF records.
Annotations include classification, segmentation, object detection, and keypoints when present.
| Parameters | |
imagePath | Directory with images. |
annotationPath | Annotation JSON file. |
| Returns | |
ParserOutput | Parser output containing annotation records, skeleton metadata, and added images. |
@staticmethod
def _detect_dataset_dir_format(dataset_dir: Path) -> tuple[ COCOFormat | None, list[ str]]:
¶
Detect whether a dataset uses FiftyOne or Roboflow layout.
def _finalize_split_definitions(self, split_definitions:
dict[ str, list[ Path]], split_val_to_test: bool) -> dict[ str, list[ Path]]:
¶
Undocumented
@override
def _parse_available_splits(self, dataset_dir: Path, use_keypoint_ann: bool = False, keypoint_ann_paths: dict[ str, str] | None = None, split_val_to_test: bool = True) -> dict[ str, list[ Path]]:
¶
Undocumented
def _resolve_dir_format_and_keypoint_paths(self, dataset_dir:
Path, use_keypoint_ann: bool, keypoint_ann_paths: dict[ str, str] | None) -> tuple[ COCOFormat, list[ str], dict[ str, str] | None]:
¶
Undocumented