开发
简体中文
nodes.py
LoadImage
i = Image.open(image_path) i = ImageOps.exif_transpose(i) if i.mode == 'I': i = i.point(lambda i: i * (1 / 255)) image = i.convert("RGB") image = np.array(image).astype(np.float32) / 255.0 image = torch.from_numpy(image)[None,]
SaveImage
for (batch_number, image) in enumerate(images): i = 255. * image.cpu().numpy() img = Image.fromarray(np.clip(i, 0, 255).astype(np.uint8)) filepath = # some path that takes the batch number into account img.save(filepath)
mask = 1.0 - mask
# 我们需要 [B,H,W,C],其中 C = 1 if len(mask.shape)==2: # 当前为 [H,W],插入 B 和 C 作为第1维 mask = mask[None,:,:,None] elif len(mask.shape)==3 and mask.shape[2]==1: # 当前为 [H,W,C] mask = mask[None,:,:,:] elif len(mask.shape)==3: # 当前为 [B,H,W] mask = mask[:,:,:,None]
# 将蒙版反转回原始透明层 mask = 1.0 - mask # 扩展 `C`(通道)维度 mask = mask.unsqueeze(-1) # 沿 `C` 维拼接(cat) rgba_image = torch.cat((rgb_image, mask), dim=-1)
weight2
class Noise_MixedNoise: def __init__(self, nosie1, noise2, weight2): self.noise1 = noise1 self.noise2 = noise2 self.weight2 = weight2 @property def seed(self): return self.noise1.seed def generate_noise(self, input_latent:torch.Tensor) -> torch.Tensor: noise1 = self.noise1.generate_noise(input_latent) noise2 = self.noise2.generate_noise(input_latent) return noise1 * (1.0-self.weight2) + noise2 * (self.weight2)
此页面对您有帮助吗?