fusion_bench.dataset¶
NYUv2 Dataset¶
fusion_bench.dataset.nyuv2.NYUv2
¶
Bases: Dataset
NYUv2 dataset, 3 tasks + 1 generated useless task Included tasks:
1. Semantic Segmentation,
2. Depth prediction,
3. Surface Normal prediction,
4. Noise prediction [to test auxiliary learning, purely conflict gradients]
Modified from https://github.com/lorenmt/auto-lambda/blob/main/create_dataset.py
removed the augmentation
arg and add transform
args
Source code in fusion_bench/dataset/nyuv2.py
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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
|
__getitem__(index)
¶
Retrieve an item from the dataset.
Parameters:
-
index
(int
) –The index of the item to retrieve.
Returns:
-
tuple
–A tuple containing the image and a dictionary of task-specific outputs.
Source code in fusion_bench/dataset/nyuv2.py
__init__(root, train=True, transform=None, seg_transform=None, sn_transform=None, depth_transform=None)
¶
Initialize the NYUv2 dataset.
Parameters:
-
root
(str
) –The root directory of the dataset.
-
train
(bool
, default:True
) –If True, use training set. If False, use validation set. Defaults to True.
-
transform
(Callable
, default:None
) –image transform. Defaults to None.
-
seg_transform
(Callable
, default:None
) –segmentation transform. Defaults to None.
-
sn_transform
(Callable
, default:None
) –surface normal transform. Defaults to None.
-
depth_transform
(Callable
, default:None
) –depth transform. Defaults to None.
Source code in fusion_bench/dataset/nyuv2.py
Image Classification Tasks¶
fusion_bench.dataset.clip_dataset.CLIPDataset
¶
Bases: Dataset
A dataset class for CLIP models that converts a dataset of dictionaries or tuples into a format suitable for CLIP processing.
This class wraps an existing dataset and applies CLIP preprocessing to the images. It expects each item in the dataset to be either a dictionary with 'image' and 'label' keys, or a tuple/list of (image, label).
Parameters:
-
dataset
–The original dataset to wrap.
-
processor
(CLIPProcessor
, default:None
) –The CLIP processor for preparing inputs. If None, no preprocessing is applied and raw images are returned.
Attributes:
-
dataset
–The wrapped dataset.
-
processor
(CLIPProcessor
) –The CLIP processor used for image preprocessing.
Source code in fusion_bench/dataset/clip_dataset.py
__getitem__(idx)
¶
Retrieves and processes an item from the dataset.
Parameters:
-
idx
(int
) –The index of the item to retrieve.
Returns:
-
tuple
(Tuple[Tensor, int]
) –A tuple containing the processed image tensor and the label.
Raises:
-
ValueError
–If the item is neither a dictionary nor a tuple/list of length 2.
Source code in fusion_bench/dataset/clip_dataset.py
fusion_bench.dataset.image_dataset.TransformedImageDataset
¶
Bases: Dataset
A dataset class for image classification tasks that applies a transform to images.
This class wraps an existing dataset and applies a specified transform to the images. It expects each item in the dataset to be either a dictionary with 'image' and 'label' keys, or a tuple/list of (image, label).
Parameters:
-
dataset
–The original dataset to wrap.
-
transform
(Callable
) –A function/transform to apply on the image.
Attributes:
-
dataset
–The wrapped dataset.
-
transform
(Callable
) –The transform to be applied to the images.
Source code in fusion_bench/dataset/image_dataset.py
__getitem__(idx)
¶
Retrieves and processes an item from the dataset.
Parameters:
-
idx
(int
) –The index of the item to retrieve.
Returns:
-
tuple
(Tuple[Any, Any]
) –A tuple containing the processed image and the label.
Raises:
-
ValueError
–If the item is neither a dictionary nor a tuple/list of length 2.
Source code in fusion_bench/dataset/image_dataset.py
GPT-2 on GLUE Benchmark¶
fusion_bench.dataset.gpt2_glue.TokenizedGLUE
¶
A class to load and cache GLUE datasets for GPT-2 models.
This class provides methods to load various GLUE datasets and tokenize them using a provided tokenizer. The datasets are cached to disk to avoid reloading and tokenizing them multiple times.
Attributes:
-
tokenizer
(PreTrainedTokenizer
) –The tokenizer to use for tokenizing the datasets.
Source code in fusion_bench/dataset/gpt2_glue.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
|
__init__(tokenizer)
¶
Initialize the TokenizedGLUE class with a tokenizer.
Parameters:
-
tokenizer
(PreTrainedTokenizer
) –The tokenizer to use for tokenizing the datasets.
Source code in fusion_bench/dataset/gpt2_glue.py
load_cola_dataset()
¶
Load and tokenize the CoLA dataset.
This method loads the CoLA dataset, tokenizes it using the provided tokenizer, and caches the tokenized dataset to disk.
Returns:
-
Dataset
–The tokenized CoLA dataset.
Source code in fusion_bench/dataset/gpt2_glue.py
load_dataset(name)
¶
Load and tokenize a GLUE dataset.
This method loads a specified GLUE dataset, tokenizes it using the provided tokenizer, and caches the tokenized dataset to disk.
Parameters:
-
name
(Literal['mrpc', 'mnli', 'cola', 'sst2', 'qnli', 'qqp', 'rte']
) –The name of the GLUE dataset to load.
Returns:
-
Dataset
–The tokenized GLUE dataset.
Source code in fusion_bench/dataset/gpt2_glue.py
load_mnli_dataset()
¶
Load and tokenize the MNLI dataset.
This method loads the MNLI dataset, tokenizes it using the provided tokenizer, and caches the tokenized dataset to disk.
Returns:
-
Dataset
–The tokenized MNLI dataset.
Source code in fusion_bench/dataset/gpt2_glue.py
load_mrpc_dataset()
¶
Load and tokenize the MRPC dataset.
This method loads the MRPC dataset, tokenizes it using the provided tokenizer, and caches the tokenized dataset to disk.
Returns:
-
Dataset
–The tokenized MRPC dataset.
Source code in fusion_bench/dataset/gpt2_glue.py
load_qnli_dataset()
¶
Load and tokenize the QNLI dataset.
This method loads the QNLI dataset, tokenizes it using the provided tokenizer, and caches the tokenized dataset to disk.
Returns:
-
Dataset
–The tokenized QNLI dataset.
Source code in fusion_bench/dataset/gpt2_glue.py
load_qqp_dataset()
¶
Load and tokenize the QQP dataset.
This method loads the QQP dataset, tokenizes it using the provided tokenizer, and caches the tokenized dataset to disk.
Returns:
-
Dataset
–The tokenized QQP dataset.
Source code in fusion_bench/dataset/gpt2_glue.py
load_rte_dataset()
¶
Load and tokenize the RTE dataset.
This method loads the RTE dataset, tokenizes it using the provided tokenizer, and caches the tokenized dataset to disk.
Returns:
-
Dataset
–The tokenized RTE dataset.
Source code in fusion_bench/dataset/gpt2_glue.py
load_sst2_dataset()
¶
Load and tokenize the SST-2 dataset.
This method loads the SST-2 dataset, tokenizes it using the provided tokenizer, and caches the tokenized dataset to disk.
Returns:
-
Dataset
–The tokenized SST-2 dataset.
Source code in fusion_bench/dataset/gpt2_glue.py
load_wnli_dataset()
¶
Load and tokenize the WNLI dataset.
This method loads the WNLI dataset, tokenizes it using the provided tokenizer, and caches the tokenized dataset to disk.
Returns:
-
Dataset
–The tokenized WNLI dataset.