Skip to content

Commit

Permalink
Merge pull request #88 from pylabel-project/dev
Browse files Browse the repository at this point in the history
add use of tqdm to all importers-exporters
  • Loading branch information
alexheat committed Feb 7, 2023
2 parents 5e4b6af + 150a468 commit 7614f4b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
15 changes: 10 additions & 5 deletions pylabel/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,8 @@ def voc_xml_file_creation(
return output_file_path

# Loop through all images in the dataframe and call voc_xml_file_creation for each one
for file_title in tqdm(list(set(self.dataset.df.img_filename)), desc='Exporting files'):

pbar = tqdm(desc="Exporting VOC files...", total=len(list(set(self.dataset.df.img_filename))))
for file_title in list(set(self.dataset.df.img_filename)):
file_name = Path(file_title)
file_name = str(file_name.with_suffix(".xml"))
file_path = str(Path(output_path, file_name))
Expand All @@ -397,6 +397,7 @@ def voc_xml_file_creation(
output_file_path=file_path,
)
output_file_paths.append(voc_file_path)
pbar.update()

return output_file_paths

Expand Down Expand Up @@ -538,8 +539,8 @@ def ExportToYoloV5(

unique_images = yolo_dataset["img_filename"].unique()
output_file_paths = []

for img_filename in tqdm(unique_images, desc='Exporting files'):
pbar = tqdm(desc="Exporting YOLO files...", total=len(unique_images))
for img_filename in unique_images:
df_single_img_annots = yolo_dataset.loc[
yolo_dataset.img_filename == img_filename
]
Expand Down Expand Up @@ -631,6 +632,7 @@ def ExportToYoloV5(
str(source_image_path),
str(PurePath(path_dict["image_path"], split_dir, img_filename)),
)
pbar.update()

# Create YAML file
if yaml_file:
Expand Down Expand Up @@ -708,7 +710,8 @@ def ExportToCoco(self, output_path=None, cat_id_index=None):
list_c = []
json_list = []

for i in tqdm(range(0, df.shape[0]), desc="Exporting files"):
pbar = tqdm(desc="Exporting to COCO file...", total=df.shape[0])
for i in range(0, df.shape[0]):
images = [
{
"id": df["img_id"][i],
Expand Down Expand Up @@ -782,6 +785,8 @@ def ExportToCoco(self, output_path=None, cat_id_index=None):
if not pd.isna(categories[0]["id"]):
df_outputA.append(pd.DataFrame([annotations]))

pbar.update()

mergedI = pd.concat(df_outputI, ignore_index=True)
mergedA = pd.concat(df_outputA, ignore_index=True)
mergedC = pd.concat(df_outputC, ignore_index=True)
Expand Down
9 changes: 8 additions & 1 deletion pylabel/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ def GetCatId(cat_name):
return cat_names.index(cat_name)

# iterate over files in that directory
pbar = tqdm(desc="Importing VOC files...", total=len(os.listdir(path)))
for filename in os.scandir(path):
if filename.is_file() and filename.name.endswith(".xml"):
filepath = filename.path
Expand Down Expand Up @@ -229,6 +230,7 @@ def GetCatId(cat_name):

# Increment the imageid because we are going to read annother file
img_id += 1
pbar.update()

# Convert the dict with all of the annotation data to a dataframe
df = pd.DataFrame.from_dict(d, "index", columns=schema)
Expand Down Expand Up @@ -305,7 +307,8 @@ def GetCatNameFromId(cat_id, cat_names):
img_id = 0

# iterate over files in that directory
for filename in tqdm(os.scandir(path), desc='Importing files'):
pbar = tqdm(desc="Importing YOLO files...", total=len(os.listdir(path)))
for filename in os.scandir(path):
if filename.is_file() and filename.name.endswith(".txt"):
filepath = filename.path
file = open(filepath, "r", encoding=encoding) # Read file
Expand Down Expand Up @@ -394,6 +397,7 @@ def GetCatNameFromId(cat_id, cat_names):
# Add this row to the dict
# increment the image id
img_id += 1
pbar.update()

df = pd.DataFrame.from_dict(d, "index", columns=schema)
df.index.name = "id"
Expand Down Expand Up @@ -442,6 +446,8 @@ def ImportImagesOnly(path, name="dataset"):
img_id = 0

# iterate over files in that directory
pbar = tqdm(desc="Importing image files...", total=len(os.listdir(path)))

for filename in os.scandir(path):
if filename.is_file() and filename.name.lower().endswith(
(".png", ".jpg", ".jpeg", ".tiff", ".bmp", ".gif")
Expand Down Expand Up @@ -471,6 +477,7 @@ def ImportImagesOnly(path, name="dataset"):
# Add this row to the dict
d[img_id] = row
img_id += 1
pbar.update()

df = pd.DataFrame.from_dict(d, "index", columns=schema)
df.index.name = "id"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
setup(
name="pylabel",
packages=["pylabel"],
version="0.1.46",
version="0.1.47",
description="Transform, analyze, and visualize computer vision annotations.",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 7614f4b

Please sign in to comment.