Jiaqi Wu
advisor: Prof. Eytan Adar
This work is built upon Attend-and-Excite:Attention-Based Semantic Guidance for Text-to-Image Diffusion Models (SIGGRAPH 2023).
The method can generate images guided by multi-object prompts and follow the soft mask layout condition by user input. in other words, input mask images don't need to be specific, but can only roughly tell the model where the objects should be. Also, in some cases, this method can generate reasonable results when original AAE and stable diffusion fail to aligh with the specific spatial relationship of the prompts. (e.g., a monkey riding a tiger)
![Screen Shot 2023-12-03 at 10 26 25 PM](https://private-user-images.githubusercontent.com/55591358/287582330-e80f9619-4518-4003-995f-ecdc2f541c15.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ0MjIzODgsIm5iZiI6MTcyNDQyMjA4OCwicGF0aCI6Ii81NTU5MTM1OC8yODc1ODIzMzAtZTgwZjk2MTktNDUxOC00MDAzLTk5NWYtZWNkYzJmNTQxYzE1LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODIzVDE0MDgwOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTNiNzZlZmQ4YzNjMWE5ODI2YjI5OGQyMjBjNDI0YWI1OTk3ZWNiOWZmZTRhN2NkN2MwYWRiNmE5YTUwZjgzYTcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.w4qRpg4GqBz03EnYLnqrA4EYEfszOzvBr6gUjxVrEHw)
Research question: How can we enable soft conditions on multiple objects layout in stable diffusion?
contributions:
• Built a new algorithm upon Attend and Excite (Attention-Based Semantic Guidance for Diffusion Models)
• Deployed a new loss function, directly regulating attention maps by input masks at the inference stage
• The new architecture can generate images guided by multi-object prompts and follow the mask layout
We provide addtional binary mask input for selected key tokens of the prompt. The instinct is to regulize the attention map of each token as close to the mask as possible. Here is how we construct our new loss function:
1.We want to maximize the values inside the mask (we call the matrix keeping only these values Inner), and also minimize the values outside of the mask (we call the matrix keeping only these values Outer).
![Screen Shot 2023-12-03 at 5 46 10 PM](https://private-user-images.githubusercontent.com/55591358/287554903-4478aded-07e5-48bc-b513-7e6427640737.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ0MjIzODgsIm5iZiI6MTcyNDQyMjA4OCwicGF0aCI6Ii81NTU5MTM1OC8yODc1NTQ5MDMtNDQ3OGFkZWQtMDdlNS00OGJjLWI1MTMtN2U2NDI3NjQwNzM3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODIzVDE0MDgwOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPThiMThlNGIwODg4YTMxMGE1NTUxZTEzZTU5YjViNzBlNmNmNDZmMDk3NmZmY2UxYjUyZjNkMTUxOGY4NjMzYWYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.wEvOLMjbEA2kKyikECBmQsd7EA2g0pDQNB4-TLBGlUw)
To compute this, for each attention map, we compute the Diff matrix = Inner-Outer, and try to minimize value: mean (Diff) in our loss function
2.Also, we want to make sure the attention map also regulated by the edge of the masks. To do this, we compute the edge matrix of each attention map:
![Screen Shot 2023-12-03 at 5 51 58 PM](https://private-user-images.githubusercontent.com/55591358/287555212-15744d07-6b61-40a7-b3f4-aa4536e1c28d.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ0MjIzODgsIm5iZiI6MTcyNDQyMjA4OCwicGF0aCI6Ii81NTU5MTM1OC8yODc1NTUyMTItMTU3NDRkMDctNmI2MS00MGE3LWIzZjQtYWE0NTM2ZTFjMjhkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODIzVDE0MDgwOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTgwMzJiOWZlMTgyZmQyZmYyYzZkZjZhNmY4MzljZDY4MzdjZTE0NTY0ZDBiMGFjMjNhMDQ0Y2Y3ZWY4YjVlNTAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.oFtRwHbOoo-tmcy2sbi-2-Bd2qYgE9fuPC3wa4BGkIQ)
In our loss function, we also try to maximize the edge matrix, by minimizing value: -sum (edge matrix).
Putting together, our loss function would be:
![Screen Shot 2023-12-03 at 6 05 54 PM](https://private-user-images.githubusercontent.com/55591358/287555917-eab80a0b-2a0e-4df6-8642-b43e78d07cf6.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ0MjIzODgsIm5iZiI6MTcyNDQyMjA4OCwicGF0aCI6Ii81NTU5MTM1OC8yODc1NTU5MTctZWFiODBhMGItMmEwZS00ZGY2LTg2NDItYjQzZTc4ZDA3Y2Y2LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODIzVDE0MDgwOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTQ0NzE5MjMzZTA1OWU3M2IzOWM5ZWYxYWM0ZWE1NDk2Zjc5ZTZlYTAyZGY3NzQyMDdjZTk1NDIyMDYwMDc2ZWQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.YgrICnTeE_IlCgt3vHpAHr6TJiADA2Sc2bM5WD0Vxqc)
notice that in real implementation, the edge part of the loss function can be eliminated, given the situation whether edge regularization is important in specific tasks. α is a hyperparameter that is usually 100.
MAAE overview:
![Screen Shot 2023-12-03 at 5 28 22 PM](https://private-user-images.githubusercontent.com/55591358/287553993-a1bc78cf-a849-418d-b7d5-d3fec34b3a48.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ0MjIzODgsIm5iZiI6MTcyNDQyMjA4OCwicGF0aCI6Ii81NTU5MTM1OC8yODc1NTM5OTMtYTFiYzc4Y2YtYTg0OS00MThkLWI3ZDUtZDNmZWMzNGIzYTQ4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODIzVDE0MDgwOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTk5ZTQxODFlMWNkNjY4Njc4ZGNkODVlM2FjNWE3NDMxMzkwYTI0YTE5YzRiOTNhZjZlZWMzMjFjMWQzOTQwNmImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0._oDf_zx5iJ5mNZjLyjEhf2AAQy1CER8YRQIha-ZaWy4)
In comparison, original AAE overview from paper:
![Screen Shot 2023-12-03 at 5 27 07 PM](https://private-user-images.githubusercontent.com/55591358/287553930-0bdb2490-fe1c-4842-90d6-67f8a92332ad.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ0MjIzODgsIm5iZiI6MTcyNDQyMjA4OCwicGF0aCI6Ii81NTU5MTM1OC8yODc1NTM5MzAtMGJkYjI0OTAtZmUxYy00ODQyLTkwZDYtNjdmOGE5MjMzMmFkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODIzVDE0MDgwOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWU0YWU2NzQxODU4Y2NkNjA5NzBlZmJlOTk4Y2Q4YTNmYzc1ZmI0ZTc4YTE5MzQ3MjgwODE1YzFjZjY3ODZjYzAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.y9064Xh9vop7UKYjQPRTiAdGXLLN477-dSHTgBhYYcw)
Although this is an efficient and effective way of mask guided layout in stable diffusion which requires no training cost, There are several limitations:
The method is not suitable for tasks that requires a precise mask or shape layout.
In some cases, the images generated by MAAE have worse quality than original AAE or stable diffusion
The method also extend the limitations of stable diffusion in poor performance in specific prompts (like usually prompts).
The method sometimes fail to generate reasonable images due to the limitation of inference-stage training, whereas changes in seeds can partly solve this problem.