mmagic.models.editors.cyclegan.cyclegan
¶
Module Contents¶
Classes¶
CycleGAN model for unpaired image-to-image translation. |
- class mmagic.models.editors.cyclegan.cyclegan.CycleGAN(*args, buffer_size=50, loss_config=dict(cycle_loss_weight=10.0, id_loss_weight=0.5), **kwargs)[source]¶
Bases:
mmagic.models.base_models.BaseTranslationModel
CycleGAN model for unpaired image-to-image translation.
Ref: Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networks
- forward_test(img, target_domain, **kwargs)[source]¶
Forward function for testing.
- Parameters
img (tensor) – Input image tensor.
target_domain (str) – Target domain of output image.
kwargs (dict) – Other arguments.
- Returns
Forward results.
- Return type
dict
- _get_disc_loss(outputs)[source]¶
Backward function for the discriminators.
- Parameters
outputs (dict) – Dict of forward results.
- Returns
Discriminators’ loss and loss dict.
- Return type
dict
- _get_gen_loss(outputs)[source]¶
Backward function for the generators.
- Parameters
outputs (dict) – Dict of forward results.
- Returns
Generators’ loss and loss dict.
- Return type
dict
- _get_opposite_domain(domain)[source]¶
Get the opposite domain respect to the input domain.
- Parameters
domain (str) – The input domain.
- Returns
The opposite domain.
- Return type
str
- train_step(data: dict, optim_wrapper: mmengine.optim.OptimWrapperDict)[source]¶
Training step function.
- Parameters
data_batch (dict) – Dict of the input data batch.
optimizer (dict[torch.optim.Optimizer]) – Dict of optimizers for the generators and discriminators.
ddp_reducer (
Reducer
| None, optional) – Reducer from ddp. It is used to prepare forbackward()
in ddp. Defaults to None.running_status (dict | None, optional) – Contains necessary basic information for training, e.g., iteration number. Defaults to None.
- Returns
Dict of loss, information for logger, the number of samples and results for visualization.
- Return type
dict
- test_step(data: dict) mmagic.utils.typing.SampleList [source]¶
Gets the generated image of given data. Same as
val_step()
.- Parameters
data (dict) – Data sampled from metric specific sampler. More details in Metrics and Evaluator.
- Returns
A list of
DataSample
contain generated results.- Return type
SampleList
- val_step(data: dict) mmagic.utils.typing.SampleList [source]¶
Gets the generated image of given data. Same as
val_step()
.- Parameters
data (dict) – Data sampled from metric specific sampler. More details in Metrics and Evaluator.
- Returns
A list of
DataSample
contain generated results.- Return type
SampleList