<jupyter_start><jupyter_text>Pylabel End to End Example  Yolo v5 text files to VOC XMLUse this notebook to try out importing, analyzing, and exporting datasets of image annotations.<jupyter_code>!pip install -i https://test.pypi.org/simple/ pylabel==0.1.1
from pylabel import importer<jupyter_output><empty_output><jupyter_text>Import Yolo annotations First we will import annotations stored in Yolo v5 format.<jupyter_code>path_to_annotations = "/Users/alex/Google Drive/pylabel/datasets/wildlife/yolo_splits/val/labels/"

#Identify the path to get from the annotations to the images 
path_to_images = "../images/"

#Import the dataset into the pylable schema 
yoloclasses =["bear","cottontail","coyote","deer","elk","foxgray","foxred","opossum","racoon","snowshoehare","turkey"]
dataset = importer.ImportYoloV5(path=path_to_annotations, path_to_images=path_to_images, cat_names=yoloclasses,
    img_ext="jpeg", name="wildlife", img_height=329, img_width=329)

dataset.df.head(5)
#dataset.df.loc[:, dataset.df.columns.str.startswith('ann')]<jupyter_output><empty_output><jupyter_text>Analyze annotationsPylabel can calculate basic summary statisticts about the dataset such as the number of files and the classes. The dataset is stored as a pandas frame so the developer can do additional exploratory analysis on the dataset.<jupyter_code>print(f"Number of images: {dataset.analyze.num_images}")
print(f"Number of classes: {dataset.analyze.num_classes}")
print(f"Classes:{dataset.analyze.classes}")
print(f"Class counts:\n{dataset.analyze.class_counts}")<jupyter_output>Number of images: 1918
Number of classes: 10
Classes:['deer' 'foxgray' 'cottontail' 'snowshoehare' 'foxred' 'coyote' 'opossum'
 'racoon' 'elk' 'bear']
Class counts:
deer            577
elk             296
opossum         265
racoon          198
snowshoehare    185
cottontail      162
coyote          156
foxgray         145
foxred           79
bear             57
Name: cat_name, dtype: int64<jupyter_text>Visualize Annotations You can render the bounding boxes for your image to inspect them and confirm that they imported correctly.<jupyter_code>from IPython.display import Image, display
display(dataset.visualize.ShowBoundingBoxes(dataset, 100))
display(dataset.visualize.ShowBoundingBoxes(dataset, "2020781_2.jpeg"))<jupyter_output>/Users/alex/Google Drive/pylabel/datasets/wildlife/yolo_splits/val/labels/../images/4979998_2.jpeg<jupyter_text>Export to Coco XMLThe PyLabel exporter will export all of the annotations in the dataframe to the desired target format.All annotations will be stored in a single json file.<jupyter_code>from pathlib import Path
import os
output_path = str(Path(dataset.path_to_annotations, "../", "voc_annotations/"))
print(output_path)
Path(output_path).mkdir(exist_ok=True)
dataset.export.ExportToVoc(dataset, output_file_path_=output_path)<jupyter_output>/Users/alex/Google Drive/pylabel/datasets/wildlife/yolo_splits/val/labels/../voc_annotations
2041874_0.jpeg
/Users/alex/Google Drive/pylabel/datasets/wildlife/yolo_splits/val/labels/../voc_annotations
/Users/alex/Google Drive/pylabel/datasets/wildlife/yolo_splits/val/labels/../voc_annotations/2041874_0_jpeg.xml
4980760_2.jpeg
/Users/alex/Google Drive/pylabel/datasets/wildlife/yolo_splits/val/labels/../voc_annotations
/Users/alex/Google Drive/pylabel/datasets/wildlife/yolo_splits/val/labels/../voc_annotations/4980760_2_jpeg.xml
4935735_2.jpeg
/Users/alex/Google Drive/pylabel/datasets/wildlife/yolo_splits/val/labels/../voc_annotations
/Users/alex/Google Drive/pylabel/datasets/wildlife/yolo_splits/val/labels/../voc_annotations/4935735_2_jpeg.xml
2011393_0.jpeg
/Users/alex/Google Drive/pylabel/datasets/wildlife/yolo_splits/val/labels/../voc_annotations
/Users/alex/Google Drive/pylabel/datasets/wildlife/yolo_splits/val/labels/../voc_annotations/2011393_0_jpeg.xml
2020769_1.jpeg
/Users/alex/[...]
{'fraction_non_alphanumeric': 0.10935884177869701, 'fraction_numerical': 0.03619441571871768, 'mean_word_length': 5.705372616984402, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '93596', 'license': 'MIT', 'n_tokens_mistral': 1420, 'n_tokens_neox': 1300, 'n_words': 261, 'path': 'yolo2voc.ipynb', 'repo_name': 'pylabelalpha/pylabel', 'size': '3868'}