-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract_iclr24_fewshot.py
More file actions
66 lines (53 loc) · 2.21 KB
/
extract_iclr24_fewshot.py
File metadata and controls
66 lines (53 loc) · 2.21 KB
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
60
61
62
63
64
65
66
import os
import random
import shutil
from pathlib import Path
import argparse
def sample_folders(source_dir: str, target_dir: str, few_shot: int, seed: int = 42):
"""
Randomly sample and copy specified number of folders from source directory to target directory
Args:
source_dir: Source directory path
target_dir: Target directory path
few_shot: Number of folders to sample
seed: Random seed for reproducibility
"""
# Set random seed for reproducibility
random.seed(seed)
# Get all folders (excluding 'damaged' folder)
folders = [f for f in os.listdir(source_dir)
if os.path.isdir(os.path.join(source_dir, f))
and f != 'damaged']
# Ensure sampling size doesn't exceed available folders
few_shot = min(few_shot, len(folders))
# Randomly sample specified number of folders
selected_folders = random.sample(folders, few_shot)
# Create target directory if it doesn't exist
Path(target_dir).mkdir(parents=True, exist_ok=True)
# Copy selected folders to target directory
for folder in selected_folders:
src_path = os.path.join(source_dir, folder)
dst_path = os.path.join(target_dir, folder)
print(f"Copying folder: {folder}")
shutil.copytree(src_path, dst_path)
print(f"\nComplete! Copied {few_shot} folders to {target_dir}")
return selected_folders
def main():
# Parse command line arguments
parser = argparse.ArgumentParser(description='Random folder sampling')
parser.add_argument('--few_shot', type=int, default=8,
help='Number of folders to sample')
parser.add_argument('--seed', type=int, default=42,
help='Random seed for reproducibility')
args = parser.parse_args()
# Setup paths
source_dir = "/shared/hdd/data/openreview_data/ICLR.cc/2024/Conference"
target_dir = f"/shared/hdd/junyi/iclr24_{args.few_shot}shot"
# Execute sampling and copying
selected = sample_folders(source_dir, target_dir, args.few_shot, args.seed)
# Print results
print("\nSelected folders:")
for folder in selected:
print(folder)
if __name__ == "__main__":
main()