-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* support winoground. re-use image_caption_selection for both sugar crepe and winoground. * minor
- Loading branch information
Showing
4 changed files
with
84 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import os | ||
from torch.utils.data import Dataset | ||
from PIL import Image | ||
import torch | ||
import json | ||
|
||
class WinoGround(Dataset): | ||
|
||
def __init__(self, root=".", transform=None): | ||
from datasets import load_dataset | ||
self.ds = load_dataset("facebook/winoground", cache_dir=root)["test"] | ||
self.transform = transform | ||
|
||
def __getitem__(self, idx): | ||
data = self.ds[idx] | ||
img0 = data["image_0"] | ||
img1 = data["image_1"] | ||
cap0 = data["caption_0"] | ||
cap1 = data["caption_1"] | ||
if self.transform is not None: | ||
img0 = self.transform(img0) | ||
img1 = self.transform(img1) | ||
imgs = torch.stack([img0, img1]) | ||
else: | ||
imgs = [img0, img1] | ||
caps = [cap0, cap1] | ||
return imgs, caps | ||
|
||
def __len__(self): | ||
return len(self.ds) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters