0


使用HuggingFace实现 DiffEdit论文的掩码引导语义图像编辑

在本文中,我们将实现Meta AI和Sorbonne Universite的研究人员最近发表的一篇名为DIFFEDIT的论文。对于那些熟悉稳定扩散过程或者想了解DiffEdit是如何工作的人来说,这篇文章将对你有所帮助。

什么是DiffEdit?

简单地说,可以将DiffEdit方法看作图像到图像的一个更受控制的版本。DiffEdit接受三个输入-

  1. 输入图像
  2. 标题-描述输入图像
  3. 目标查询文本-描述想要生成的新图像的文本

模型会根据查询文本生成原始图像的修改版本。如果您想对实际图像进行轻微调整而不需要完全修改它,那么使用DiffEdit是非常有效的。

从上图中可以看到,只有水果部分被梨代替了。这是一个非常惊人的结果!

论文作者解释说,他们实现这一目标的方法是引入一个遮蔽生成模块,该模块确定图像的哪一部分应该被编辑,然后只对遮罩部分执行基于文本的扩散。

从上面这张论文中截取的图片中可以看到,作者从输入的图像中创建了一个掩码,确定了图像中出现水果的部分(如橙色所示),然后进行掩码扩散,将水果替换为梨。作者提供了整个DiffEdit过程的良好可视化表示。

这篇论文中,生成遮蔽掩码似乎是最重要的步骤,其他的部分是使用文本条件进行扩散过程的调节。使用掩码对图像进行调节的方法与在“Hugging face”的In-Paint 实现的想法类似。正如作者所建议的,“DiffEdit过程有三个步骤:

步骤1:为输入图像添加噪声,并去噪:一次参考提示文本,一次参考查询文本(或无条件,也就是不参考任何文本),并根据去噪结果的差异推导出一个掩码。

步骤2:对输入图像进行DDIM编码,估计与输入图像相对应的潜在值

步骤3:在文本查询条件下执行DDIM解码,使用推断的掩码将背景替换为来自编码过程中相应时间步" 1 "的像素值

下面我们将这些思想实现到实际的代码中。

让我们从导入所需的库和一些辅助函数开始。

  1. import torch, logging
  2. ## disable warnings
  3. logging.disable(logging.WARNING)
  4. ## Imaging library
  5. from PIL import Image
  6. from torchvision import transforms as tfms
  7. ## Basic libraries
  8. from fastdownload import FastDownload
  9. import numpy as np
  10. from tqdm.auto import tqdm
  11. import matplotlib.pyplot as plt
  12. %matplotlib inline
  13. from IPython.display import display
  14. import shutil
  15. import os
  16. ## For video display
  17. from IPython.display import HTML
  18. from base64 import b64encode
  19. ## Import the CLIP artifacts
  20. from transformers import CLIPTextModel, CLIPTokenizer
  21. from diffusers import AutoencoderKL, UNet2DConditionModel, DDIMScheduler
  22. ## Helper functions
  23. def load_artifacts():
  24. '''
  25. A function to load all diffusion artifacts
  26. '''
  27. vae = AutoencoderKL.from_pretrained("CompVis/stable-diffusion-v1-4", subfolder="vae", torch_dtype=torch.float16).to("cuda")
  28. unet = UNet2DConditionModel.from_pretrained("CompVis/stable-diffusion-v1-4", subfolder="unet", torch_dtype=torch.float16).to("cuda")
  29. tokenizer = CLIPTokenizer.from_pretrained("openai/clip-vit-large-patch14", torch_dtype=torch.float16)
  30. text_encoder = CLIPTextModel.from_pretrained("openai/clip-vit-large-patch14", torch_dtype=torch.float16).to("cuda")
  31. scheduler = DDIMScheduler(beta_start=0.00085, beta_end=0.012, beta_schedule="scaled_linear", clip_sample=False, set_alpha_to_one=False)
  32. return vae, unet, tokenizer, text_encoder, scheduler
  33. def load_image(p):
  34. '''
  35. Function to load images from a defined path
  36. '''
  37. return Image.open(p).convert('RGB').resize((512,512))
  38. def pil_to_latents(image):
  39. '''
  40. Function to convert image to latents
  41. '''
  42. init_image = tfms.ToTensor()(image).unsqueeze(0) * 2.0 - 1.0
  43. init_image = init_image.to(device="cuda", dtype=torch.float16)
  44. init_latent_dist = vae.encode(init_image).latent_dist.sample() * 0.18215
  45. return init_latent_dist
  46. def latents_to_pil(latents):
  47. '''
  48. Function to convert latents to images
  49. '''
  50. latents = (1 / 0.18215) * latents
  51. with torch.no_grad():
  52. image = vae.decode(latents).sample
  53. image = (image / 2 + 0.5).clamp(0, 1)
  54. image = image.detach().cpu().permute(0, 2, 3, 1).numpy()
  55. images = (image * 255).round().astype("uint8")
  56. pil_images = [Image.fromarray(image) for image in images]
  57. return pil_images
  58. def text_enc(prompts, maxlen=None):
  59. '''
  60. A function to take a texual promt and convert it into embeddings
  61. '''
  62. if maxlen is None: maxlen = tokenizer.model_max_length
  63. inp = tokenizer(prompts, padding="max_length", max_length=maxlen, truncation=True, return_tensors="pt")
  64. return text_encoder(inp.input_ids.to("cuda"))[0].half()
  65. vae, unet, tokenizer, text_encoder, scheduler = load_artifacts()

