<jupyter_start><jupyter_text>Data Preparation    In this notebook we will try to restructure the dataset into so that it can be loaded through a csv file using the fastai dataloader.    We will create a csv file 'labels.csv' which has the image paths and their respective labels. Import Required Packages<jupyter_code>import os
import random
from shutil import copyfile
import pandas as pd<jupyter_output><empty_output><jupyter_text>Set the required paths<jupyter_code>DEST_PATH = 'data/'
SOURCE_PATH = 'Kannada/Hnd/Img/'<jupyter_output><empty_output><jupyter_text>Copying all the images to a single directory Create a 'data' directory to store all the images of the dataset.<jupyter_code>if 'data' not in os.listdir('.'):
    os.mkdir(PATH)<jupyter_output><empty_output><jupyter_text>Load all the directory names from the original dataset<jupyter_code>samples = os.listdir(SOURCE_PATH)
#data_dir = os.listdir(DEST_PATH)<jupyter_output><empty_output><jupyter_text>Copy all the images from each directory in the dataset folder to the 'data' directory<jupyter_code>for i in os.listdir(src_path):
    for j in os.listdir(src_path + i):
        temp_path = src_path + i + '/' + j
        copyfile(temp_path, dest_path + j)<jupyter_output><empty_output><jupyter_text>Check whether images have copied properly<jupyter_code>os.listdir('data/')[0]<jupyter_output><empty_output><jupyter_text>Create a CSV file containing the image names and labels<jupyter_code>img_names = os.listdir('data/')
labels = [int(i[3:6])-1 for i in img_names]
data = pd.DataFrame(data={'img_name':img_names, 'label':labels})
data.head()<jupyter_output><empty_output><jupyter_text>Save the csv file<jupyter_code>data.to_csv('labels.csv', index=None)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10080183276059565, 'fraction_numerical': 0.002290950744558992, 'mean_word_length': 6.764444444444444, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '212486', 'license': 'MIT', 'n_tokens_mistral': 598, 'n_tokens_neox': 586, 'n_words': 156, 'path': 'Data Preparation.ipynb', 'repo_name': 'pmk21/kannada-character-recognition', 'size': '1746'}