|
|
--- |
|
|
license: openrail |
|
|
datasets: |
|
|
- balgot/stylegan3-annotated |
|
|
language: |
|
|
- en |
|
|
metrics: |
|
|
- mse |
|
|
tags: |
|
|
- face-generation |
|
|
- stylegan3 |
|
|
library_name: pytorch |
|
|
--- |
|
|
|
|
|
# Text-to-StyleGAN3 Latent Space Translation |
|
|
|
|
|
This model was created as a part of the project for FI:PA228 (Masaryk University), |
|
|
inspired by this paper: [Face Generation from Textual Features using Conditionally trained Inputs to Generative Adversarial Networks](https://arxiv.org/abs/2301.09123) |
|
|
|
|
|
It was trained on the generated dataset from BLIP and StyleGAN3. See the [corresponding notebook](https://colab.research.google.com/drive/14rDcCc0Xr1L1Ax3aKezEhmcn81vXGVQ7?usp=sharing) |
|
|
for further details. |
|
|
|
|
|
|
|
|
## How to use: |
|
|
|
|
|
|
|
|
```python |
|
|
import torch.nn as nn |
|
|
|
|
|
|
|
|
# for now, the model class needs to be defined, so... |
|
|
class LaTran(nn.Module): |
|
|
def __init__(self, *args, **kwargs): |
|
|
super().__init__(*args, **kwargs) |
|
|
self.pipe = nn.Sequential( |
|
|
nn.Linear(384, 512), |
|
|
nn.ReLU(), |
|
|
nn.Linear(512, 512) |
|
|
) |
|
|
|
|
|
def forward(self, v): |
|
|
return self.pipe(v.unsqueeze(1)) |
|
|
|
|
|
|
|
|
|
|
|
# Instantiate and load the model |
|
|
dev = ... # device to use |
|
|
PATH = "translation_model-sd.pt" # local path |
|
|
model = LaTran().to(dev) |
|
|
model.load_state_dict(torch.load(TRANSLATION_MODEL, map_location=dev)) |
|
|
``` |
|
|
|
|
|
## Demo |
|
|
|
|
|
For the demo of the whole pipeline, or how this model helps to generate a final image, |
|
|
visits [text-to-stylegan HF space](https://huggingface.co/spaces/balgot/text-to-stylegan3). |
|
|
|
|
|
## Examples |
|
|
|
|
|
* Prompt: `attractive young woman, blond hair` |
|
|
 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* Prompt initial: `cute young boy, blond hair, blue eyes, smiling` |
|
|
* Prompt second: `old man, short gray hair, glasses, wearing hat` |
|
|
<img src="https://huggingface.co/balgot/bert-2-stylegan3/resolve/main/young2old.gif" width="200" height="200" /> |