-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathclamp3_eval.py
More file actions
65 lines (50 loc) · 2.21 KB
/
clamp3_eval.py
File metadata and controls
65 lines (50 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
import os
import sys
from utils import *
def main():
if len(sys.argv) != 3:
print('Usage: python clamp3_eval.py <query_dir_path> <ref_dir_path>')
sys.exit(1)
query_dir_path = os.path.abspath(sys.argv[1])
ref_dir_path = os.path.abspath(sys.argv[2])
query_dir = os.path.basename(query_dir_path)
ref_dir = os.path.basename(ref_dir_path)
# Step 1: Create temporary and cache directories
os.makedirs('temp', exist_ok=True)
os.makedirs('cache', exist_ok=True)
# Step 2: Determine modalities automatically
query_modality = get_modality_from_dir(query_dir_path)
ref_modality = get_modality_from_dir(ref_dir_path)
if query_modality is None:
print(f'Error: Could not determine query modality for "{query_dir}"')
sys.exit(1)
if ref_modality is None:
print(f'Error: Could not determine reference modality for "{ref_dir}"')
sys.exit(1)
print(f'Detected query modality: {query_modality}')
print(f'Detected reference modality: {ref_modality}')
# Step 3: Extract features based on detected modality
modality_functions = {
'txt': extract_txt_features,
'img': extract_img_features,
'xml': extract_xml_features,
'mid': extract_mid_features,
'audio': extract_audio_features,
}
if os.path.exists(f'cache/{query_modality}-{query_dir}'):
print(f'Warning: {query_dir} already exists in the cache, skipping extraction.')
else:
modality_functions[query_modality](query_dir_path, f'cache/{query_modality}-{query_dir}')
if os.path.exists(f'cache/{ref_modality}-{ref_dir}'):
print(f'Warning: {ref_dir} already exists in the cache, skipping extraction.')
else:
modality_functions[ref_modality](ref_dir_path, f'cache/{ref_modality}-{ref_dir}')
# Step 4: Change directory to the inference folder
change_directory('inference')
# Step 5: Run the score comparison script
run_command(f'python clamp3_eval.py ../cache/{query_modality}-{query_dir} ../cache/{ref_modality}-{ref_dir}')
# Step 6: Clean up
change_directory('..')
remove_folder('temp')
if __name__ == '__main__':
main()