feat: 🏗️ Update architecture
This commit is contained in:
parent
3deae416b2
commit
3f91595b42
21
main.py
21
main.py
@ -7,7 +7,6 @@ import requests
|
||||
import os
|
||||
from multiprocessing import Pool
|
||||
|
||||
|
||||
CACHE_FOLDER = "cache/fonts"
|
||||
|
||||
# Créer le dossier de cache s'il n'existe pas
|
||||
@ -104,19 +103,21 @@ def create_letter_image(letter, output_path, font_path):
|
||||
def createImageForEachLetter(args):
|
||||
"""
|
||||
Function to create an image for each of the letters passed as an argument
|
||||
:param args: Tuple containing output folder, font path, and index
|
||||
:param args: Tuple containing output folder, font path, index, and type (training/validation)
|
||||
"""
|
||||
output_folder, font_path, index = args
|
||||
output_folder, font_path, index, dataset_type = args
|
||||
alphabet = string.ascii_letters # Inclut à la fois les lettres minuscules et majuscules
|
||||
|
||||
os.makedirs(output_folder, exist_ok=True) # Ensure base output folder exists
|
||||
base_folder = os.path.join(output_folder, dataset_type)
|
||||
os.makedirs(base_folder, exist_ok=True)
|
||||
|
||||
for element in alphabet:
|
||||
letter_folder = os.path.join(output_folder, element)
|
||||
letter_folder = os.path.join(base_folder, element)
|
||||
os.makedirs(letter_folder, exist_ok=True)
|
||||
|
||||
create_letter_image(element, f"{letter_folder}/{element}-{index}.png", font_path)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(argv) < 3:
|
||||
raise Exception("Usage: " + argv[0] + " <number-of-iterations> <api-key>")
|
||||
@ -132,9 +133,13 @@ if __name__ == "__main__":
|
||||
# Fetch fonts and cache them
|
||||
fonts = [getRandomFont(api_key, usedFont) for _ in range(num_iterations)]
|
||||
|
||||
# Prepare arguments for multiprocessing
|
||||
args = [("dataset", fonts[i], i) for i in range(num_iterations)]
|
||||
# Split into training and validation datasets
|
||||
num_training = int(num_iterations * 0.7)
|
||||
num_validation = num_iterations - num_training
|
||||
|
||||
training_args = [("dataset", fonts[i], i, "training") for i in range(num_training)]
|
||||
validation_args = [("dataset", fonts[i], i, "validation") for i in range(num_training, num_iterations)]
|
||||
|
||||
# Use multiprocessing pool
|
||||
with Pool() as pool:
|
||||
pool.map(createImageForEachLetter, args)
|
||||
pool.map(createImageForEachLetter, training_args + validation_args)
|
Reference in New Issue
Block a user