rizavelioglu
commited on
Update README.md
Browse files
README.md
CHANGED
@@ -29,14 +29,33 @@ The models proposed in the paper _"TryOffDiff: Virtual-Try-Off via High-Fidelity
|
|
29 |
```python
|
30 |
from huggingface_hub import hf_hub_download
|
31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
path_model = hf_hub_download(
|
33 |
repo_id="rizavelioglu/tryoffdiff",
|
34 |
-
filename="tryoffdiff.pth", # or one of ["ldm-1", "ldm-2", "ldm-3", ...]
|
35 |
)
|
36 |
-
|
|
|
|
|
37 |
```
|
38 |
|
39 |
-
> Check out the demo code on [HuggingFace Spaces][hf_spaces] for
|
40 |
|
41 |
> Also, check out [GitHub repository][github] to get more information on
|
42 |
> training, inference, and evaluation.
|
@@ -58,7 +77,7 @@ If you find this repository useful in your research, please consider giving a st
|
|
58 |
}
|
59 |
```
|
60 |
|
61 |
-
[hf_spaces]: https://huggingface.co/spaces/rizavelioglu/tryoffdiff
|
62 |
[project_page]: https://rizavelioglu.github.io/tryoffdiff/
|
63 |
[paper_arxiv]: https://arxiv.org/abs/2411.18350
|
64 |
[github]: https://github.com/rizavelioglu/tryoffdiff
|
|
|
29 |
```python
|
30 |
from huggingface_hub import hf_hub_download
|
31 |
|
32 |
+
class TryOffDiff(nn.Module):
|
33 |
+
def __init__(self):
|
34 |
+
super().__init__()
|
35 |
+
self.unet = UNet2DConditionModel.from_pretrained("CompVis/stable-diffusion-v1-4", subfolder="unet")
|
36 |
+
self.transformer = torch.nn.TransformerEncoderLayer(d_model=768, nhead=8, batch_first=True)
|
37 |
+
self.proj = nn.Linear(1024, 77)
|
38 |
+
self.norm = nn.LayerNorm(768)
|
39 |
+
|
40 |
+
def adapt_embeddings(self, x):
|
41 |
+
x = self.transformer(x)
|
42 |
+
x = self.proj(x.permute(0, 2, 1)).permute(0, 2, 1)
|
43 |
+
return self.norm(x)
|
44 |
+
|
45 |
+
def forward(self, noisy_latents, t, cond_emb):
|
46 |
+
cond_emb = self.adapt_embeddings(cond_emb)
|
47 |
+
return self.unet(noisy_latents, t, encoder_hidden_states=cond_emb).sample
|
48 |
+
|
49 |
path_model = hf_hub_download(
|
50 |
repo_id="rizavelioglu/tryoffdiff",
|
51 |
+
filename="tryoffdiff.pth", # or one of ablations ["ldm-1", "ldm-2", "ldm-3", ...]
|
52 |
)
|
53 |
+
net = TryOffDiff()
|
54 |
+
net.load_state_dict(torch.load(path_model, weights_only=False))
|
55 |
+
net.eval().to(device)
|
56 |
```
|
57 |
|
58 |
+
> Check out the demo code on [HuggingFace Spaces][hf_spaces] for the full running example.
|
59 |
|
60 |
> Also, check out [GitHub repository][github] to get more information on
|
61 |
> training, inference, and evaluation.
|
|
|
77 |
}
|
78 |
```
|
79 |
|
80 |
+
[hf_spaces]: https://huggingface.co/spaces/rizavelioglu/tryoffdiff/blob/main/app.py
|
81 |
[project_page]: https://rizavelioglu.github.io/tryoffdiff/
|
82 |
[paper_arxiv]: https://arxiv.org/abs/2411.18350
|
83 |
[github]: https://github.com/rizavelioglu/tryoffdiff
|