让我们还选择了一个图像,将在代码实现过程中使用它。

  1. p = FastDownload().download('https://images.pexels.com/photos/1996333/pexels-photo-1996333.jpeg?cs=srgb&dl=pexels-helena-lopes-1996333.jpg&fm=jpg&_gl=1*1pc0nw8*_ga*OTk4MTI0MzE4LjE2NjY1NDQwMjE.*_ga_8JE65Q40S6*MTY2Njc1MjIwMC4yLjEuMTY2Njc1MjIwMS4wLjAuMA..')
  2. init_img = load_image(p)
  3. init_img

DiffEdit的代码实现

下面我们开始按照作者建议的那样实现这篇论文。

1、掩码创建:这是DiffEdit过程的第一步

对于第一步,论文中有更详细的解释,我们这里只看重点提到的部分-

  1. 使用不同的文本条件(参考文本和查询文本)对图像去噪,并从结果中取差异。这个想法的理论是在不同的部分有更多的变化,而不是在图像的背景不会做过多的改变。
  2. 重复这个差分过程10次
  3. 求出这些差异的平均值并将其二值化

这里需要注意的是掩码创建的第三步(平均和二值化)在论文中没有解释清楚,这使得我花了很多实验时间才做对。

下面的prompt_2_img_i2i函数,可以返回图像的潜在空间,而不是重新缩放和解码后的去噪图像。

  1. def prompt_2_img_i2i(prompts, init_img, neg_prompts=None, g=7.5, seed=100, strength =0.8, steps=50, dim=512):
  2. """
  3. Diffusion process to convert prompt to image
  4. """
  5. # Converting textual prompts to embedding
  6. text = text_enc(prompts)
  7. # Adding an unconditional prompt , helps in the generation process
  8. if not neg_prompts: uncond = text_enc([""], text.shape[1])
  9. else: uncond = text_enc(neg_prompt, text.shape[1])
  10. emb = torch.cat([uncond, text])
  11. # Setting the seed
  12. if seed: torch.manual_seed(seed)
  13. # Setting number of steps in scheduler
  14. scheduler.set_timesteps(steps)
  15. # Convert the seed image to latent
  16. init_latents = pil_to_latents(init_img)
  17. # Figuring initial time step based on strength
  18. init_timestep = int(steps * strength)
  19. timesteps = scheduler.timesteps[-init_timestep]
  20. timesteps = torch.tensor([timesteps], device="cuda")
  21. # Adding noise to the latents
  22. noise = torch.randn(init_latents.shape, generator=None, device="cuda", dtype=init_latents.dtype)
  23. init_latents = scheduler.add_noise(init_latents, noise, timesteps)
  24. latents = init_latents
  25. # Computing the timestep to start the diffusion loop
  26. t_start = max(steps - init_timestep, 0)
  27. timesteps = scheduler.timesteps[t_start:].to("cuda")
  28. # Iterating through defined steps
  29. for i,ts in enumerate(tqdm(timesteps)):
  30. # We need to scale the i/p latents to match the variance
  31. inp = scheduler.scale_model_input(torch.cat([latents] * 2), ts)
  32. # Predicting noise residual using U-Net
  33. with torch.no_grad(): u,t = unet(inp, ts, encoder_hidden_states=emb).sample.chunk(2)
  34. # Performing Guidance
  35. pred = u + g*(t-u)
  36. # Conditioning the latents
  37. #latents = scheduler.step(pred, ts, latents).pred_original_sample
  38. latents = scheduler.step(pred, ts, latents).prev_sample
  39. # Returning the latent representation to output an array of 4x64x64
  40. return latents.detach().cpu()

