File size: 1,946 Bytes
a377382
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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.")