<jupyter_start><jupyter_text>Loads the classes<jupyter_code>classes = []
with open(names_file, "r") as file:
    classes = file.read().split("\n")
classes_dict = {x: classes[x] for x in range(len(classes))} # converts num to class
classes_dict<jupyter_output><empty_output><jupyter_text>Counts the number of images<jupyter_code>def count_images_darknet(txt):
    num_images = 0
    with open(txt, "r") as file:
        num_images = len(file.read().split("\n")[:-1])
    return num_images
num_train_images = count_images_darknet(train_txt)
num_test_images = count_images_darknet(test_txt)
num_total_images = num_train_images + num_test_images

print("Num Train:", num_train_images)
print("Num Test:", num_test_images)
print("Total:", num_total_images)<jupyter_output>Num Train: 59501
Num Test: 6614
Total: 66115<jupyter_text>Function to count data, given list of classes<jupyter_code>def count_data_darknet(classes, txt):
    classes_dict = {x: classes[x] for x in range(len(classes))} # converts num to class
    class_count = {x: 0 for x in classes} # keeps track of count.

    img_paths = []
    with open(txt, "r") as file:
        img_paths = file.read().split("\n")[:-1]
    
    # iterates through every image path defined in the .txt file (darknet)
    for img_path in tqdm(img_paths, desc="Counting Images..."):
        img_labels_txt = img_path[:-3]+"txt" # replaces the .jpg at end with .txt
        
        # reads in the labels
        labels = []
        with open(img_labels_txt, "r") as file:
            labels = file.read().split("\n")
        
        # iterates through each label
        for label in labels:
            label_class = int(label.split(" ")[0]) # split by space, grab first item, to int
            class_count[classes_dict[label_class]] += 1

    return class_count<jupyter_output><empty_output><jupyter_text>Counting the classes<jupyter_code>train_count = count_data_darknet(classes, train_txt)
test_count = count_data_darknet(classes, test_txt)
class_count = {x: train_count[x] + test_count[x] for x in classes}
class_count<jupyter_output><empty_output><jupyter_text>Plots histograms<jupyter_code># traffic signs only
traffic_light_classes = ['trafficLight', 'trafficLightgreen', 'trafficLightyellow', 'trafficLightred']
signs_count = {x: class_count[x] for x in classes if x not in traffic_light_classes}
fig = plt.figure(figsize=(18, 5), dpi=100)
plt.bar(signs_count.keys(), signs_count.values(), 1, align="center", color="b")

fig.axes[0].get_yaxis().set_visible(False)
fig.axes[0].tick_params(labelrotation=70, labelsize=12)
new_names = ['lightframe', 'green', 'yellow', 'red']
lights_count_temp = {x: class_count[x] for x in classes if x in traffic_light_classes}
lights_count = {new_names[x] : lights_count_temp[key] for x, key in enumerate(lights_count_temp.keys())}
fig = plt.figure(figsize=(8, 5), dpi=100)
plt.bar(lights_count.keys(), lights_count.values(), 1, align="center", color=["gray", "green", "yellow", "red"])

fig.axes[0].get_yaxis().set_visible(False)
fig.axes[0].tick_params(labelrotation=70, labelsize=12)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13331181407359588, 'fraction_numerical': 0.014848289218850872, 'mean_word_length': 5.1610337972166995, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '211333', 'license': 'MIT', 'n_tokens_mistral': 1108, 'n_tokens_neox': 1063, 'n_words': 248, 'path': 'data_exploration/visualization.ipynb', 'repo_name': 'PoldervaartS/traffic_detection_dataset', 'size': '3098'}