Skip to content

Commit 3a94a65

Browse files
review_changes
1 parent 5c5f41f commit 3a94a65

File tree

1 file changed

+2
-12
lines changed
  • clarifai_datautils/image/annotation_conversion

1 file changed

+2
-12
lines changed

clarifai_datautils/image/annotation_conversion/utils.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ def __init__(
2222
Args:
2323
path (str): The path to the clarifai dataset.
2424
25-
Returns:
26-
A Datumaro dataset object.
2725
"""
2826
self.main_path = main_path
2927
self.image_list = os.listdir(os.path.join(self.main_path, 'inputs'))
@@ -46,13 +44,10 @@ def convert(self) -> Dataset:
4644
return dataset
4745

4846
def create_item(self, image_path: str) -> DatasetItem:
49-
"""Creates a Datumaro item from an image path.
50-
"""
51-
#read the image
47+
"""Creates a Datumaro item from an image path."""
5248
image_full_path = os.path.join(self.main_path, 'inputs', image_path)
5349
image_data = Image.from_file(image_full_path)
5450
width, height = PIL.Image.open(image_full_path).size
55-
# read the json file
5651
try:
5752
with open(
5853
os.path.join(self.main_path, 'annotations', image_path.split('.png')[0] + '.json'),
@@ -70,7 +65,6 @@ def create_item(self, image_path: str) -> DatasetItem:
7065
self.label_map[label] = value
7166
annotations.append(Bbox(x=x, y=y, w=w, h=h, label=value))
7267

73-
#file not found error
7468
except FileNotFoundError:
7569
annotations = []
7670

@@ -86,23 +80,19 @@ def clarifai_bbox_to_datumaro_bbox(self, clarifai_bbox, width, height) -> Tuple[
8680
return obj_box
8781

8882
def check_folder(self):
89-
"""Checks the clarifai folder format.
90-
"""
83+
"""Checks the clarifai folder format."""
9184
if not os.path.exists(self.main_path):
9285
raise AnnotationsDatasetError(f'Folder not found at {self.main_path}')
9386

94-
#check if the folder has two subfolders named 'inputs' and 'annotations'
9587
if not os.path.exists(os.path.join(self.main_path, 'inputs')):
9688
raise AnnotationsFormatError(
9789
f'Folder does not contain an "inputs" folder at {self.main_path}')
9890
if not os.path.exists(os.path.join(self.main_path, 'annotations')):
9991
raise AnnotationsFormatError(
10092
f'Folder does not contain an "annotations" folder at {self.main_path}')
10193

102-
#check if the 'inputs' folder contains images
10394
if not all(img.endswith('.png') for img in self.image_list):
10495
raise AnnotationsFormatError(f'Folder should only contain images at {self.main_path}/inputs')
105-
#check if the 'annotations' folder contains json files
10696
if not all(img.endswith('.json') for img in self.annotations_list):
10797
raise AnnotationsFormatError(
10898
f'Folder should only contain annotations at {self.main_path}/annotations')

0 commit comments

Comments
 (0)