Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] AttentionRefine BUG & Add assets & TYPO in prompt-to-prompt project #2012

Merged
merged 8 commits into from
Sep 21, 2023

Conversation

Beaconsyh08
Copy link
Contributor

@Beaconsyh08 Beaconsyh08 commented Aug 31, 2023

Thanks for your contribution and we appreciate it a lot. The following instructions would make your pull request more healthy and more easily get feedback. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.

Motivation

  1. Make the prompt-to-prompt project's demo(~/mmagic/projects/prompt_to_prompt/visualize.ipynb) work
  2. Make the prompt-to-prompt AttentionRefine function work

Modification

1. ~/mmagic/projects/prompt_to_prompt/assets

In the demo notebook(~/mmagic/projects/prompt_to_prompt/visualize.ipynb), Part VAE vs DDIM Inversion vs Null-Text Inversion, Section 1. VAE reconstruction as the standard result. The code block loads the image path from [projects/prompt_to_prompt/assets/gnochi_mirror.jpeg]. However, the project doesn't contain the specific folder assets. Then, I download the gnochi_mirror image from prompt-to-prompt repository(https://github.com/google/prompt-to-prompt) and add it to the mmagic repository.

2. ~/mmagic/projects/prompt_to_prompt/models/seq_aligner.py
If you run the demo code in the above notebook, you will find that the AttentionRefine function doesn't work in the Section Prompt-to-prompt Editing. It shows

TypeError: list indices must be integers or slices, not tupleTypeError: list indices must be integers or slices, not tuple

Hence, the function get_matrix in ~/mmagic/projects/prompt_to_prompt/models/seq_aligner.py should be modified to make the function work.

def get_matrix(size_x, size_y, gap):
    matrix = []
    for i in range(size_x + 1):
        sub_matrix = []
        for j in range(size_y + 1):
            sub_matrix.append(0)
        matrix.append(sub_matrix)
    for j in range(1, size_y + 1):
        matrix[0][j] = j * gap
    for i in range(1, size_x + 1):
        matrix[i][0] = i * gap
    return np.array(matrix)
  1. ~/mmagic/projects/prompt_to_prompt/visualize.ipynb
    TYPO "1. VAE reconstruction as the a standard result" --> "1. VAE reconstruction as the standard result"

BC-breaking (Optional)

N/A

Use cases (Optional)

from mmengine import MODELS, Config
from mmengine.registry import init_default_scope

init_default_scope('mmagic')
config = 'configs/stable_diffusion/stable-diffusion_ddim_denoisingunet.py'
config = Config.fromfile(config).copy()
StableDiffuser = MODELS.build(config.model)
StableDiffuser = StableDiffuser.to('cuda')

prompts = ["a photo of Eiffel Tower",
           "a photo of Eiffel Tower at night"]
from models.ptp import AttentionRefine
controller = AttentionRefine(prompts, 50, cross_replace_steps=1.0,
                             self_replace_steps=.4, model=StableDiffuser)
images, _ = text2image_ldm_stable(StableDiffuser, prompts, controller, latent=None)
ptp_utils.view_images(images)

Checklist

Submitting this pull request means that,

Before PR:

  • I have read and followed the workflow indicated in the CONTRIBUTING.md to create this PR.
  • Pre-commit or linting tools indicated in CONTRIBUTING.md are used to fix the potential lint issues.
  • Bug fixes are covered by unit tests, the case that causes the bug should be added in the unit tests.
  • New functionalities are covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  • The documentation has been modified accordingly, including docstring or example tutorials.

After PR:

  • If the modification has potential influence on downstream or other related projects, this PR should be tested with some of those projects.
  • CLA has been signed and all committers have signed the CLA in this PR.

@CLAassistant
Copy link

CLAassistant commented Aug 31, 2023

CLA assistant check
All committers have signed the CLA.

@OpenMMLab-Assistant-004
Copy link

Hi @Beaconsyh08,

We'd like to express our appreciation for your valuable contributions to the mmagic. Your efforts have significantly aided in enhancing the project's quality.
It is our pleasure to invite you to join our community thorugh Discord_Special Interest Group (SIG) channel. This is a great place to share your experiences, discuss ideas, and connect with other like-minded people. To become a part of the SIG channel, send a message to the moderator, OpenMMLab, briefly introduce yourself and mention your open-source contributions in the #introductions channel. Our team will gladly facilitate your entry. We eagerly await your presence. Please follow this link to join us: ​https://discord.gg/UjgXkPWNqA.

If you're on WeChat, we'd also love for you to join our community there. Just add our assistant using the WeChat ID: openmmlabwx. When sending the friend request, remember to include the remark "mmsig + Github ID".

Thanks again for your awesome contribution, and we're excited to have you as part of our community!

Copy link
Collaborator

@liuwenran liuwenran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution!

@liuwenran liuwenran merged commit 5bfcda6 into open-mmlab:main Sep 21, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants