File size: 2,566 Bytes
d6145b2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
60
61
62
63
64
import os

def get_dataset_info(args, split):
    if args.EVAL_DATASET == 'pascal':
        # data_dir = 'data/PF-dataset-PASCAL'
        data_dir = '../../Datasets/PF-dataset-PASCAL'
        categories = sorted(os.listdir(os.path.join(data_dir, 'Annotations')))
    # elif args.EVAL_DATASET == 'ap10k':
    #     data_dir = 'data/ap-10k'
    #     categories = []
    #     subfolders = os.listdir(os.path.join(data_dir, 'ImageAnnotation'))
    #     # Handle AP10K_EVAL test settings
    #     if args.AP10K_EVAL_SUBSET == 'intra-species':
    #         categories = [folder for subfolder in subfolders for folder in os.listdir(os.path.join(data_dir, 'ImageAnnotation', subfolder))]
    #     elif args.AP10K_EVAL_SUBSET == 'cross-species':
    #         categories = [subfolder for subfolder in subfolders if len(os.listdir(os.path.join(data_dir, 'ImageAnnotation', subfolder))) > 1]
    #         split += '_cross_species'
    #     elif args.AP10K_EVAL_SUBSET == 'cross-family':
    #         categories = ['all']
    #         split += '_cross_family'
    #     categories = sorted(categories)
    #     if split == 'val':
    #         # remove category "king cheetah" from categories, since it is not present in the validation set
    #         categories.remove('king cheetah')
    elif args.EVAL_DATASET == 'spair': # SPair
        # data_dir = 'data/SPair-71k'
        data_dir = '../../Datasets/SPair-71k'
        categories = sorted(os.listdir(os.path.join(data_dir, 'ImageAnnotation')))

    return data_dir, categories, split



# SPair-71k dataset for batch processing
from PIL import Image
from torch.utils.data import Dataset

class VLDataset(Dataset):
    """A simple dataset to wrap a list of images and prompts for the DataLoader."""
    def __init__(self, images, prompts):
        self.images = images
        self.prompts = prompts

    def __len__(self):
        return len(self.images)

    def __getitem__(self, idx):
        # The DataLoader will call this for each item
        return self.images[idx], self.prompts[idx]
    

class VLDatasetPaired(Dataset):
    """A simple dataset to wrap a list of images and prompts for the DataLoader."""
    def __init__(self, source_imgs, target_imgs, prompts):
        self.source_imgs = source_imgs
        self.target_imgs = target_imgs
        self.prompts = prompts

    def __len__(self):
        return len(self.source_imgs)

    def __getitem__(self, idx):
        # The DataLoader will call this for each item
        return self.source_imgs[idx], self.target_imgs[idx], self.prompts[idx]