File size: 2,309 Bytes
a3b5ed7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from collections import defaultdict
import hashlib
import os
import json
import tqdm
import pandas as pd
WORK_DIR = os.path.dirname(os.path.abspath(__file__))

MD5 = {
    "MMGenBench-Domain.tsv": "5c10daf6e2c5f08bdfb0701aa6db86bb",
    "MMGenBench-Domain.json": "0a3164af5734192665e56b18d2fb2220",
    "MMGenBench-Test-label-count.json": "d256a30f90f6b732281aa6847fa33bb6",
    "MMGenBench-Test-label-index.json": "68372cda211b5ec85576cdc9f939656b",
    "MMGenBench-Test.json": "672789f8073f7f55a753c7f3d0ad075e",
    "MMGenBench-Test.tsv": "94f8dac6bbf7c20be403f99adeaa73da",
}


def main():
    for filename, md5 in MD5.items():
        with open(os.path.join(WORK_DIR, filename), 'rb') as f:
            assert md5 == hashlib.md5(f.read()).hexdigest(), f'{filename} md5 not match'
    print('MD5 check pass')

    print("Running data check")
    domain_tsv = pd.read_csv(os.path.join(WORK_DIR, 'MMGenBench-Domain.tsv'), sep='\t')
    domain_json = json.load(open(os.path.join(WORK_DIR, 'MMGenBench-Domain.json')))
    for i in range(len(domain_tsv)):
        tmp = domain_json[i]
        tmp['index'] = tmp['id']
        del tmp['id'], tmp['img_path']
        assert domain_tsv.iloc[i].to_dict() == tmp, f'{domain_tsv.iloc[i].to_dict()} != {tmp}'
    print('Domain check pass')

    test_tsv = pd.read_csv(os.path.join(WORK_DIR, 'MMGenBench-Test.tsv'), sep='\t')
    test_json = json.load(open(os.path.join(WORK_DIR, 'MMGenBench-Test.json')))
    test_label_index = json.load(open(os.path.join(WORK_DIR, 'MMGenBench-Test-label-index.json')))
    test_label_count = json.load(open(os.path.join(WORK_DIR, 'MMGenBench-Test-label-count.json')))
    label_index = defaultdict(list)
    label_count = defaultdict(int)
    for i in range(len(test_tsv)):
        tmp = test_json[i]

        for label in tmp['label']:
            label_index[label].append(i)
            label_count[label] += 1

        tmp['index'] = tmp['id']
        del tmp['id'], tmp['label'], tmp['label_detail']
        assert test_tsv.iloc[i].to_dict() == tmp, f'{test_tsv.iloc[i].to_dict()} != {tmp}'

    assert label_index == test_label_index, f'{label_index} != {test_label_index}'
    assert label_count == test_label_count, f'{label_count} != {test_label_count}'
    print('Test check pass')


if __name__ == '__main__':
    main()