# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

# + [markdown] id="zC-dG7dt6Ks-"
# This shows how PyLabel can import data when given a YAML File and a dataset that has already had its images and annotations/labels folders split into train, test and val. This is our expected use case.

# + id="ZlG6Nnec0EHi"
import torch
from IPython.display import Image  # for displaying images
import os, zipfile
import random
import shutil
from sklearn.model_selection import train_test_split
import xml.etree.ElementTree as ET
from xml.dom import minidom
from tqdm import tqdm
from PIL import Image, ImageDraw
import numpy as np
import matplotlib.pyplot as plt

random.seed(108)

import logging
logging.getLogger().setLevel(logging.CRITICAL)
# !pip install pylabel > /dev/null

# #!pip install pylabel

from pylabel import importer
from pylabel import *

from pathlib import PurePath

import yaml

# + colab={"base_uri": "https://localhost:8080/"} id="REHUX3HHhSeP" outputId="c286f4e2-9e83-48ab-8ef7-716ffc1cf01c"
#A random dataset that we found online.
# !wget -O roadsign_splitdata.zip https://raw.githubusercontent.com/pylabel-project/datasets_models/main/roadsign_splitdata.zip
# !unzip roadsign_splitdata.zip


# + colab={"base_uri": "https://localhost:8080/"} id="nxYw2FbmhhQJ" outputId="64fad070-0e90-4a01-99ce-ea495994b60f"
#An example annotation
# !cat /content/annotations/train/road4.txt

# + colab={"base_uri": "https://localhost:8080/"} id="L3lYwlImhhMN" outputId="d6513479-beb2-4fa7-9833-9dd89fe2fdee"
#An example YAML file
# !cat /content/road_sign_data.yaml

# + id="XFzuoZYjiR__"
#Import the data from a YAML file and convert it to a dataset
data0 = importer.ImportYoloV5WithYaml(yaml_file="/content/road_sign_data.yaml", 
                     path_to_annotations=None, 
                     image_ext='png',
                     name_of_annotations_folder="annotations")

# + colab={"base_uri": "https://localhost:8080/", "height": 258} id="shMQ1ebViMHH" outputId="af4cfb26-40ab-42e4-8fae-df51dbccdb32"
#An example of what the data looks like
data0.df.head(5)

# + colab={"base_uri": "https://localhost:8080/", "height": 195} id="sUfbY-NxhhGn" outputId="8ac631dd-5dbd-4b94-bb42-ad6f44373624"
#A sample of what the groupings look like
data0.df.groupby('split').count()

# + id="AEuFW-vZhhA9"


# + id="PUISOppWhg7x"


# + id="UNXcq-QFhg5t"


# + id="maPU3HdE5Hj6"


# + id="3NyTds8a9sLw"


# + id="68jpf37TnHlX"


StarcoderdataJupyterScriptsDedupFiltered