Datasets:
Tasks:
Video Classification
Modalities:
Video
Languages:
English
Size:
10K<n<100K
Tags:
video
License:
Upload k600/train/train/generate_json_dataset.py with huggingface_hub
Browse files
k600/train/train/generate_json_dataset.py
CHANGED
@@ -6,36 +6,29 @@ import random
|
|
6 |
def generate_dataset_json(root_dir='.', output_file='dataset.json'):
|
7 |
dataset = []
|
8 |
|
9 |
-
# Get all directories in root_dir (each represents an action)
|
10 |
actions = [d for d in os.listdir(root_dir) if os.path.isdir(os.path.join(root_dir, d))]
|
11 |
|
12 |
for action in actions:
|
13 |
action_dir = os.path.join(root_dir, action)
|
14 |
|
15 |
-
# Find all mp4 files in this action directory
|
16 |
video_files = glob(os.path.join(action_dir, '*.mp4'))
|
17 |
|
18 |
for video_path in video_files:
|
19 |
-
# Create relative path from root_dir
|
20 |
rel_path = os.path.relpath(video_path, root_dir)
|
21 |
|
22 |
-
# Create caption by capitalizing the action name
|
23 |
caption = action.capitalize()
|
24 |
|
25 |
dataset.append({
|
26 |
-
"video": rel_path.replace('\\', '/'),
|
27 |
"caption": caption
|
28 |
})
|
29 |
|
30 |
-
# Shuffle the dataset with seed 42 for reproducibility
|
31 |
random.seed(42)
|
32 |
random.shuffle(dataset)
|
33 |
|
34 |
-
# Write to JSON file
|
35 |
with open(output_file, 'w') as f:
|
36 |
json.dump(dataset, f, indent=2)
|
37 |
|
38 |
print(f"Dataset JSON file created at {output_file} with {len(dataset)} entries.")
|
39 |
|
40 |
-
|
41 |
-
generate_dataset_json(root_dir='./', output_file='kinetics.json')
|
|
|
6 |
def generate_dataset_json(root_dir='.', output_file='dataset.json'):
|
7 |
dataset = []
|
8 |
|
|
|
9 |
actions = [d for d in os.listdir(root_dir) if os.path.isdir(os.path.join(root_dir, d))]
|
10 |
|
11 |
for action in actions:
|
12 |
action_dir = os.path.join(root_dir, action)
|
13 |
|
|
|
14 |
video_files = glob(os.path.join(action_dir, '*.mp4'))
|
15 |
|
16 |
for video_path in video_files:
|
|
|
17 |
rel_path = os.path.relpath(video_path, root_dir)
|
18 |
|
|
|
19 |
caption = action.capitalize()
|
20 |
|
21 |
dataset.append({
|
22 |
+
"video": rel_path.replace('\\', '/'),
|
23 |
"caption": caption
|
24 |
})
|
25 |
|
|
|
26 |
random.seed(42)
|
27 |
random.shuffle(dataset)
|
28 |
|
|
|
29 |
with open(output_file, 'w') as f:
|
30 |
json.dump(dataset, f, indent=2)
|
31 |
|
32 |
print(f"Dataset JSON file created at {output_file} with {len(dataset)} entries.")
|
33 |
|
34 |
+
generate_dataset_json(root_dir='./', output_file='kinetics.json')
|
|