下一步是创建create_mask函数,它的参数是使用的初始图像、引导提示和查询提示,以及我们需要重复这些步骤的次数。论文中作者认为在他们的实验中,n=10和强度为0.5是可行的。因此函数的默认值被调整为该值。Create_mask函数执行以下步骤-

  1. 创建两个去噪的潜在空间,一个条件是参考文本,另一个条件是查询文本,并取这些潜在空间的差值
  2. 重复此步骤n次
  3. 取这些差异的平均值并进行标准化
  4. 选择0.5的阈值进行二值化并创建掩码
  1. def create_mask(init_img, rp, qp, n=10, s=0.5):
  2. ## Initialize a dictionary to save n iterations
  3. diff = {}
  4. ## Repeating the difference process n times
  5. for idx in range(n):
  6. ## Creating denoised sample using reference / original text
  7. orig_noise = prompt_2_img_i2i(prompts=rp, init_img=init_img, strength=s, seed = 100*idx)[0]
  8. ## Creating denoised sample using query / target text
  9. query_noise = prompt_2_img_i2i(prompts=qp, init_img=init_img, strength=s, seed = 100*idx)[0]
  10. ## Taking the difference
  11. diff[idx] = (np.array(orig_noise)-np.array(query_noise))
  12. ## Creating a mask placeholder
  13. mask = np.zeros_like(diff[0])
  14. ## Taking an average of 10 iterations
  15. for idx in range(n):
  16. ## Note np.abs is a key step
  17. mask += np.abs(diff[idx])
  18. ## Averaging multiple channels
  19. mask = mask.mean(0)
  20. ## Normalizing
  21. mask = (mask - mask.mean()) / np.std(mask)
  22. ## Binarizing and returning the mask object
  23. return (mask > 0).astype("uint8")
  24. mask = create_mask(init_img=init_img, rp=["a horse image"], qp=["a zebra image"], n=10)

让我们在图像上可视化生成的掩码。

  1. plt.imshow(np.array(init_img), cmap='gray') # I would add interpolation='none'
  2. plt.imshow(
  3. Image.fromarray(mask).resize((512,512)), ## Scaling the mask to original size
  4. cmap='cividis',
  5. alpha=0.5*(np.array(Image.fromarray(mask*255).resize((512,512))) > 0)
  6. )

正如我们在上面看到的,制作的掩码覆盖了马的部分,这的确是我们想要的结果。

2、掩码扩散:DiffEdit论文的步骤2和步骤3

步骤2和3需要在同一个循环中实现,因为作者是说基于参考文本对非掩码部分和查询文本对掩码部分进行条件处理。使用这个简单的公式将这两个部分结合起来,创建组合的潜在空间

  1. def prompt_2_img_diffedit(rp, qp, init_img, mask, g=7.5, seed=100, strength =0.7, steps=70, dim=512):
  2. """
  3. Diffusion process to convert prompt to image
  4. """
  5. # Converting textual prompts to embedding
  6. rtext = text_enc(rp)
  7. qtext = text_enc(qp)
  8. # Adding an unconditional prompt , helps in the generation process
  9. uncond = text_enc([""], rtext.shape[1])
  10. emb = torch.cat([uncond, rtext, qtext])
  11. # Setting the seed
  12. if seed: torch.manual_seed(seed)
  13. # Setting number of steps in scheduler
  14. scheduler.set_timesteps(steps)
  15. # Convert the seed image to latent
  16. init_latents = pil_to_latents(init_img)
  17. # Figuring initial time step based on strength
  18. init_timestep = int(steps * strength)
  19. timesteps = scheduler.timesteps[-init_timestep]
  20. timesteps = torch.tensor([timesteps], device="cuda")
  21. # Adding noise to the latents
  22. noise = torch.randn(init_latents.shape, generator=None, device="cuda", dtype=init_latents.dtype)
  23. init_latents = scheduler.add_noise(init_latents, noise, timesteps)
  24. latents = init_latents
  25. # Computing the timestep to start the diffusion loop
  26. t_start = max(steps - init_timestep, 0)
  27. timesteps = scheduler.timesteps[t_start:].to("cuda")
  28. # Converting mask to torch tensor
  29. mask = torch.tensor(mask, dtype=unet.dtype).unsqueeze(0).unsqueeze(0).to("cuda")
  30. # Iterating through defined steps
  31. for i,ts in enumerate(tqdm(timesteps)):
  32. # We need to scale the i/p latents to match the variance
  33. inp = scheduler.scale_model_input(torch.cat([latents] * 3), ts)
  34. # Predicting noise residual using U-Net
  35. with torch.no_grad(): u, rt, qt = unet(inp, ts, encoder_hidden_states=emb).sample.chunk(3)
  36. # Performing Guidance
  37. rpred = u + g*(rt-u)
  38. qpred = u + g*(qt-u)
  39. # Conditioning the latents
  40. rlatents = scheduler.step(rpred, ts, latents).prev_sample
  41. qlatents = scheduler.step(qpred, ts, latents).prev_sample
  42. latents = mask*qlatents + (1-mask)*rlatents
  43. # Returning the latent representation to output an array of 4x64x64
  44. return latents_to_pil(latents)

