mmagic.models.losses.loss_comps.clip_loss_comps
¶
Module Contents¶
Classes¶
Clip loss. In styleclip, this loss is used to optimize the latent code |
- class mmagic.models.losses.loss_comps.clip_loss_comps.CLIPLossComps(loss_weight: float = 1.0, data_info: Optional[dict] = None, clip_model: dict = dict(), loss_name: str = 'loss_clip')[source]¶
Bases:
torch.nn.Module
Clip loss. In styleclip, this loss is used to optimize the latent code to generate image that match the text.
In this loss, we may need to provide
image
,text
. Thus, an example of thedata_info
is:1data_info = dict( 2 image='fake_imgs', 3 text='descriptions')
Then, the module will automatically construct this mapping from the input data dictionary.
- Parameters
loss_weight (float, optional) – Weight of this loss item. Defaults to
1.
.data_info (dict, optional) – Dictionary contains the mapping between loss input args and data dictionary. If
None
, this module will directly pass the input data to the loss function. Defaults to None.clip_model (dict, optional) – Kwargs for clip loss model. Defaults to dict().
loss_name (str, optional) – Name of the loss item. If you want this loss item to be included into the backward graph, loss_ must be the prefix of the name. Defaults to ‘loss_clip’.
- forward(*args, **kwargs) torch.Tensor [source]¶
Forward function.
If
self.data_info
is notNone
, a dictionary containing all of the data and necessary modules should be passed into this function. If this dictionary is given as a non-keyword argument, it should be offered as the first argument. If you are using keyword argument, please name it as outputs_dict.If
self.data_info
isNone
, the input argument or key-word argument will be directly passed to loss function,third_party_net_loss
.
- static loss_name() str [source]¶
Loss Name.
This function must be implemented and will return the name of this loss function. This name will be used to combine different loss items by simple sum operation. In addition, if you want this loss item to be included into the backward graph, loss_ must be the prefix of the name.
- Returns
The name of this loss item.
- Return type
str