解缠组件

Domain Agnostic Learning with Disentangled Representations笔记

DADA框架:

(解读:D分为    1、类解缠:分离域不变特征和类无关特征; 2、域解缠:分离域不变特征和域特定特征

用标记的源域数据训练分类器C,通过C与D的对抗训练来使D生成类无关特征欺骗C,

域不变特征和域特定特征输入到DI中输出域标签,D和DI的对抗提取域不变特征。)

出发点:

目标域数据可能不只是来自一个域的数据(比较杂),如何把有标注的源域信息迁移到没有标注的任意目标域数据上(域标签不可用)?

难点:

  • 目标数据来自混合的目标域;
  • 类无关信息会导致负迁移。

所以不仅应该学习源和目标的不变性,还应该分离出特定类别的特征。

The disentangler D is responsible for disentangling the features (f G )
### StyleGAN 数据方法及实现 #### 的重要性 为了使生成的图像具有更好的可控性和多样性,操作至关重要。意味着将不同的语义属性分离出来,使得每个属性可以在不影响其他属性的情况下独立变化。 #### Mapping Network 的作用 Mapping network 是 StyleGAN 中的关键组件之一,在此网络中输入噪声向量 \( z \) 被映射成中间潜码 \( w \)[^5]。这种转换不仅能够增强模型的学习能力,还能有效降低特征间的相关性,从而促进特征的效果。具体而言,mapping network 可以生成一个不必严格遵循训练数据分布的新向量,进而减少不同特征之间的相互依赖关系。 #### AdaIN 层的作用机制 AdaIN (Adaptive Instance Normalization) 层负责引入风格信息并应用于卷积层产生的特征图上。通过调整这些特征图的标准差和均值,AdaIN 实现了对特定样式的模仿[^3]。由于 StyleGAN 使用的是从 mapping network 输出获得而非直接来自原始图片的样式参数,所以可以更加灵活地操纵所要施加的目标风格。 #### Truncation Trick 对的影响 尽管 truncation trick 主要是用来提升样本质量的一种技术手段,但它同样有助于改善某些程度上的特征效果。通过对潜在空间中的点实施一定程度上的约束——即让它们靠近中心位置——truncation trick 减少了极端情况的发生频率,间接促进了更为平滑且易于释的变化模式形成[^4]。 ```python import torch from stylegan import Generator, get_truncated_noise def disentangle_features(generator: Generator, latent_vector_w: torch.Tensor, feature_to_adjust_index: int, adjustment_value: float): """ Adjusts a specific feature within the W space of StyleGAN. Args: generator (Generator): The pretrained StyleGAN model. latent_vector_w (torch.Tensor): Latent vector in W space to be adjusted. feature_to_adjust_index (int): Index indicating which feature should be modified. adjustment_value (float): Value by which the selected feature will be changed. Returns: torch.Tensor: Modified latent vector with specified feature altered. """ # Create copy of original tensor to avoid modifying it directly new_latent_vector = latent_vector_w.clone() # Modify only one dimension corresponding to chosen index new_latent_vector[:, feature_to_adjust_index] += adjustment_value return new_latent_vector if __name__ == "__main__": device = "cuda" if torch.cuda.is_available() else "cpu" gen = Generator().to(device) # Generate random noise and map into W-space using pre-trained GAN's components seed = 0 num_samples = 1 truncated_z = get_truncated_noise(seed=seed, batch_size=num_samples).to(device) mapped_w = gen.mapping_network(truncated_z) # Choose an attribute/index you want to change; here we choose index `7` as example target_feature_idx = 7 adjust_amount = 2.0 # Positive or negative value depending on desired effect edited_w = disentangle_features(gen, mapped_w, target_feature_idx, adjust_amount) generated_image_edited = gen.synthesis_network(edited_w) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值