让我们可视化生成的图像

  1. output = prompt_2_img_diffedit(
  2. rp = ["a horse image"],
  3. qp=["a zebra image"],
  4. init_img=init_img,
  5. mask = mask,
  6. g=7.5, seed=100, strength =0.5, steps=70, dim=512)
  7. ## Plotting side by side
  8. fig, axs = plt.subplots(1, 2, figsize=(12, 6))
  9. for c, img in enumerate([init_img, output[0]]):
  10. axs[c].imshow(img)
  11. if c == 0 : axs[c].set_title(f"Initial image ")
  12. else: axs[c].set_title(f"DiffEdit output")

将掩码和扩散过程整合成一个简单的函数。

  1. def diffEdit(init_img, rp , qp, g=7.5, seed=100, strength =0.7, steps=70, dim=512):
  2. ## Step 1: Create mask
  3. mask = create_mask(init_img=init_img, rp=rp, qp=qp)
  4. ## Step 2 and 3: Diffusion process using mask
  5. output = prompt_2_img_diffedit(
  6. rp = rp,
  7. qp=qp,
  8. init_img=init_img,
  9. mask = mask,
  10. g=g,
  11. seed=seed,
  12. strength =strength,
  13. steps=steps,
  14. dim=dim)
  15. return mask , output

我们还可以为DiffEdit创建一个可视化函数,显示原始输入图像、掩码图像和最终输出图像。

  1. def plot_diffEdit(init_img, output, mask):
  2. ## Plotting side by side
  3. fig, axs = plt.subplots(1, 3, figsize=(12, 6))
  4. ## Visualizing initial image
  5. axs[0].imshow(init_img)
  6. axs[0].set_title(f"Initial image")
  7. ## Visualizing initial image
  8. axs[2].imshow(output[0])
  9. axs[2].set_title(f"DiffEdit output")
  10. ## Visualizing the mask
  11. axs[1].imshow(np.array(init_img), cmap='gray')
  12. axs[1].imshow(
  13. Image.fromarray(mask).resize((512,512)), ## Scaling the mask to original size
  14. cmap='cividis',
  15. alpha=0.5*(np.array(Image.fromarray(mask*255).resize((512,512))) > 0)
  16. )
  17. axs[1].set_title(f"DiffEdit mask")

下面可以在一些其他的图像上测试这个函数。

  1. p = FastDownload().download('https://images.pexels.com/photos/1996333/pexels-photo-1996333.jpeg?cs=srgb&dl=pexels-helena-lopes-1996333.jpg&fm=jpg&_gl=1*1pc0nw8*_ga*OTk4MTI0MzE4LjE2NjY1NDQwMjE.*_ga_8JE65Q40S6*MTY2Njc1MjIwMC4yLjEuMTY2Njc1MjIwMS4wLjAuMA..')
  2. init_img = load_image(p)
  3. mask, output = diffEdit(
  4. init_img,
  5. rp = ["a horse image"],
  6. qp=["a zebra image"]
  7. )
  8. plot_diffEdit(init_img, output, mask)

