Datasets:
Tasks:
Video Classification
Modalities:
Video
Languages:
English
Size:
10K<n<100K
Tags:
video
License:
Update k600/k600_reorganize.py
Browse files- k600/k600_reorganize.py +5 -9
k600/k600_reorganize.py
CHANGED
|
@@ -4,7 +4,6 @@ import sys
|
|
| 4 |
import json
|
| 5 |
|
| 6 |
def parse_txt_to_json(txt_path):
|
| 7 |
-
"""Parse a .txt file into a JSON dict structure."""
|
| 8 |
with open(txt_path, 'r', encoding='utf-8') as f:
|
| 9 |
lines = [line.rstrip('\n') for line in f]
|
| 10 |
|
|
@@ -37,7 +36,6 @@ def parse_txt_to_json(txt_path):
|
|
| 37 |
return result
|
| 38 |
|
| 39 |
def organize_files(json_data, base_dir):
|
| 40 |
-
"""Organize files into directories based on JSON data."""
|
| 41 |
os.makedirs(base_dir, exist_ok=True)
|
| 42 |
|
| 43 |
for key in json_data:
|
|
@@ -52,14 +50,14 @@ def organize_files(json_data, base_dir):
|
|
| 52 |
dst = os.path.join(dir_path, file_name)
|
| 53 |
|
| 54 |
if not os.path.exists(src):
|
| 55 |
-
print(f"
|
| 56 |
continue
|
| 57 |
|
| 58 |
try:
|
| 59 |
shutil.move(src, dst)
|
| 60 |
-
print(f"
|
| 61 |
except Exception as e:
|
| 62 |
-
print(f"
|
| 63 |
|
| 64 |
def main():
|
| 65 |
if len(sys.argv) != 2:
|
|
@@ -70,16 +68,14 @@ def main():
|
|
| 70 |
output_json = "structure.json"
|
| 71 |
base_dir = "./train"
|
| 72 |
|
| 73 |
-
# Step 1: Parse .txt into JSON
|
| 74 |
print("Parsing input file...")
|
| 75 |
json_data = parse_txt_to_json(input_txt)
|
| 76 |
|
| 77 |
print(f"Got {len(json_data.keys())} categories!")
|
| 78 |
|
| 79 |
-
# Step 2: Organize files
|
| 80 |
print("Organizing files into directories...")
|
| 81 |
organize_files(json_data, base_dir)
|
| 82 |
-
print("
|
| 83 |
|
| 84 |
if __name__ == "__main__":
|
| 85 |
-
main()
|
|
|
|
| 4 |
import json
|
| 5 |
|
| 6 |
def parse_txt_to_json(txt_path):
|
|
|
|
| 7 |
with open(txt_path, 'r', encoding='utf-8') as f:
|
| 8 |
lines = [line.rstrip('\n') for line in f]
|
| 9 |
|
|
|
|
| 36 |
return result
|
| 37 |
|
| 38 |
def organize_files(json_data, base_dir):
|
|
|
|
| 39 |
os.makedirs(base_dir, exist_ok=True)
|
| 40 |
|
| 41 |
for key in json_data:
|
|
|
|
| 50 |
dst = os.path.join(dir_path, file_name)
|
| 51 |
|
| 52 |
if not os.path.exists(src):
|
| 53 |
+
print(f"File not found: {src}. Skipping.")
|
| 54 |
continue
|
| 55 |
|
| 56 |
try:
|
| 57 |
shutil.move(src, dst)
|
| 58 |
+
print(f"Moved: {src} -> {dst}")
|
| 59 |
except Exception as e:
|
| 60 |
+
print(f"Error moving {src}: {e}")
|
| 61 |
|
| 62 |
def main():
|
| 63 |
if len(sys.argv) != 2:
|
|
|
|
| 68 |
output_json = "structure.json"
|
| 69 |
base_dir = "./train"
|
| 70 |
|
|
|
|
| 71 |
print("Parsing input file...")
|
| 72 |
json_data = parse_txt_to_json(input_txt)
|
| 73 |
|
| 74 |
print(f"Got {len(json_data.keys())} categories!")
|
| 75 |
|
|
|
|
| 76 |
print("Organizing files into directories...")
|
| 77 |
organize_files(json_data, base_dir)
|
| 78 |
+
print("Done!")
|
| 79 |
|
| 80 |
if __name__ == "__main__":
|
| 81 |
+
main()
|