mmagic.models.base_models.base_translation_model
¶
Module Contents¶
Classes¶
Base Translation Model. |
- class mmagic.models.base_models.base_translation_model.BaseTranslationModel(generator, discriminator, default_domain: str, reachable_domains: List[str], related_domains: List[str], data_preprocessor, discriminator_steps: int = 1, disc_init_steps: int = 0, real_img_key: str = 'real_img', loss_config: Optional[dict] = None)[source]¶
Bases:
mmengine.model.BaseModel
Base Translation Model.
Translation models can transfer images from one domain to another. Domain information like default_domain, reachable_domains are needed to initialize the class. And we also provide query functions like is_domain_reachable, get_other_domains.
You can get a specific generator based on the domain, and by specifying target_domain in the forward function, you can decide the domain of generated images. Considering the difference among different image translation models, we only provide the external interfaces mentioned above. When you implement image translation with a specific method, you can inherit both BaseTranslationModel and the method (e.g BaseGAN) and implement abstract methods.
- Parameters
default_domain (str) – Default output domain.
reachable_domains (list[str]) – Domains that can be generated by the model.
related_domains (list[str]) – Domains involved in training and testing. reachable_domains must be contained in related_domains. However, related_domains may contain source domains that are used to retrieve source images from data_batch but not in reachable_domains.
discriminator_steps (int) – The number of times the discriminator is completely updated before the generator is updated. Defaults to 1.
disc_init_steps (int) – The number of initial steps used only to train discriminators.
- init_weights()[source]¶
Initialize weights for the module dict.
- Parameters
pretrained (str, optional) – Path for pretrained weights. If given None, pretrained weights will not be loaded. Default: None.
- get_module(module)[source]¶
Get nn.ModuleDict to fit the MMDistributedDataParallel interface.
- Parameters
module (MMDistributedDataParallel | nn.ModuleDict) – The input module that needs processing.
- Returns
The ModuleDict of multiple networks.
- Return type
nn.ModuleDict
- forward(img, test_mode=False, **kwargs)[source]¶
Forward function.
- Parameters
img (tensor) – Input image tensor.
test_mode (bool) – Whether in test mode or not. Default: False.
kwargs (dict) – Other arguments.
- forward_train(img, target_domain, **kwargs)[source]¶
Forward function for training.
- Parameters
img (tensor) – Input image tensor.
target_domain (str) – Target domain of output image.
kwargs (dict) – Other arguments.
- Returns
Forward results.
- Return type
dict