allietran commited on
Commit
a202797
·
verified ·
1 Parent(s): 74d53e2

Delete restructure.py

Browse files
Files changed (1) hide show
  1. restructure.py +0 -37
restructure.py DELETED
@@ -1,37 +0,0 @@
1
- import os
2
- import shutil
3
- import pandas as pd
4
-
5
-
6
- def restructure_images(df, image_dir, output_dir):
7
- """
8
- Moves images from a flat folder to a nested structure: /01/ab/image_id.jpg
9
- and updates the DataFrame with the new paths.
10
- """
11
- new_paths = []
12
- for img_id in df["image_path"]:
13
- # Create nested folders based on first 4 chars of ID
14
- sub_dir_1 = img_id[0:2]
15
- sub_dir_2 = img_id[2:4]
16
-
17
- target_folder = os.path.join(output_dir, sub_dir_1, sub_dir_2)
18
- os.makedirs(target_folder, exist_ok=True)
19
-
20
- src = os.path.join(image_dir, f"{img_id}.jpg")
21
- dst = os.path.join(target_folder, f"{img_id}.jpg")
22
-
23
- if os.path.exists(src):
24
- shutil.copy(src, dst)
25
- # Store relative path for the metadata
26
- new_paths.append(f"{sub_dir_1}/{sub_dir_2}/{img_id}.jpg")
27
- else:
28
- new_paths.append(None)
29
-
30
- df["relative_path"] = new_paths
31
- return df
32
-
33
-
34
- # Usage
35
- df = pd.read_parquet("products.parquet")
36
- df = restructure_images(df, "./images_flat", "./images_nested")
37
- df.to_parquet("products.parquet", index=False)