File size: 2,102 Bytes
45b4835
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
55
56
57
58
59
import os
from datasets import Dataset, DatasetDict, Image, Features, Value
import glob

# Define the path to your dataset (where the folders like 0_frames, 1_frames, etc., are located)
dataset_path = "/Users/lorenzo/Documents/GitHub/sprite-animation/train"  # Replace with the actual path

# Define the features for the dataset
features = Features({
    "image": Image(),
    "label": Value("string"),  # The folder name (e.g., "12_frames")
    "sprite_id": Value("string"),  # The sprite ID (e.g., "12")
})

# Initialize lists to hold the consolidated data
images = []
labels = []
sprite_ids = []

# Iterate over each folder (0_frames, 1_frames, etc.)
for folder_name in os.listdir(dataset_path):
    folder_path = os.path.join(dataset_path, folder_name)
    
    # Skip non-directory files and hidden directories (e.g., .git)
    if not os.path.isdir(folder_path) or folder_name.startswith("."):
        continue

    print(f"Processing folder: {folder_name}")  # Debug: Print folder being processed

    # Extract the sprite ID from the folder name (e.g., "12" from "12_frames")
    sprite_id = folder_name.split("_")[0]

    # Load all images in the folder
    image_paths = glob.glob(os.path.join(folder_path, "sprite_*.png"))
    print(f"Found {len(image_paths)} images in folder '{folder_name}'")  # Debug: Print number of images found

    for image_path in image_paths:
        # Append data to the consolidated lists
        images.append(image_path)
        labels.append(folder_name)  # Use the folder name as the label
        sprite_ids.append(sprite_id)  # Use the sprite ID as an additional field

# Create a single dataset with all the data
dataset = Dataset.from_dict(
    {
        "image": images,
        "label": labels,
        "sprite_id": sprite_ids,
    },
    features=features
)

# Create a DatasetDict with a single split (e.g., "train")
final_dataset = DatasetDict({"train": dataset})

# Push the dataset to Hugging Face
final_dataset.push_to_hub("Lod34/sprite-animation", private=False)  # Set private=True if you want it private

print("Dataset successfully uploaded!")