Mou11209203
commited on
Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
@@ -65,18 +65,21 @@ from diffusers import UNet2DModel, DDPMScheduler
|
|
65 |
import tqdm
|
66 |
|
67 |
# 1. Initialize the model
|
|
|
68 |
repo_id = "google/ddpm-celebahq-256"
|
69 |
-
|
|
|
70 |
model.to("cuda") # Move the model to GPU
|
71 |
-
|
72 |
|
73 |
# 2. Initialize the scheduler
|
74 |
-
scheduler = DDPMScheduler.from_pretrained(
|
|
|
75 |
|
76 |
# 3. Create an image with Gaussian noise
|
77 |
-
torch.manual_seed(0) #
|
78 |
noisy_sample = torch.randn(1, model.config.in_channels, model.config.sample_size, model.config.sample_size).to("cuda")
|
79 |
-
|
80 |
|
81 |
# 4. Define a function to display the image
|
82 |
def display_sample(sample, i):
|
@@ -85,13 +88,13 @@ def display_sample(sample, i):
|
|
85 |
image_processed = image_processed.numpy().astype(np.uint8)
|
86 |
|
87 |
image_pil = PIL.Image.fromarray(image_processed[0])
|
88 |
-
|
89 |
-
|
90 |
|
91 |
# 5. Reverse diffusion process
|
92 |
sample = noisy_sample
|
93 |
for i, t in enumerate(tqdm.tqdm(scheduler.timesteps)):
|
94 |
-
# 1. Predict noise residual
|
95 |
with torch.no_grad():
|
96 |
residual = model(sample, t).sample
|
97 |
|
@@ -102,7 +105,7 @@ for i, t in enumerate(tqdm.tqdm(scheduler.timesteps)):
|
|
102 |
if (i + 1) % 50 == 0:
|
103 |
display_sample(sample, i + 1)
|
104 |
|
105 |
-
|
106 |
```
|
107 |
|
108 |
## Training
|
|
|
65 |
import tqdm
|
66 |
|
67 |
# 1. Initialize the model
|
68 |
+
# Choose a model ID, use google's with use_safetensors=False, use Mou11209203's with use_safetensors=True
|
69 |
repo_id = "google/ddpm-celebahq-256"
|
70 |
+
repo_id1 = "Mou11209203/ddpm-celebahq-256"
|
71 |
+
model = UNet2DModel.from_pretrained(repo_id1, use_safetensors=True)
|
72 |
model.to("cuda") # Move the model to GPU
|
73 |
+
print("model.config: ", model.config)
|
74 |
|
75 |
# 2. Initialize the scheduler
|
76 |
+
scheduler = DDPMScheduler.from_pretrained(repo_id1)
|
77 |
+
print("scheduler.config: ", scheduler.config)
|
78 |
|
79 |
# 3. Create an image with Gaussian noise
|
80 |
+
torch.manual_seed(0) # Fix the random seed for reproducibility
|
81 |
noisy_sample = torch.randn(1, model.config.in_channels, model.config.sample_size, model.config.sample_size).to("cuda")
|
82 |
+
print(f"Noisy sample shape: {noisy_sample.shape}")
|
83 |
|
84 |
# 4. Define a function to display the image
|
85 |
def display_sample(sample, i):
|
|
|
88 |
image_processed = image_processed.numpy().astype(np.uint8)
|
89 |
|
90 |
image_pil = PIL.Image.fromarray(image_processed[0])
|
91 |
+
print(f"Image at step {i}")
|
92 |
+
image_pil.show()
|
93 |
|
94 |
# 5. Reverse diffusion process
|
95 |
sample = noisy_sample
|
96 |
for i, t in enumerate(tqdm.tqdm(scheduler.timesteps)):
|
97 |
+
# 1. Predict the noise residual
|
98 |
with torch.no_grad():
|
99 |
residual = model(sample, t).sample
|
100 |
|
|
|
105 |
if (i + 1) % 50 == 0:
|
106 |
display_sample(sample, i + 1)
|
107 |
|
108 |
+
print("Denoising complete.")
|
109 |
```
|
110 |
|
111 |
## Training
|