Datasets:
Upload dataset_setup.py
Browse filesThe script used to extract the zipped bundles to the right place
- dataset_setup.py +36 -0
dataset_setup.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import subprocess
|
| 3 |
+
|
| 4 |
+
def extract_video_tasks():
|
| 5 |
+
root = os.path.join('video_tasks', 'frames')
|
| 6 |
+
all_bundles = list(filter(lambda x: '.tar.gz' in x, os.listdir(root)))
|
| 7 |
+
for task in ['cls', 'qa', 'ret', 'mret']:
|
| 8 |
+
print(f'Extracting {task} task ... ...')
|
| 9 |
+
output_dir = os.path.join(root, f'video_{task}')
|
| 10 |
+
os.makedirs(output_dir, exist_ok=True)
|
| 11 |
+
bundles = sorted(list(filter(lambda x: task in x, all_bundles)))
|
| 12 |
+
bundles = [os.path.join(root, x) for x in bundles]
|
| 13 |
+
if len(bundles) > 1:
|
| 14 |
+
cat = subprocess.Popen(['cat'] + bundles, stdout=subprocess.PIPE)
|
| 15 |
+
cmd = ['tar', '-xzf', '-', '-C', output_dir]
|
| 16 |
+
tar = subprocess.Popen(cmd, stdin=cat.stdout)
|
| 17 |
+
tar.wait()
|
| 18 |
+
cat.stdout.close()
|
| 19 |
+
else:
|
| 20 |
+
assert len(bundles) == 1, f'Unexpected size'
|
| 21 |
+
tar = subprocess.run(['tar', '-xzfv', bundles[0], '-C', output_dir])
|
| 22 |
+
print('Extracting video tasks completed!')
|
| 23 |
+
|
| 24 |
+
def extract_image_tasks():
|
| 25 |
+
root = os.path.join('image_tasks')
|
| 26 |
+
for task in ['mmeb_v1', 'visdoc']:
|
| 27 |
+
print(f'Extracting {task} task ... ...')
|
| 28 |
+
subprocess.run(['tar', '-xzf', os.path.join(root, f'{task}.tar.gz'), '-C', root])
|
| 29 |
+
print('Extracting image tasks completed!')
|
| 30 |
+
|
| 31 |
+
def main():
|
| 32 |
+
extract_image_tasks()
|
| 33 |
+
extract_video_tasks()
|
| 34 |
+
|
| 35 |
+
if __name__ == '__main__':
|
| 36 |
+
main()
|