Spaces:
Runtime error
Runtime error
shionhonda
commited on
Commit
•
7402229
1
Parent(s):
b736daf
Upload 4 files
Browse files- README.md +1 -1
- app.py +38 -0
- model-final.pt +3 -0
- requirements.txt +1 -0
README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
---
|
2 |
title: Sushi Diffusion
|
3 |
-
emoji:
|
4 |
colorFrom: yellow
|
5 |
colorTo: blue
|
6 |
sdk: streamlit
|
|
|
1 |
---
|
2 |
title: Sushi Diffusion
|
3 |
+
emoji: 🍣
|
4 |
colorFrom: yellow
|
5 |
colorTo: blue
|
6 |
sdk: streamlit
|
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from denoising_diffusion_pytorch import Unet, GaussianDiffusion
|
2 |
+
import streamlit as st
|
3 |
+
import torch
|
4 |
+
|
5 |
+
|
6 |
+
def get_model():
|
7 |
+
unet = Unet(
|
8 |
+
dim = 64,
|
9 |
+
dim_mults = (1, 2, 4, 8)
|
10 |
+
)
|
11 |
+
model = GaussianDiffusion(
|
12 |
+
unet,
|
13 |
+
image_size = 64,
|
14 |
+
timesteps = 1000, # number of steps
|
15 |
+
sampling_timesteps = 250, # number of sampling timesteps (using ddim for faster inference [see citation for ddim paper])
|
16 |
+
loss_type = 'l1' , # L1 or L2
|
17 |
+
p2_loss_weight_gamma = 1.
|
18 |
+
)
|
19 |
+
model.load_state_dict(torch.load("./model-final.pt", map_location="cpu"))
|
20 |
+
model.eval()
|
21 |
+
return model
|
22 |
+
|
23 |
+
def generate_image(model):
|
24 |
+
img = torch.randn((1,3,64,64), device="cpu")
|
25 |
+
for t in reversed(range(0, model.num_timesteps)):
|
26 |
+
img, _ = model.p_sample(img, t, None)
|
27 |
+
return scale_to_255(img.squeeze().numpy().transpose(1,2,0))
|
28 |
+
|
29 |
+
def scale_to_255(x):
|
30 |
+
return ((x+1)/2*255).astype('uint8')
|
31 |
+
|
32 |
+
if __name__ == "__main__":
|
33 |
+
st.title("Sushi Diffusion")
|
34 |
+
st.text('It takes about 10 mins for the generation process. Thanks for your patience!')
|
35 |
+
model = get_model()
|
36 |
+
if st.button('🍣'):
|
37 |
+
img = generate_image(model)
|
38 |
+
st.image(img, caption='This sushi does not exist.')
|
model-final.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4810e45bbdf1334e9cd2eeb35d34422663a2c8049cbc77a43c48be3ef5473494
|
3 |
+
size 145163071
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
denoising_diffusion_pytorch==0.27.12
|