MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / get_alpha

Method get_alpha

diffusers/src/diffusers/models/resnet.py:753–782  ·  view source on GitHub ↗
(self, image_only_indicator: torch.Tensor, ndims: int)

Source from the content-addressed store, hash-verified

751 raise ValueError(f"Unknown merge strategy {self.merge_strategy}")
752
753 def get_alpha(self, image_only_indicator: torch.Tensor, ndims: int) -> torch.Tensor:
754 if self.merge_strategy == "fixed":
755 alpha = self.mix_factor
756
757 elif self.merge_strategy == "learned":
758 alpha = torch.sigmoid(self.mix_factor)
759
760 elif self.merge_strategy == "learned_with_images":
761 if image_only_indicator is None:
762 raise ValueError("Please provide image_only_indicator to use learned_with_images merge strategy")
763
764 alpha = torch.where(
765 image_only_indicator.bool(),
766 torch.ones(1, 1, device=image_only_indicator.device),
767 torch.sigmoid(self.mix_factor)[..., None],
768 )
769
770 # (batch, channel, frames, height, width)
771 if ndims == 5:
772 alpha = alpha[:, None, :, None, None]
773 # (batch*frames, height*width, channels)
774 elif ndims == 3:
775 alpha = alpha.reshape(-1)[:, None, None]
776 else:
777 raise ValueError(f"Unexpected ndims {ndims}. Dimensions should be 3 or 5")
778
779 else:
780 raise NotImplementedError
781
782 return alpha
783
784 def forward(
785 self,

Callers 1

forwardMethod · 0.95

Calls 1

sigmoidMethod · 0.80

Tested by

no test coverage detected