Datasets:
Tasks:
Question Answering
Modalities:
Image
Formats:
imagefolder
Languages:
English
Size:
1K - 10K
License:
weizhen
commited on
Commit
Β·
fae6778
1
Parent(s):
dd4ca4d
Refactor the images into subdirectories for compatibilities per HF Dataset. Updated VQA records to reflect the change
Browse filesThis view is limited to 50 files because it contains too many changes. Β
See raw diff
- .gitattributes +1 -0
- __pycache__/breakdown.cpython-312.pyc +0 -0
- trainval.json β misc/move_to_mapping.json +2 -2
- {obs β misc}/old2new.json +0 -0
- refactor.py +83 -0
- {obs β trainval_obs/0}/10011.png +0 -0
- {obs β trainval_obs/0}/10020.png +0 -0
- {obs β trainval_obs/0}/10030.png +0 -0
- {obs β trainval_obs/0}/10047.png +0 -0
- {obs β trainval_obs/0}/1005.png +0 -0
- {obs β trainval_obs/0}/10055.png +0 -0
- {obs β trainval_obs/0}/10071.png +0 -0
- {obs β trainval_obs/0}/10113.png +0 -0
- {obs β trainval_obs/0}/10133.png +0 -0
- {obs β trainval_obs/0}/10135.png +0 -0
- {obs β trainval_obs/0}/10139.png +0 -0
- {obs β trainval_obs/0}/1019.png +0 -0
- {obs β trainval_obs/0}/10194.png +0 -0
- {obs β trainval_obs/0}/10202.png +0 -0
- {obs β trainval_obs/0}/1021.png +0 -0
- {obs β trainval_obs/0}/10210.png +0 -0
- {obs β trainval_obs/0}/10222.png +0 -0
- {obs β trainval_obs/0}/10230.png +0 -0
- {obs β trainval_obs/0}/10242.png +0 -0
- {obs β trainval_obs/0}/1025.png +0 -0
- {obs β trainval_obs/0}/10265.png +0 -0
- {obs β trainval_obs/0}/10295.png +0 -0
- {obs β trainval_obs/0}/10311.png +0 -0
- {obs β trainval_obs/0}/10318.png +0 -0
- {obs β trainval_obs/0}/10323.png +0 -0
- {obs β trainval_obs/0}/10327.png +0 -0
- {obs β trainval_obs/0}/10334.png +0 -0
- {obs β trainval_obs/0}/10356.png +0 -0
- {obs β trainval_obs/0}/1038.png +0 -0
- {obs β trainval_obs/0}/10393.png +0 -0
- {obs β trainval_obs/0}/10420.png +0 -0
- {obs β trainval_obs/0}/10458.png +0 -0
- {obs β trainval_obs/0}/10459.png +0 -0
- {obs β trainval_obs/0}/10462.png +0 -0
- {obs β trainval_obs/0}/10472.png +0 -0
- {obs β trainval_obs/0}/10481.png +0 -0
- {obs β trainval_obs/0}/1050.png +0 -0
- {obs β trainval_obs/0}/10501.png +0 -0
- {obs β trainval_obs/0}/10513.png +0 -0
- {obs β trainval_obs/0}/10520.png +0 -0
- {obs β trainval_obs/0}/10557.png +0 -0
- {obs β trainval_obs/0}/10570.png +0 -0
- {obs β trainval_obs/0}/10575.png +0 -0
- {obs β trainval_obs/0}/10618.png +0 -0
- {obs β trainval_obs/0}/10626.png +0 -0
.gitattributes
CHANGED
|
@@ -59,3 +59,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 59 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
| 60 |
.json filter=lfs diff=lfs merge=lfs -text
|
| 61 |
*.json filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 59 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
| 60 |
.json filter=lfs diff=lfs merge=lfs -text
|
| 61 |
*.json filter=lfs diff=lfs merge=lfs -text
|
| 62 |
+
updated_trainval.json filter=lfs diff=lfs merge=lfs -text
|
__pycache__/breakdown.cpython-312.pyc
ADDED
|
Binary file (3.62 kB). View file
|
|
|
trainval.json β misc/move_to_mapping.json
RENAMED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e14bc9912b92a5a5086ac7c1485aa5964445581302f51da291ee3cf9de290ad8
|
| 3 |
+
size 1862221
|
{obs β misc}/old2new.json
RENAMED
|
File without changes
|
refactor.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import os
|
| 3 |
+
import tqdm
|
| 4 |
+
def preprocess():
|
| 5 |
+
all_train = json.load(open('trainval.json', 'r'))
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
im_ids = set()
|
| 9 |
+
for vqa_id, vqa in all_train.items():
|
| 10 |
+
im_ids.add(vqa['obs'][0])
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
move_to_mapping = dict()
|
| 14 |
+
|
| 15 |
+
subfolder_id = 0
|
| 16 |
+
subfolder_num_items = 0
|
| 17 |
+
max_items = 5000
|
| 18 |
+
for im_id in im_ids:
|
| 19 |
+
move_to_mapping[im_id] = subfolder_id
|
| 20 |
+
subfolder_num_items += 1
|
| 21 |
+
if subfolder_num_items >= max_items:
|
| 22 |
+
subfolder_id += 1
|
| 23 |
+
subfolder_num_items = 0
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
json.dump(move_to_mapping, open('move_to_mapping.json', 'w'), indent=2)
|
| 27 |
+
print(len(im_ids))
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def refactor():
|
| 32 |
+
new_root_folder = 'trainval_obs'
|
| 33 |
+
if not os.path.exists(new_root_folder):
|
| 34 |
+
os.makedirs(new_root_folder)
|
| 35 |
+
move_to_mapping = json.load(open('move_to_mapping.json', 'r'))
|
| 36 |
+
all_train = json.load(open('trainval.json', 'r'))
|
| 37 |
+
|
| 38 |
+
for vqa_id, vqa in tqdm.tqdm(all_train.items(), total=len(all_train)):
|
| 39 |
+
im_id = vqa['obs'][0]
|
| 40 |
+
|
| 41 |
+
im_file_name = os.path.basename(im_id)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
subfolder_id = move_to_mapping[im_id]
|
| 45 |
+
subfolder_path = os.path.join(new_root_folder, str(subfolder_id))
|
| 46 |
+
|
| 47 |
+
new_im_path = os.path.join(subfolder_path, im_file_name)
|
| 48 |
+
|
| 49 |
+
if not os.path.exists(subfolder_path):
|
| 50 |
+
os.makedirs(subfolder_path)
|
| 51 |
+
if not os.path.exists(new_im_path):
|
| 52 |
+
#print(f'Moving {im_id} to {new_im_path}')
|
| 53 |
+
os.rename(im_id, new_im_path)
|
| 54 |
+
|
| 55 |
+
vqa['obs'] = [new_im_path]
|
| 56 |
+
|
| 57 |
+
json.dump(all_train, open('updated_trainval.json', 'w'), indent=2)
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def sanity_check():
|
| 61 |
+
prev_vqas = json.load(open('trainval.json', 'r'))
|
| 62 |
+
now_vqas = json.load(open('updated_trainval.json', 'r'))
|
| 63 |
+
assert len(prev_vqas) == len(now_vqas), 'Number of VQAs should be the same after refactoring.'
|
| 64 |
+
for vqa_id, vqa in now_vqas.items():
|
| 65 |
+
assert prev_vqas[vqa_id]['obs'][0] != vqa['obs'][0], 'VQA obs should be updated after refactoring.'
|
| 66 |
+
old_im_name = os.path.basename(prev_vqas[vqa_id]['obs'][0])
|
| 67 |
+
new_im_name = os.path.basename(vqa['obs'][0])
|
| 68 |
+
assert old_im_name == new_im_name, 'Image file names should be the same'
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
if __name__ == '__main__':
|
| 73 |
+
pass
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
|
{obs β trainval_obs/0}/10011.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/10020.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/10030.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/10047.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/1005.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/10055.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/10071.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/10113.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/10133.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/10135.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/10139.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/1019.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/10194.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/10202.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/1021.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/10210.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/10222.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/10230.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/10242.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/1025.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/10265.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/10295.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/10311.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/10318.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/10323.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/10327.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/10334.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/10356.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/1038.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/10393.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/10420.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/10458.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/10459.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/10462.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/10472.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/10481.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/1050.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/10501.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/10513.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/10520.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/10557.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/10570.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/10575.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/10618.png
RENAMED
|
File without changes
|
{obs β trainval_obs/0}/10626.png
RENAMED
|
File without changes
|