MMEB-V2 / dataset_setup.py
MINGYISU's picture
Update dataset_setup.py
38233fd verified
import os
import subprocess
def extract_video_tasks():
root = os.path.join('video_tasks', 'frames')
all_bundles = list(filter(lambda x: '.tar.gz' in x, os.listdir(root)))
for task in ['cls', 'qa', 'ret', 'mret']:
print(f'Extracting {task} task ... ...')
output_dir = os.path.join(root, f'video_{task}')
os.makedirs(output_dir, exist_ok=True)
bundles = sorted(list(filter(lambda x: task in x, all_bundles)))
bundles = [os.path.join(root, x) for x in bundles]
if len(bundles) > 1:
cat = subprocess.Popen(['cat'] + bundles, stdout=subprocess.PIPE)
cmd = ['tar', '-xzf', '-', '-C', output_dir]
tar = subprocess.Popen(cmd, stdin=cat.stdout)
cat_return_code = cat.wait()
tar_return_code = tar.wait()
if cat_return_code != 0:
raise RuntimeError('Error occured during concatenation!')
if tar_return_code != 0:
raise RuntimeError('Error occured during extraction!')
else:
assert len(bundles) == 1, f'Unexpected size'
tar = subprocess.run(['tar', '-xzfv', bundles[0], '-C', output_dir])
print('All video tasks completed!')
def extract_image_tasks():
root = 'image_tasks'
for task in ['mmeb_v1', 'visdoc']:
print(f'Extracting {task} task ... ...')
subprocess.run(['tar', '-xzf', os.path.join(root, f'{task}.tar.gz'), '-C', root])
print('All image tasks completed!')
def main():
extract_image_tasks()
extract_video_tasks()
if __name__ == '__main__':
main()