File size: 1,109 Bytes
1a32a03
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json
import os

data = json.load(open('llava_v1_5_mix1k_filter.json'))
LAYERS = [15, 20, 22, 23]

collection = []

for item in data:
    new_item = {}
    image_path = item['image']
    qs = item['conversations'][0]['value']
    label = item['conversations'][1]['value']
    idx_list =[]
    attn_path = []
    loss_list = []
    for idx, l in enumerate(LAYERS):
        idx_list.append(idx)
        attn_path.append(f'APICLIP_llava_ViT-L-14-336_{l}/1_3_BICUBIC_0/{image_path}')
        img = os.path.join(f'/mnt/bn/bes-mllm-shared/zhangyuan.kevin/attnmap/APICLIP_llava_ViT-L-14-336_{l}/1_3_BICUBIC_0/', image_path)

        # TODO: 计算loss
        # loss = Model(img, qs, label)
        loss = 1
        loss_list.append(loss)

    new_item['image'] = item['image']
    new_item['conversations'] = item['conversations']
    new_item['id'] = item['id']
    new_item['attn_map_path'] = attn_path
    new_item['attn_map_idx'] = idx_list
    new_item['llava_loss'] = loss_list

    collection.append(new_item)

with open('llava_v1_5_mix1k_reward.json', 'w') as f:
    json.dump(collection, f, indent=4)