Loacky commited on
Commit
8708ab6
·
1 Parent(s): 45b4835

delete reorganize_sprite_dataset.py (replaced by generate_sprite_metadata.py)

Browse files
Files changed (1) hide show
  1. reorganize_sprite_dataset.py +0 -59
reorganize_sprite_dataset.py DELETED
@@ -1,59 +0,0 @@
1
- import os
2
- from datasets import Dataset, DatasetDict, Image, Features, Value
3
- import glob
4
-
5
- # Define the path to your dataset (where the folders like 0_frames, 1_frames, etc., are located)
6
- dataset_path = "/Users/lorenzo/Documents/GitHub/sprite-animation/train" # Replace with the actual path
7
-
8
- # Define the features for the dataset
9
- features = Features({
10
- "image": Image(),
11
- "label": Value("string"), # The folder name (e.g., "12_frames")
12
- "sprite_id": Value("string"), # The sprite ID (e.g., "12")
13
- })
14
-
15
- # Initialize lists to hold the consolidated data
16
- images = []
17
- labels = []
18
- sprite_ids = []
19
-
20
- # Iterate over each folder (0_frames, 1_frames, etc.)
21
- for folder_name in os.listdir(dataset_path):
22
- folder_path = os.path.join(dataset_path, folder_name)
23
-
24
- # Skip non-directory files and hidden directories (e.g., .git)
25
- if not os.path.isdir(folder_path) or folder_name.startswith("."):
26
- continue
27
-
28
- print(f"Processing folder: {folder_name}") # Debug: Print folder being processed
29
-
30
- # Extract the sprite ID from the folder name (e.g., "12" from "12_frames")
31
- sprite_id = folder_name.split("_")[0]
32
-
33
- # Load all images in the folder
34
- image_paths = glob.glob(os.path.join(folder_path, "sprite_*.png"))
35
- print(f"Found {len(image_paths)} images in folder '{folder_name}'") # Debug: Print number of images found
36
-
37
- for image_path in image_paths:
38
- # Append data to the consolidated lists
39
- images.append(image_path)
40
- labels.append(folder_name) # Use the folder name as the label
41
- sprite_ids.append(sprite_id) # Use the sprite ID as an additional field
42
-
43
- # Create a single dataset with all the data
44
- dataset = Dataset.from_dict(
45
- {
46
- "image": images,
47
- "label": labels,
48
- "sprite_id": sprite_ids,
49
- },
50
- features=features
51
- )
52
-
53
- # Create a DatasetDict with a single split (e.g., "train")
54
- final_dataset = DatasetDict({"train": dataset})
55
-
56
- # Push the dataset to Hugging Face
57
- final_dataset.push_to_hub("Lod34/sprite-animation", private=False) # Set private=True if you want it private
58
-
59
- print("Dataset successfully uploaded!")