Skip to content

Commit

Permalink
fix native parser
Browse files Browse the repository at this point in the history
  • Loading branch information
kozlov721 committed Jan 14, 2025
1 parent 3a07ada commit beb4f2a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
26 changes: 15 additions & 11 deletions luxonis_ml/data/parsers/base_parser.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from abc import ABC, abstractmethod
from dataclasses import dataclass
from pathlib import Path
Expand Down Expand Up @@ -89,17 +90,20 @@ def _parse_split(self, **kwargs) -> List[Path]:
@rtype: List[str]
@return: List of added images.
"""
generator, skeletons, added_images = self.from_split(**kwargs)
self.dataset.add(self._add_task(generator))
if skeletons:
for skeleton in skeletons.values():
self.dataset.set_skeletons(
skeleton.get("labels"),
skeleton.get("edges"),
self.dataset_type.value,
)

return added_images
old_cwd = os.getcwd()
try:
generator, skeletons, added_images = self.from_split(**kwargs)
self.dataset.add(self._add_task(generator))
if skeletons:
for skeleton in skeletons.values():
self.dataset.set_skeletons(
skeleton.get("labels"),
skeleton.get("edges"),
self.dataset_type.value,
)
return added_images
finally:
os.chdir(old_cwd)

def parse_split(
self,
Expand Down
12 changes: 5 additions & 7 deletions luxonis_ml/data/parsers/native_parser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import os
from pathlib import Path
from typing import Any, Dict, List, Optional, Tuple

Expand Down Expand Up @@ -65,14 +66,11 @@ def from_split(self, annotation_path: Path) -> ParserOutput:
dictionary for keypoints and list of added images.
"""

data = json.loads(annotation_path.read_text())
os.chdir(annotation_path.parent)

def generator() -> DatasetIterator:
for record in json.loads(annotation_path.read_text()):
if "file" not in record:
raise ValueError(
"The annotation record must contain 'file' key."
)
record["file"] = annotation_path.parent / record["file"]
yield record
yield from data

added_images = self._get_added_images(generator())

Expand Down

0 comments on commit beb4f2a

Please sign in to comment.