How-to guide
In the project we put every functionality changes into yaml files. Every aspect of tunning, dataset change, trainer change can be done with simply changing parameters in the yaml file. Our pipeline uses hydra to load and manage pipeline with YAML structures. Firstly we will show you structure of the yaml file and than present you three sample yaml files used in this project. At the end we will also provide major modules used in the pipeline.
If you play to run train.py
script your yaml file need to be in conf
folder with the name config.yaml
as hydra loads this file for the script. If you want to make changes just to them to the fail and for saving for now just rename it 🥸.
your_project/
│
├── conf/
│ ├── config.yaml
│ └── legacy.yaml
│
├── modules/
│ ├── __init__.py
│ ├── config.py
│ ├── losses.py
│ ├── models.py
│ ├── training.py
│ ├── utils.py
│ └── vqgan.py
│
└── train.py
YAML Structures
Main yaml config file should have base structure LoadConfig
defined in modules.config.py
LoadConfig
Load configuration class to store the configuration of a train model and data. Main configuration class to be used for training.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
train |
DataConfig
|
data configuration. |
required |
data |
TrainConfig
|
training configuration. |
required |
Source code in modules/config.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
|
Config structure have two parameters data
specifying dataset and dataloader parameters and train
specifing architecture and training parameters.
DataConfig
Data configuration class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
train_params |
DataParams
|
training data parameters. Check DataParams for more details. |
required |
test_params |
DataParams
|
testing data parameters. Check DataParams for more details. |
required |
dataset_name |
str
|
name of the dataset to use. Currently only supports "voc". |
''
|
dataset_root |
str
|
root directory of the dataset. |
''
|
transform |
optional, dict
|
transform to apply to the dataset. Default None for no transf. Transform dict comes from albumentations library. Check albumentations for more details. Loading transform should proceed with albumentations.from_dict method. |
None
|
size |
int
|
size of image width and height. |
224
|
Source code in modules/config.py
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 |
|
DataConfig
tells everything you need to know about downloading Tensorflow datasets and processing it. Agumentation information for the pipeline is based on albumentations framework and please refer to it for additional changes. This config relays on train_params
and test_params
telling about shuffling and batch size for train and test splits.
DataParams
Train and test data parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch_size |
int
|
batch size for training. |
required |
shuffle |
bool
|
whether to shuffle the dataset. |
required |
Source code in modules/config.py
215 216 217 218 219 220 221 222 223 224 |
|
TrainConfig
Configuration class to store the configuration of a train model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_name |
str
|
name of the model to train. Used for saving and logging. |
required |
model_hparams |
VQGANConfig
|
model hyperparameters. Check VQGANConfig for more details. |
required |
disc_hparams |
DiscConfig
|
discriminator hyperparameters. Check DiscConfig for more details. |
required |
save_dir |
str
|
directory to save the model. |
required |
log_dir |
str
|
directory to save the logs for tensorboard. |
required |
check_val_every_n_epoch |
int
|
number of epochs to run validation. |
required |
log_img_every_n_epoch |
int
|
number of epochs to log images. |
required |
input_shape |
Tuple[int, int, int]
|
shape of the input image (H, W, C). |
required |
codebook_weight |
float
|
weight for the codebook loss (Quantizer part). |
required |
monitor |
str
|
metric to monitor for saving best model. |
required |
recon_loss |
str
|
reconstruction loss to use. Can be one of |
required |
disc_loss |
str
|
discriminator loss to use. Can be |
required |
disc_weight |
float
|
weight for the discriminator loss. |
required |
num_epochs |
int
|
number of epochs to train. |
required |
dtype |
str
|
dtype to use for training.
Supported: |
required |
distributed |
bool
|
whether to use distributed training. |
required |
seed |
int
|
seed for random number generation. |
required |
optimizer |
str
|
optimizer to use for training. Structure needs to be optax Optimizer (Check optax for more details) with 'target' parameter, for specifing optax optimizer, and 'kwargs' parameter for passing to optimizer. check config_test.yaml for example. |
required |
optimizer_disc |
str
|
optimizer to use for discriminator training. Similar to optimizer. |
required |
disc_start |
int
|
number of epochs to past to start using the discriminator. |
required |
temp_scheduler |
optional
|
temperature scheduler to use for training. Similar to optimizer but uses optax scheduler with 'target' parameter, for specifing optax scheduler. if None, then no scheduler is used. Check config_test.yaml for example. |
required |
Source code in modules/config.py
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 |
|
TrainConfig
is main config for setting trainer. The most important parameters are model_name
, save_dir
, log_dir
, dtype
, seed
, distributed
. dtype
, seed
and distributed
are parameters also used in datasets (For now we support only false for distributed
). save_dir
and log_dir
are paths for model checkpointing and tensorboard saving. model_name
is the name of model which is referenced in saving and logging to tensorboard so you need to keep an eye on this parameter. optimize
and temp_scheduler
are parameters which are instantiate by hydra and for this we use objects from optax
(please refer to samples). model_hparams
contains all the parameters for VQGAN module architecture and disc_hparams
contains parameters for Discriminator.
DiscConfig
Bases: PretrainedConfig
Configuration class to store the configuration of a Discriminator model.
Dataclass for storing is based on PretrainedConfig
from transformers
package.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_last_dim |
int
|
last dimension of the input sample in Discriminator. |
3
|
output_last_dim |
int
|
last dimension of the output sample in Discriminator. |
1
|
resolution |
int
|
resolution of the input image (256x256). |
256
|
ndf |
int
|
number of filters in the first layer of Discriminator. |
64
|
n_layers |
int
|
number of layers in Discriminator. |
3
|
Source code in modules/config.py
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 |
|
VQGANConfig
Bases: PretrainedConfig
Configuration class to store the configuration of a VQGAN model.
Dataclass for storing is based on PretrainedConfig
from transformers
package.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ch |
int
|
number of channels. |
128
|
out_ch |
int
|
number of output channels (RGB). |
3
|
in_channels |
int
|
number of input channels (RGB). |
3
|
num_res_blocks |
int
|
number of residual blocks. |
2
|
resolution |
int
|
resolution of the input image (256x256). |
256
|
z_channels |
int
|
number of channels in the latent space. |
256
|
ch_mult |
Tuple[int]
|
channel multiplier for each layer. |
tuple([1, 1, 2, 2, 4])
|
attn_resolutions |
Tuple[int]
|
resolutions at which to apply attention. |
(16)
|
n_embed |
int
|
number of embeddings, unique codes in the latent space. |
1024
|
embed_dim |
int
|
dimension of embedding from Encoder. |
256
|
dropout |
float
|
dropout rate. |
0.0
|
double_z |
bool
|
whether to double the latent space for. |
False
|
resamp_with_conv |
bool
|
whether to use convolutions for upsampling. |
True
|
use_gumbel |
bool
|
whether to use gumbel softmax for quantization. |
False
|
gumb_temp |
float
|
temperature for gumbel softmax. |
1.0
|
act_name |
str
|
activation function name to use. |
'swish'
|
give_pre_end |
bool
|
whether to give the pre-end layer for the decoder. |
False
|
kwargs |
Any
|
keyword arguments passed along to the super class. |
{}
|
Source code in modules/config.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 |
|
VQGANConfig
major parameter here is use_gumbel
. VQGAN can be trained with Gumbel-max Trick (Original paper) which gives our bottleneck distribution on which we choose argmax for the code to assign.
Samples
We provide three samples of data and train configs:
- config.yaml
my training config on imagenette
dataset.
- gumbel.yaml
official training config on imagenet
dataset.
- imagenet.yaml
official training config with Gumble tick on imagenet
dataset.
Major Modules
Major Modules used in the pipeline are:
TrainerVQGan
TrainerVQGan
in modules.training
, this modules responds for training VQGAN
Bases: TrainerModule
Helper functions for training VQGAN.
Source code in modules/training.py
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 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 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 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 |
|
checkpoint_exists()
Check whether a pretrained model exist.
Returns:
Type | Description |
---|---|
bool
|
True if model and discriminator exists, False otherwise. |
Source code in modules/training.py
454 455 456 457 458 459 460 461 |
|
create_functions()
Create training and eval functions.
Source code in modules/training.py
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 |
|
create_train_stat_full(optimizer, optimizer_disc)
Initialize training state.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
optimizer |
optax.GradientTransformation
|
Optimizer for generator. |
required |
optimizer_disc |
optax.GradientTransformation
|
Optimizer for discriminator. |
required |
Source code in modules/training.py
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 |
|
init_optimizer()
Initialize optimizer and scheduler also for discriminator. By default, we decrease the learning rate with cosine annealing.
Source code in modules/training.py
400 401 402 403 404 405 406 |
|
load_model()
Load model.
Source code in modules/training.py
439 440 441 442 443 444 445 446 447 448 449 450 451 452 |
|
save_model(step=None)
Save current model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
step |
int
|
Current step. Defaults to None. |
None
|
Source code in modules/training.py
428 429 430 431 432 433 434 435 436 437 |
|
temperature_scheduling(epoch)
Temperature scheduling.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
epoch |
int
|
Current epoch. |
required |
Returns:
Type | Description |
---|---|
float
|
Temperature. |
Source code in modules/training.py
388 389 390 391 392 393 394 395 396 397 398 |
|
train_epoch(data_loader, epoch)
Train model for one epoch, and log avg metrics.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_loader |
utils.DataLoader
|
Data loader to train on. |
required |
Returns:
Type | Description |
---|---|
Dict[str, float]
|
Dictionary with all metrics. |
Source code in modules/training.py
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 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 |
|
VQGANPreTrainedModel
VQGANPreTrainedModel
in modules.vqgan
, response for VQ autoencoder architecture. This class is based on FlaxPreTrainedModel
which gives ous abilities to push the architecture to Hugging Face Hub.
Bases: FlaxPreTrainedModel
An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained models.
Attributes:
Name | Type | Description |
---|---|---|
module_class |
nn.Module
|
a class derived from nn.Module that defines the model's core computation. |
config_class |
PretrainedConfig
|
a class derived from PretrainedConfig |
Source code in modules/vqgan.py
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 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 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 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 |
|
__call__(pixel_values, params=None, dropout_rng=None, gumble_rng=None, train=False)
Encode and decode the input.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pixel_values |
jnp.ndarray
|
the input to the encoder. |
required |
params |
Optional[FrozenDict]
|
the params of the model. Defaults to None. |
None
|
dropout_rng |
Optional[jnp.ndarray]
|
the dropout rng. Defaults to None. |
None
|
gumble_rng |
Optional[jnp.ndarray]
|
the gumbel rng. Defaults to None. If gumble_rng is None then the defult rng is used and produce deterministic results. |
None
|
train |
bool
|
Training or inference mode. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
jnp.ndarray
|
the encoded latent vector, |
jnp.ndarray
|
the decoded image, |
float
|
the log prob of the latent vector, |
jnp.ndarray
|
the indices of the latent vector. |
Source code in modules/vqgan.py
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 |
|
__init__(config=VQGANConfig(), input_shape=(1, 256, 256, 3), seed=0, dtype=jnp.float32, _do_init=True, **kwargs)
Initialize the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
PretrainedConfig
|
the config of the model. Defaults to VQGANConfig. |
VQGANConfig()
|
input_shape |
Tuple
|
the input shape of the model. Defaults to (1, 256, 256, 3). |
(1, 256, 256, 3)
|
seed |
int
|
the seed of the model. Defaults to 0. |
0
|
dtype |
jnp.dtype
|
the dtype of the computation. Defaults to jnp.float32. |
jnp.float32
|
_do_init |
bool
|
whether to initialize the model. Defaults to True. |
True
|
Source code in modules/vqgan.py
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 365 366 367 368 369 |
|
decode(z, params=None, dropout_rng=None, gumble_rng=None, train=False)
Decode the latent vector.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
z |
jnp.ndarray
|
the latent vector. |
required |
params |
Optional[FrozenDict]
|
the params of the model. Defaults to None. |
None
|
dropout_rng |
Union[Any, jnp.ndarray]
|
the dropout rng. Defaults to None. |
None
|
gumble_rng |
Union[Any, jnp.ndarray]
|
the gumbel rng. Defaults to None. |
None
|
train |
bool
|
Training or inference mode. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
jnp.ndarray
|
the decoded image. |
Source code in modules/vqgan.py
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 |
|
decode_code(indices, z_shape, params=None)
Decode the indices.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
indices |
jnp.ndarray
|
the indices. |
required |
z_shape |
Tuple[int, ...]
|
the shape of the latent vector. |
required |
params |
Optional[FrozenDict]
|
the params of the model. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
jnp.ndarray
|
the decoded image from indices. |
Source code in modules/vqgan.py
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 |
|
encode(pixel_values, params=None, dropout_rng=None, gumble_rng=None, train=False)
Encode the input.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pixel_values |
jnp.ndarray
|
the input to the encoder. |
required |
params |
Optional[FrozenDict]
|
the params of the model. Defaults to None. |
None
|
dropout_rng |
Union[Any, jnp.ndarray]
|
the dropout rng. Defaults to None. |
None
|
gumble_rng |
Union[Any, jnp.ndarray]
|
the gumbel rng. Defaults to None. |
None
|
train |
bool
|
Training or inference mode. Defaults to False. |
False
|
Source code in modules/vqgan.py
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 |
|
init_weights(rng, input_shape, params=None)
Initialize the weights of the model. Get the params
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rng |
Union[Any, jnp.ndarray]
|
the random number generator. |
required |
input_shape |
Tuple
|
the input shape of the model. |
required |
params |
FrozenDict
|
the params of the model. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
FrozenDict[str, Any]
|
initialized params of the model. |
Source code in modules/vqgan.py
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 |
|
update_temperature(temperature, params=None)
Update the temperature of the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
temperature |
float
|
the temperature to update to. |
required |
params |
Optional[FrozenDict]
|
the params of the model. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
float
|
the updated temperature. |
Source code in modules/vqgan.py
494 495 496 497 498 499 500 501 502 503 504 505 506 507 |
|
VQGanDiscriminator
VQGanDiscriminator
in modules.vqgan
, response for Discriminator architecture. This class is based on FlaxPreTrainedModel
which gives ous abilities to push the architecture to Hugging Face Hub.
Bases: FlaxPreTrainedModel
VQGAN discriminator model.
Attributes:
Name | Type | Description |
---|---|---|
module_class |
nn.Module
|
the discriminator module class (NLayerDiscriminator). |
Source code in modules/vqgan.py
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 |
|
TensorflowDataset
TensorflowDataset
in modules.utils
, response for loading Tensorflow datasets and prepering them. This class is based on BaseDataset
Bases: BaseDataset
Tensorflow dataset.
Source code in modules/utils.py
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 |
|
load_dataset(train)
Load the dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
train |
bool
|
If the dataset is for training. |
required |
Returns:
Type | Description |
---|---|
tf.data.Dataset
|
The dataset. |
Source code in modules/utils.py
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 |
|
Bases: ABC
Load the dataset. Abstract method.
Source code in modules/utils.py
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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
|
__init__(train, dtype, config)
Set the dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
train |
bool
|
If the dataset is for training. |
required |
config |
DataConfig
|
The config for the dataset. |
required |
Source code in modules/utils.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
__len__()
Return the length of the dataset.
Source code in modules/utils.py
103 104 105 |
|
get_dataset()
Return the dataset.
Returns:
Type | Description |
---|---|
tf.data.Dataset
|
The dataset. |
Source code in modules/utils.py
132 133 134 135 136 137 138 139 |
|
load_dataset(train)
abstractmethod
Load the dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
train |
bool
|
If the dataset is for training. |
required |
Returns:
Type | Description |
---|---|
tf.data.Dataset
|
The dataset. |
Source code in modules/utils.py
93 94 95 96 97 98 99 100 101 |
|
DataLoader
DataLoader
in modules.utils
, responses for wraping datasets and creating batches. Similar to Pytorch Dataloader
Dataloader similar as in pytorch.
Source code in modules/utils.py
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 |
|
__call__(*args, **kwds)
Return the dataset in dataloader style.
Source code in modules/utils.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
|
__init__(dataset, distributed)
Create a data loader.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset |
BaseDataset
|
The dataset to load. |
required |
distributed |
bool
|
If the data is distributed. |
required |
Source code in modules/utils.py
199 200 201 202 203 204 205 206 |
|
__len__()
Return the length of the dataset.
Source code in modules/utils.py
208 209 210 |
|