deel.lipdp.pipeline module
AugmultConfig
dataclass
¶
Preprocessing options for images at training time.
Copied from https://github.com/google-deepmind/jax_privacy that was released under license Apache-2.0.
Attributes:
Name | Type | Description |
---|---|---|
augmult |
int
|
Number of augmentation multiplicities to use. |
random_crop |
bool
|
Whether to use random crops for data augmentation. |
random_flip |
bool
|
Whether to use random horizontal flips for data augmentation. |
random_color |
bool
|
Whether to use random color jittering for data augmentation. |
pad |
Union[int, None]
|
Optional padding before the image is cropped for data augmentation. |
Source code in deel/lipdp/pipeline.py
98 99 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 |
|
DatasetMetadata
dataclass
¶
class that handle dataset metadata that will be used to compute privacy guarantees
Source code in deel/lipdp/pipeline.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
apply_augmult(image, label, *, augmult, random_flip, random_crop, random_color, crop_size, pad)
¶
Augmult data augmentation (Hoffer et al., 2019; Fort et al., 2021).
Copied from https://github.com/google-deepmind/jax_privacy that was released under license Apache-2.0.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image |
Tensor
|
(single) image to augment. |
required |
label |
Tensor
|
label corresponding to the image (not modified by this function). |
required |
augmult |
int
|
number of augmentation multiplicities to use. This number should be non-negative (this function will fail if it is not). |
required |
random_flip |
bool
|
whether to use random horizontal flips for data augmentation. |
required |
random_crop |
bool
|
whether to use random crops for data augmentation. |
required |
random_color |
bool
|
whether to use random color jittering for data augmentation. |
required |
crop_size |
Sequence[int]
|
size of the crop for random crops. |
required |
pad |
Union[int, None]
|
optional padding before the image is cropped. |
required |
Returns:
images: augmented images with a new prepended dimension of size augmult
.
labels: repeated labels with a new prepended dimension of size augmult
.
Source code in deel/lipdp/pipeline.py
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 |
|
default_delta_value(dataset_metadata)
¶
Default policy to set delta value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_metadata |
DatasetMetadata
|
metadata of the dataset. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
default delta value. |
Source code in deel/lipdp/pipeline.py
367 368 369 370 371 372 373 374 375 376 377 378 379 380 |
|
load_adbench_data(dataset_name, dataset_dir, standardize=True, redownload=False)
¶
Load a dataset from the adbench package.
Source code in deel/lipdp/pipeline.py
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 |
|
load_and_prepare_images_data(dataset_name='mnist', batch_size=256, colorspace='RGB', bound_fct=None, drop_remainder=True, multiplicity=0)
¶
Load dataset_name image dataset using tensorflow datasets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_name |
str
|
name of the dataset to load. |
'mnist'
|
batch_size |
int
|
batch size |
256
|
colorspace |
str
|
one of RGB, HSV, YIQ, YUV |
'RGB'
|
drop_remainder |
bool
|
when true drop the last batch if it has less than batch_size elements. Defaults to True. |
True
|
multiplicity |
int
|
multiplicity of data-augmentation. 0 means no augmentation, 1 means standard augmentation, >1 means multiple. |
0
|
bound_fct |
callable
|
function that is responsible of bounding the inputs. Can be None, bound_normalize or bound_clip_value. None means that no clipping is performed, and max theoretical value is reported ( sqrt(whc) ). bound_normalize means that each input is normalized setting the bound to 1. bound_clip_value will clip norm to defined value. |
None
|
Returns:
Type | Description |
---|---|
ds_train, ds_test, metadata: two dataset, with data preparation, augmentation, shuffling and batching. Also return an DatasetMetadata object with infos about the dataset. |
Source code in deel/lipdp/pipeline.py
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 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 |
|
padding_input(x, pad)
¶
Pad input image through 'mirroring' on the four edges.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
Tensor
|
image to pad. |
required |
pad |
int
|
number of padding pixels. |
required |
Returns: Padded image.
Source code in deel/lipdp/pipeline.py
141 142 143 144 145 146 147 148 149 150 151 152 |
|
prepare_tabular_data(x_train, x_test, y_train, y_test, batch_size, bound_fct=None, drop_remainder=True)
¶
Convert Numpy dataset into tensorflow datasets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x_train |
array
|
input data, of shape (N, F) with floats. |
required |
x_test |
array
|
input data, of shape (N, F) with floats. |
required |
y_train |
array
|
labels in one hot encoding, of shape (N, C) with floats. |
required |
y_test |
array
|
labels in one hot encoding, of shape (N, C) with floats. |
required |
batch_size |
int
|
logical batch size |
required |
bound_fct |
callable
|
function that is responsible of bounding the inputs. Can be None, bound_normalize or bound_clip_value. None means that no clipping is performed, and max theoretical value is reported ( sqrt(whc) ). bound_normalize means that each input is normalized setting the bound to 1. bound_clip_value will clip norm to defined value. |
None
|
drop_remainder |
bool
|
when true drop the last batch if it has less than batch_size elements. Defaults to True. |
True
|
Returns:
Type | Description |
---|---|
ds_train, ds_test, metadata: two dataset, with data preparation, augmentation, shuffling and batching. Also return an DatasetMetadata object with infos about the dataset. |
Source code in deel/lipdp/pipeline.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 |
|
standardize_CIFAR(image)
¶
Standardize the image with the CIFAR10 mean and std dev.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image |
Tensor
|
image to standardize of shape (H,W,C) of type tf.float32. |
required |
Source code in deel/lipdp/pipeline.py
52 53 54 55 56 57 58 59 60 |
|