效果还不错太,再试一个。

  1. p = FastDownload().download('https://raw.githubusercontent.com/johnrobinsn/diffusion_experiments/main/images/bowloberries_scaled.jpg')
  2. init_img = load_image(p)
  3. mask, output = diffEdit(
  4. init_img,
  5. rp = ['Bowl of Strawberries'],
  6. qp=['Bowl of Grapes']
  7. )
  8. plot_diffEdit(init_img, output, mask)

FastDiffEdit:一个更快的DiffEdit实现

现在我们已经看到了我们自己手写代码的实现,但是我们这个实现没有经过任何的优化。为了在速度结果方面表现的更好,可以对原来的DiffEdit过程进行一些改进。我们称这些改进为FastDiffEdit。

1、掩码创建:FastDiffEdit掩码过程

掩码创建的最大的问题是它花费太多的时间(在A4500 GPU上大约50秒)。我们可能不需要运行一个完整的扩散循环来去噪图像,只需要在一个观察中使用原始样本的U-net预测,并将重复增加到20次。在这种情况下,可以将计算从10*25 = 250步改进到20步(少了12次循环)。让我们看看这在实践中是否有效。

  1. def prompt_2_img_i2i_fast(prompts, init_img, g=7.5, seed=100, strength =0.5, steps=50, dim=512):
  2. """
  3. Diffusion process to convert prompt to image
  4. """
  5. # Converting textual prompts to embedding
  6. text = text_enc(prompts)
  7. # Adding an unconditional prompt , helps in the generation process
  8. uncond = text_enc([""], text.shape[1])
  9. emb = torch.cat([uncond, text])
  10. # Setting the seed
  11. if seed: torch.manual_seed(seed)
  12. # Setting number of steps in scheduler
  13. scheduler.set_timesteps(steps)
  14. # Convert the seed image to latent
  15. init_latents = pil_to_latents(init_img)
  16. # Figuring initial time step based on strength
  17. init_timestep = int(steps * strength)
  18. timesteps = scheduler.timesteps[-init_timestep]
  19. timesteps = torch.tensor([timesteps], device="cuda")
  20. # Adding noise to the latents
  21. noise = torch.randn(init_latents.shape, generator=None, device="cuda", dtype=init_latents.dtype)
  22. init_latents = scheduler.add_noise(init_latents, noise, timesteps)
  23. latents = init_latents
  24. # We need to scale the i/p latents to match the variance
  25. inp = scheduler.scale_model_input(torch.cat([latents] * 2), timesteps)
  26. # Predicting noise residual using U-Net
  27. with torch.no_grad(): u,t = unet(inp, timesteps, encoder_hidden_states=emb).sample.chunk(2)
  28. # Performing Guidance
  29. pred = u + g*(t-u)
  30. # Zero shot prediction
  31. latents = scheduler.step(pred, timesteps, latents).pred_original_sample
  32. # Returning the latent representation to output an array of 4x64x64
  33. return latents.detach().cpu()

创建一个新的掩码函数,它使用prompt_2_img_i2i_fast函数。

  1. def create_mask_fast(init_img, rp, qp, n=20, s=0.5):
  2. ## Initialize a dictionary to save n iterations
  3. diff = {}
  4. ## Repeating the difference process n times
  5. for idx in range(n):
  6. ## Creating denoised sample using reference / original text
  7. orig_noise = prompt_2_img_i2i_fast(prompts=rp, init_img=init_img, strength=s, seed = 100*idx)[0]
  8. ## Creating denoised sample using query / target text
  9. query_noise = prompt_2_img_i2i_fast(prompts=qp, init_img=init_img, strength=s, seed = 100*idx)[0]
  10. ## Taking the difference
  11. diff[idx] = (np.array(orig_noise)-np.array(query_noise))
  12. ## Creating a mask placeholder
  13. mask = np.zeros_like(diff[0])
  14. ## Taking an average of 10 iterations
  15. for idx in range(n):
  16. ## Note np.abs is a key step
  17. mask += np.abs(diff[idx])
  18. ## Averaging multiple channels
  19. mask = mask.mean(0)
  20. ## Normalizing
  21. mask = (mask - mask.mean()) / np.std(mask)
  22. ## Binarizing and returning the mask object
  23. return (mask > 0).astype("uint8")

