Skip to content

Commit

Permalink
Added analyze.class_name_id_map property
Browse files Browse the repository at this point in the history
  • Loading branch information
alexheat committed Jan 12, 2022
1 parent e448201 commit 181331a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
13 changes: 13 additions & 0 deletions pylabel/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@ def num_images(self):
"""
return self.dataset.df["img_filename"].nunique()

@property
def class_name_id_map(self):
"""Returns a dict where the class name is the key and class id is the value.
Returns:
Dict
Example:
>>> dataset.analyze.class_name_id_map()
{('Squirrel', 0),('Nut', 1)}
"""
return dict(zip(self.dataset.df.cat_name, self.dataset.df.cat_id))

def ShowClassSplits(self, normalize=True):
"""Show the distribution of classes across train, val, and
test splits of the dataset.
Expand Down
4 changes: 3 additions & 1 deletion pylabel/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,9 @@ def ExportToYoloV5(
# Note, having zero annotates can still be considered annotated
# in cases when are no objects in the image thats should be indentified
yolo_dataset = yolo_dataset.loc[yolo_dataset["annotated"] == 1]
yolo_dataset["cat_id"] = yolo_dataset["cat_id"].astype(pd.Int32Dtype())
yolo_dataset["cat_id"] = (
yolo_dataset["cat_id"].astype("float").astype(pd.Int32Dtype())
)

if cat_id_index != None:
assert isinstance(cat_id_index, int), "cat_id_index must be an int."
Expand Down

0 comments on commit 181331a

Please sign in to comment.