Skip to content

代码里面关于对潜在空间的扰动 #49

Open

Description

@Scientist888-star

您好!感谢您出彩的作品,对我的研究有很好借鉴意义,我在看您项目代码的时候有一些疑惑,我没太get到对于潜在空间扰动在代码里面如何体现的,代码其余部分我已理解,期待您的回复!

Activity

  1. WindVChen commented on Jun 5, 2025

    @WindVChen
    Owner

    哈喽 @niania-whb ,

    这一部分是指对扩散模型的隐变量直接做优化哈,可以看这部分的的代码段,隐变量为优化对象.

  2. Scientist888-star commented on Jun 5, 2025

    @Scientist888-star
    Author

    这个地方是对latent的有文本部分进行优化,然后用损失Ltransfer去逼近注意力点平均分布吗

  3. WindVChen commented on Jun 5, 2025

    @WindVChen
    Owner

    哈喽,准确来说是有三个损失函数共同作用哈(见此). 另外,这里是对整个 latent tensor 进行优化的,并不存在“latent 的文本部分”这种说法。在 classifier-free 的去噪过程中,会对 latent 进行复制,分别在带文本条件和空文本条件下进行去噪,最后将二者的结果融合 (见此).

  4. Scientist888-star commented on Jun 6, 2025

    @Scientist888-star
    Author

    好嘞,感谢您的解答,我已理解,谢谢!

  5. Scientist888-star commented on Jun 6, 2025

    @Scientist888-star
    Author

    发生异常: RuntimeError
    CUDA error: invalid argument
    CUDA kernel errors might be asynchronously reported at some other API call, so the stacktrace below might be incorrect.
    For debugging consider passing CUDA_LAUNCH_BLOCKING=1.
    Compile with TORCH_USE_CUDA_DSA to enable device-side assertions.
    File "/root/project/DiffAttack-main/diff_latent_attack.py", line 541, in diffattack
    loss.backward()
    File "/root/project/DiffAttack-main/main.py", line 72, in run_diffusion_attack
    adv_image, clean_acc, adv_acc = diff_latent_attack.diffattack(diffusion_model, label, controller,
    File "/root/project/DiffAttack-main/main.py", line 170, in
    adv_image, clean_acc, adv_acc = run_diffusion_attack(tmp_image, label[ind:ind + 1],
    RuntimeError: CUDA error: invalid argument
    CUDA kernel errors might be asynchronously reported at some other API call, so the stacktrace below might be incorrect.
    For debugging consider passing CUDA_LAUNCH_BLOCKING=1.
    Compile with TORCH_USE_CUDA_DSA to enable device-side assertions.

    您好,我运行时出现这个问题,loss不会出现nan或者inf,显存情况如下,cuda都放到gpu:0上,请问这个是啥问题呢

    Image

  6. WindVChen commented on Jun 6, 2025

    @WindVChen
    Owner

    这个蛮奇怪的,我这儿没有遇到过这个问题,有改动哪一部分代码嘛?是直接按照ReadMe里的步骤来跑的嘛?

  7. Scientist888-star commented on Jun 7, 2025

    @Scientist888-star
    Author

    目前没有改动代码,我使用了我自己的数据集,总共20各类别,我先使用预训练好的resnet,fc输出已改成20,不知道是啥情况,是不是跟torch版本有关,我从网上没找到解决办法,使用cpu跑就没问题

  8. WindVChen commented on Jun 12, 2025

    @WindVChen
    Owner

    哈喽 @niania-whb ,

    不好意思回复晚了,上面这个TORCH_USE_CUDA_DSA问题以及这个热力点的问题我不是很确定. 这两个问题在默认的ImageNet-Compatible数据集上会出现同样的问题吗?还是说目前只有在私有数据集上出现呢?

  9. Scientist888-star commented on Jun 12, 2025

    @Scientist888-star
    Author
  10. WindVChen commented on Jun 12, 2025

    @WindVChen
    Owner

    上面提到的"cross attention 之前 之后"是指什么呢?

    热力图是说变化不明显吗?我看上下两行系列上还是有些变化

  11. Scientist888-star commented on Jun 12, 2025

    @Scientist888-star
    Author
  12. WindVChen commented on Jun 13, 2025

    @WindVChen
    Owner

    可以尝试下增大transfer loss的权重,看看是否有更明显的变化?

    https://github.com/WindVChen/DiffAttack/blob/main/main.py#L46

  13. Scientist888-star commented on Jun 13, 2025

    @Scientist888-star
    Author
  14. WindVChen commented on Jun 14, 2025

    @WindVChen
    Owner

    我之前没有尝试过比较多的修饰词,大部分都是控制在1-3个文本之内.

    那可以先尝试下 1) 减少修饰词,比如约束在1-3个词之内;2) 尝试将structure loss的权重降低,因为它对于个人数据集来说,带来的约束可能比较强.

    看看这些是否带来改变.

  15. Scientist888-star commented on Jun 16, 2025

    @Scientist888-star
    Author

    好的谢谢您,我微调一下stable diffusion试试,您说的我修改后有一定提升

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions