Abdualkader
commited on
Update pipeline.py
Browse files- pipeline.py +11 -13
pipeline.py
CHANGED
@@ -660,12 +660,12 @@ class MultiViewUNetModel(ModelMixin, ConfigMixin):
|
|
660 |
|
661 |
def __init__(
|
662 |
self,
|
|
|
|
|
|
|
|
|
663 |
num_res_blocks,
|
664 |
attention_resolutions,
|
665 |
-
image_size=512,
|
666 |
-
in_channels=4,
|
667 |
-
model_channels=320,
|
668 |
-
out_channels=4,
|
669 |
dropout=0,
|
670 |
channel_mult=(1, 2, 4, 8),
|
671 |
conv_resample=True,
|
@@ -687,7 +687,6 @@ class MultiViewUNetModel(ModelMixin, ConfigMixin):
|
|
687 |
**kwargs,
|
688 |
):
|
689 |
super().__init__()
|
690 |
-
self.image_size = image_size
|
691 |
assert context_dim is not None
|
692 |
|
693 |
if num_heads_upsample == -1:
|
@@ -1440,8 +1439,8 @@ class MVDreamPipeline(DiffusionPipeline):
|
|
1440 |
self,
|
1441 |
prompt: str = "",
|
1442 |
image: Optional[np.ndarray] = None,
|
1443 |
-
height: int =
|
1444 |
-
width: int =
|
1445 |
elevation: float = 0,
|
1446 |
num_inference_steps: int = 50,
|
1447 |
guidance_scale: float = 7.0,
|
@@ -1512,6 +1511,7 @@ class MVDreamPipeline(DiffusionPipeline):
|
|
1512 |
|
1513 |
# Denoising loop
|
1514 |
num_warmup_steps = len(timesteps) - num_inference_steps * self.scheduler.order
|
|
|
1515 |
total_loss = 0.0
|
1516 |
with self.progress_bar(total=num_inference_steps) as progress_bar:
|
1517 |
for i, t in enumerate(timesteps):
|
@@ -1555,12 +1555,10 @@ class MVDreamPipeline(DiffusionPipeline):
|
|
1555 |
noise_pred = noise_pred_uncond + guidance_scale * (
|
1556 |
noise_pred_text - noise_pred_uncond
|
1557 |
)
|
1558 |
-
|
1559 |
-
|
1560 |
-
loss = F.mse_loss(noise_pred, torch.zeros_like(noise_pred))
|
1561 |
-
|
1562 |
total_loss += loss.item()
|
1563 |
-
|
1564 |
# compute the previous noisy sample x_t -> x_t-1
|
1565 |
latents: torch.Tensor = self.scheduler.step(
|
1566 |
noise_pred, t, latents, **extra_step_kwargs, return_dict=False
|
@@ -1587,4 +1585,4 @@ class MVDreamPipeline(DiffusionPipeline):
|
|
1587 |
if hasattr(self, "final_offload_hook") and self.final_offload_hook is not None:
|
1588 |
self.final_offload_hook.offload()
|
1589 |
|
1590 |
-
return image,
|
|
|
660 |
|
661 |
def __init__(
|
662 |
self,
|
663 |
+
image_size,
|
664 |
+
in_channels,
|
665 |
+
model_channels,
|
666 |
+
out_channels,
|
667 |
num_res_blocks,
|
668 |
attention_resolutions,
|
|
|
|
|
|
|
|
|
669 |
dropout=0,
|
670 |
channel_mult=(1, 2, 4, 8),
|
671 |
conv_resample=True,
|
|
|
687 |
**kwargs,
|
688 |
):
|
689 |
super().__init__()
|
|
|
690 |
assert context_dim is not None
|
691 |
|
692 |
if num_heads_upsample == -1:
|
|
|
1439 |
self,
|
1440 |
prompt: str = "",
|
1441 |
image: Optional[np.ndarray] = None,
|
1442 |
+
height: int = 256,
|
1443 |
+
width: int = 256,
|
1444 |
elevation: float = 0,
|
1445 |
num_inference_steps: int = 50,
|
1446 |
guidance_scale: float = 7.0,
|
|
|
1511 |
|
1512 |
# Denoising loop
|
1513 |
num_warmup_steps = len(timesteps) - num_inference_steps * self.scheduler.order
|
1514 |
+
|
1515 |
total_loss = 0.0
|
1516 |
with self.progress_bar(total=num_inference_steps) as progress_bar:
|
1517 |
for i, t in enumerate(timesteps):
|
|
|
1555 |
noise_pred = noise_pred_uncond + guidance_scale * (
|
1556 |
noise_pred_text - noise_pred_uncond
|
1557 |
)
|
1558 |
+
target = torch.zeros_like(noise_pred) if latents.dim() == 4 else latents
|
1559 |
+
loss = F.mse_loss(noise_pred, target.detach())
|
|
|
|
|
1560 |
total_loss += loss.item()
|
1561 |
+
|
1562 |
# compute the previous noisy sample x_t -> x_t-1
|
1563 |
latents: torch.Tensor = self.scheduler.step(
|
1564 |
noise_pred, t, latents, **extra_step_kwargs, return_dict=False
|
|
|
1585 |
if hasattr(self, "final_offload_hook") and self.final_offload_hook is not None:
|
1586 |
self.final_offload_hook.offload()
|
1587 |
|
1588 |
+
return image,total_loss
|