看看这个新的函数是否能产生好的蔽效果。

  1. p = FastDownload().download('https://images.pexels.com/photos/1996333/pexels-photo-1996333.jpeg?cs=srgb&dl=pexels-helena-lopes-1996333.jpg&fm=jpg&_gl=1*1pc0nw8*_ga*OTk4MTI0MzE4LjE2NjY1NDQwMjE.*_ga_8JE65Q40S6*MTY2Njc1MjIwMC4yLjEuMTY2Njc1MjIwMS4wLjAuMA..')
  2. init_img = load_image(p)
  3. mask = create_mask_fast(init_img=init_img, rp=["a horse image"], qp=["a zebra image"], n=20)
  4. plt.imshow(np.array(init_img), cmap='gray') # I would add interpolation='none'
  5. plt.imshow(
  6. Image.fromarray(mask).resize((512,512)), ## Scaling the mask to original size
  7. cmap='cividis',
  8. alpha=0.5*(np.array(Image.fromarray(mask*255).resize((512,512))) > 0)
  9. )

效果还是可以的虽然没有完整的函数来的准确,但计算时间在我的机器上从50秒减少到10秒(提高了5倍!),我们可以通过添加cv2的处理来改进效果。这将使掩码更平滑一点。

  1. import cv2
  2. def improve_mask(mask):
  3. mask = cv2.GaussianBlur(mask*255,(3,3),1) > 0
  4. return mask.astype('uint8')
  5. mask = improve_mask(mask)
  6. plt.imshow(np.array(init_img), cmap='gray') # I would add interpolation='none'
  7. plt.imshow(
  8. Image.fromarray(mask).resize((512,512)), ## Scaling the mask to original size
  9. cmap='cividis',
  10. alpha=0.5*(np.array(Image.fromarray(mask*255).resize((512,512))) > 0)
  11. )

掩码变得更加平滑,覆盖了更多的区域。

2、将掩码扩散的流程替换为🤗inpaint的流程

在🤗diffusers库中有一个叫做inpaint pipeline的特殊管道,所以我们可以使用它来执行掩码扩散。它接受查询提示、初始图像和生成的掩码返回生成的图像。

  1. from diffusers import StableDiffusionInpaintPipeline
  2. pipe = StableDiffusionInpaintPipeline.from_pretrained(
  3. "runwayml/stable-diffusion-inpainting",
  4. revision="fp16",
  5. torch_dtype=torch.float16,
  6. ).to("cuda")

让我们使用inpaint来进行改进

  1. pipe(
  2. prompt=["a zebra image"],
  3. image=init_img,
  4. mask_image=Image.fromarray(mask*255).resize((512,512)),
  5. generator=torch.Generator("cuda").manual_seed(100),
  6. num_inference_steps = 20
  7. ).images[0]
  8. image

inpaint管道创建了一个更真实的斑马图像。让我们为掩码和扩散过程创建一个简单的函数。

  1. def fastDiffEdit(init_img, rp , qp, g=7.5, seed=100, strength =0.7, steps=20, dim=512):
  2. ## Step 1: Create mask
  3. mask = create_mask_fast(init_img=init_img, rp=rp, qp=qp, n=20)
  4. ## Improve masking using CV trick
  5. mask = improve_mask(mask)
  6. ## Step 2 and 3: Diffusion process using mask
  7. output = pipe(
  8. prompt=qp,
  9. image=init_img,
  10. mask_image=Image.fromarray(mask*255).resize((512,512)),
  11. generator=torch.Generator("cuda").manual_seed(100),
  12. num_inference_steps = steps
  13. ).images
  14. return mask , output

还是在上面的图像上测试这个函数。

  1. p = FastDownload().download('https://raw.githubusercontent.com/johnrobinsn/diffusion_experiments/main/images/bowloberries_scaled.jpg')
  2. init_img = load_image(p)
  3. mask, output = fastDiffEdit(init_img, rp = ['Bowl of Strawberries'], qp=['Bowl of Grapes'])
  4. plot_diffEdit(init_img, output, mask)

效果比我们自己写的好多了

总结

在这篇文章中,我们实现了DiffEdit论文,然后还提出了创建FastDiffEdit的改进方法,这样不仅计算速度提高了5倍,效果也变得更好了,而且代码还变少了。

作者:Aayush Agrawal 作者网站:aayushmnit.com

“使用HuggingFace实现 DiffEdit论文的掩码引导语义图像编辑”的评论:

还没有评论