import os import json # Define the directory where your dataset images are located #dataset_directory = "cityscape_dataset" # Define the directories for images and conditioning images #image_dir = os.path.join(dataset_directory, "leftImg8bit/train") #conditioning_dir = os.path.join(dataset_directory, "gtCoarse/train") image_dir = "leftImg8bit/train" conditioning_dir = "gtCoarse/train" # Define the output JSONL filename jsonl_filename = "train.jsonl" # Initialize an empty list to store the dataset entries dataset_entries = [] # Iterate through the city folders in the image directory for city_folder in os.listdir(image_dir): city_dir = os.path.join(image_dir, city_folder) # Iterate through image files in the city directory for image_filename in os.listdir(city_dir): # Extract relevant information from the image filename parts = image_filename.split("_") city = parts[0] seq = parts[1] frame = parts[2] # Construct the paths to the image and conditioning image image_path = os.path.join(city_dir, image_filename) conditioning_image_filename = f"{city}_{seq}_{frame}_gtCoarse_color.png" conditioning_image_path = os.path.join(conditioning_dir, city_folder+"/"+conditioning_image_filename) # Create a dataset entry as a dictionary entry = { "text": "A view to a street from a car's front window", "image": image_path, "conditioning_image": conditioning_image_path, } # Append the entry dictionary to the list dataset_entries.append(entry) # Open the JSONL file for writing with open(jsonl_filename, "w") as jsonl_file: # Write each entry as a JSON string followed by a newline character for entry in dataset_entries: jsonl_file.write(json.dumps(entry) + "\n") print(f"JSON Lines file '{jsonl_filename}' has been created.")