{"id":7705,"date":"2022-09-13T15:06:57","date_gmt":"2022-09-13T07:06:57","guid":{"rendered":"http:\/\/139.9.1.231\/?p=7705"},"modified":"2022-11-07T17:19:09","modified_gmt":"2022-11-07T09:19:09","slug":"ddpm","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/09\/13\/ddpm\/","title":{"rendered":"\u6269\u6563\u6a21\u578bDDPM"},"content":{"rendered":"\n<p>\u6458\u81ea\uff1a<a href=\"https:\/\/zhuanlan.zhihu.com\/p\/563661713\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/zhuanlan.zhihu.com\/p\/563661713<\/a><\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>\u201cWhat I cannot create, I do not understand.\u201d &#8212; Richard Feynman<\/p><\/blockquote>\n\n\n\n<p class=\"has-light-pink-background-color has-background\"><a href=\"https:\/\/github.com\/xiaohu2015\/nngen\/tree\/main\/models\/diffusion_models\">https:\/\/github.com\/xiaohu2015\/nngen\/tree\/main\/models\/diffusion_models<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"751\" height=\"203\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/11\/image-60.png\" alt=\"\" class=\"wp-image-10170\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/11\/image-60.png 751w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/11\/image-60-300x81.png 300w\" sizes=\"(max-width: 751px) 100vw, 751px\" \/><\/figure>\n\n\n\n<p class=\"has-text-align-center has-bright-blue-background-color has-background\"><strong>\u8bba\u6587\uff1a<a href=\"https:\/\/arxiv.org\/abs\/2006.11239\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/arxiv.org\/abs\/2006.11239<\/a><\/strong><\/p>\n\n\n\n<p>\u8fd1\u6bb5\u65f6\u95f4\u6700\u706b\u7684\u65b9\u5411\u65e0\u7591\u662f<strong>\u57fa\u4e8e\u6587\u672c\u7528AI\u751f\u6210\u56fe\u50cf<\/strong>\uff0c\u7ee7OpenAI\u57282021\u63d0\u51fa\u7684\u6587\u672c\u8f6c\u56fe\u50cf\u6a21\u578bDALLE\u4e4b\u540e\uff0c\u8d8a\u6765\u8d8a\u591a\u7684\u5927\u516c\u53f8\u5377\u5165\u8fd9\u4e2a\u65b9\u5411\uff0c\u5982\u8c37\u6b4c\u5728\u4eca\u5e74\u76f8\u7ee7\u63a8\u51fa\u4e86<strong>Imagen<\/strong>\u548c<strong>Parti<\/strong>\u3002\u4e00\u4e9b\u4e3b\u6d41\u7684\u6587\u672c\u8f6c\u56fe\u50cf\u6a21\u578b\u5982DALL\u00b7E 2\uff0cstable-diffusion\u548cImagen\u91c7\u7528\u4e86<strong>\u6269\u6563\u6a21\u578b<\/strong>\uff08<strong>Diffusion Model<\/strong>\uff09\u4f5c\u4e3a\u56fe\u50cf\u751f\u6210\u6a21\u578b\uff0c\u8fd9\u4e5f\u5f15\u53d1\u4e86\u5bf9\u6269\u6563\u6a21\u578b\u7684\u7814\u7a76\u70ed\u6f6e\u3002\u76f8\u6bd4GAN\u6765\u8bf4\uff0c\u6269\u6563\u6a21\u578b\u8bad\u7ec3\u66f4\u7a33\u5b9a\uff0c\u800c\u4e14\u80fd\u591f\u751f\u6210\u66f4\u591a\u6837\u7684\u6837\u672c\uff0cOpenAI\u7684\u8bba\u6587Diffusion Models Beat GANs on Image Synthesis\u4e5f\u8bc1\u660e\u4e86\u6269\u6563\u6a21\u578b\u80fd\u591f\u8d85\u8d8aGAN\u3002\u7b80\u5355\u6765\u8bf4\uff0c\u6269\u6563\u6a21\u578b\u5305\u542b\u4e24\u4e2a\u8fc7\u7a0b\uff1a<strong>\u524d\u5411\u6269\u6563\u8fc7\u7a0b<\/strong>\u548c<strong>\u53cd\u5411\u751f\u6210\u8fc7\u7a0b<\/strong>\uff0c\u524d\u5411\u6269\u6563\u8fc7\u7a0b\u662f\u5bf9\u4e00\u5f20\u56fe\u50cf\u9010\u6e10\u6dfb\u52a0\u9ad8\u65af\u566a\u97f3\u76f4\u81f3\u53d8\u6210<strong>\u968f\u673a\u566a\u97f3<\/strong>\uff0c\u800c\u53cd\u5411\u751f\u6210\u8fc7\u7a0b\u662f<strong>\u53bb\u566a\u97f3\u8fc7\u7a0b<\/strong>\uff0c\u6211\u4eec\u5c06\u4ece\u4e00\u4e2a\u968f\u673a\u566a\u97f3\u5f00\u59cb\u9010\u6e10\u53bb\u566a\u97f3\u76f4\u81f3\u751f\u6210\u4e00\u5f20\u56fe\u50cf\uff0c\u8fd9\u4e5f\u662f\u6211\u4eec\u8981\u6c42\u89e3\u6216\u8005\u8bad\u7ec3\u7684\u90e8\u5206\u3002\u6269\u6563\u6a21\u578b\u4e0e\u5176\u5b83\u4e3b\u6d41\u751f\u6210\u6a21\u578b\u7684\u5bf9\u6bd4\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-121-1024x706.png\" alt=\"\" class=\"wp-image-7708\" width=\"427\" height=\"294\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-121-1024x706.png 1024w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-121-300x207.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-121-768x529.png 768w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-121.png 1106w\" sizes=\"(max-width: 427px) 100vw, 427px\" \/><\/figure><\/div>\n\n\n\n<p>\u76ee\u524d\u6240\u91c7\u7528\u7684\u6269\u6563\u6a21\u578b\u5927\u90fd\u662f\u6765\u81ea\u4e8e2020\u5e74\u7684\u5de5\u4f5c<strong>DDPM: Denoising Diffusion Probabilistic Models\uff0c<\/strong>DDPM\u5bf9\u4e4b\u524d\u7684\u6269\u6563\u6a21\u578b\uff08\u5177\u4f53\u89c1Deep Unsupervised Learning using Nonequilibrium Thermodynamics\uff09\u8fdb\u884c\u4e86\u7b80\u5316\uff0c\u5e76\u901a\u8fc7<strong>\u53d8\u5206\u63a8\u65ad<\/strong>\uff08variational inference\uff09\u6765\u8fdb\u884c\u5efa\u6a21\uff0c\u8fd9\u4e3b\u8981\u662f\u56e0\u4e3a\u6269\u6563\u6a21\u578b\u4e5f\u662f\u4e00\u4e2a<strong>\u9690\u53d8\u91cf\u6a21\u578b<\/strong>\uff08latent variable model\uff09\uff0c\u76f8\u6bd4VAE\u8fd9\u6837\u7684\u9690\u53d8\u91cf\u6a21\u578b\uff0c\u6269\u6563\u6a21\u578b\u7684\u9690\u53d8\u91cf\u662f\u548c\u539f\u59cb\u6570\u636e\u662f\u540c\u7ef4\u5ea6\u7684\uff0c\u800c\u4e14\u63a8\u7406\u8fc7\u7a0b\uff08\u5373\u6269\u6563\u8fc7\u7a0b\uff09\u5f80\u5f80\u662f\u56fa\u5b9a\u7684\u3002\u8fd9\u7bc7\u6587\u7ae0\u5c06\u57fa\u4e8eDDPM\u8be6\u7ec6\u4ecb\u7ecd\u6269\u6563\u6a21\u578b\u7684\u539f\u7406\uff0c\u5e76\u7ed9\u51fa\u5177\u4f53\u7684\u4ee3\u7801\u5b9e\u73b0\u548c\u5206\u6790\u3002<\/p>\n\n\n\n<h3>\u6269\u6563\u6a21\u578b\u539f\u7406<\/h3>\n\n\n\n<p>\u6269\u6563\u6a21\u578b\u5305\u62ec\u4e24\u4e2a\u8fc7\u7a0b\uff1a<strong>\u524d\u5411\u8fc7\u7a0b\uff08forward process\uff09<\/strong>\u548c<strong>\u53cd\u5411\u8fc7\u7a0b\uff08reverse process\uff09<\/strong>\uff0c\u5176\u4e2d\u524d\u5411\u8fc7\u7a0b\u53c8\u79f0\u4e3a\u4e3a<strong>\u6269\u6563\u8fc7\u7a0b\uff08diffusion process\uff09<\/strong>\uff0c\u5982\u4e0b\u56fe\u6240\u793a\u3002\u65e0\u8bba\u662f\u524d\u5411\u8fc7\u7a0b\u8fd8\u662f\u53cd\u5411\u8fc7\u7a0b\u90fd\u662f\u4e00\u4e2a<strong>\u53c2\u6570\u5316\u7684\u9a6c\u5c14\u53ef\u592b\u94fe\uff08Markov chain\uff09<\/strong>\uff0c\u5176\u4e2d\u53cd\u5411\u8fc7\u7a0b\u53ef\u4ee5\u7528\u6765\u751f\u6210\u6570\u636e\uff0c\u8fd9\u91cc\u6211\u4eec\u5c06\u901a\u8fc7\u53d8\u5206\u63a8\u65ad\u6765\u8fdb\u884c\u5efa\u6a21\u548c\u6c42\u89e3\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"1001\" height=\"230\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-122.png\" alt=\"\" class=\"wp-image-7711\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-122.png 1001w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-122-300x69.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-122-768x176.png 768w\" sizes=\"(max-width: 1001px) 100vw, 1001px\" \/><\/figure>\n\n\n\n<h4>\u6269\u6563\u8fc7\u7a0b<\/h4>\n\n\n\n<p>\u6269\u6563\u8fc7\u7a0b\u662f\u6307\u7684\u5bf9\u6570\u636e\u9010\u6e10\u589e\u52a0\u9ad8\u65af\u566a\u97f3\u76f4\u81f3\u6570\u636e\u53d8\u6210\u968f\u673a\u566a\u97f3\u7684\u8fc7\u7a0b\u3002\u5bf9\u4e8e\u539f\u59cb\u6570\u636e<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-123.png\" alt=\"\" class=\"wp-image-7712\" width=\"90\" height=\"20\"\/><\/figure><\/div>\n\n\n\n<p>\uff0c\u603b\u5171\u5305\u542bT\u6b65\u7684\u6269\u6563\u8fc7\u7a0b\u7684\u6bcf\u4e00\u6b65\u90fd\u662f\u5bf9\u4e0a\u4e00\u6b65\u5f97\u5230\u7684\u6570\u636ext-1\u6309\u5982\u4e0b\u65b9\u5f0f\u589e\u52a0\u9ad8\u65af\u566a\u97f3\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-124.png\" alt=\"\" class=\"wp-image-7714\" width=\"512\" height=\"61\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-124.png 782w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-124-300x36.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-124-768x93.png 768w\" sizes=\"(max-width: 512px) 100vw, 512px\" \/><\/figure><\/div>\n\n\n\n<p>\u8fd9\u91cc{\u03b2t}t=1~T\u4e3a\u6bcf\u4e00\u6b65\u6240\u91c7\u7528\u7684<strong>\u65b9\u5dee<\/strong>\uff0c\u5b83\u4ecb\u4e8e0\uff5e1\u4e4b\u95f4\u3002\u5bf9\u4e8e\u6269\u6563\u6a21\u578b\uff0c\u6211\u4eec\u5f80\u5f80\u79f0\u4e0d\u540cstep\u7684\u65b9\u5dee\u8bbe\u5b9a\u4e3a<strong>variance schedule<\/strong>\u6216\u8005<strong>noise schedule<\/strong>\uff0c\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u8d8a\u540e\u9762\u7684step\u4f1a\u91c7\u7528\u66f4\u5927\u7684\u65b9\u5dee\uff0c\u5373\u6ee1\u8db3\u03b21&lt;\u03b22&lt;\u22ef&lt;\u03b2T\u3002\u5728\u4e00\u4e2a\u8bbe\u8ba1\u597d\u7684<strong>variance schedule<\/strong>\u4e0b\uff0c\u7684\u5982\u679c\u6269\u6563\u6b65\u6570T\u8db3\u591f\u5927\uff0c\u90a3\u4e48\u6700\u7ec8\u5f97\u5230\u7684xT\u5c31\u5b8c\u5168\u4e22\u5931\u4e86\u539f\u59cb\u6570\u636e\u800c\u53d8\u6210\u4e86\u4e00\u4e2a\u968f\u673a\u566a\u97f3\u3002 \u6269\u6563\u8fc7\u7a0b\u7684\u6bcf\u4e00\u6b65\u90fd\u751f\u6210\u4e00\u4e2a\u5e26\u566a\u97f3\u7684\u6570\u636ext\uff0c\u6574\u4e2a\u6269\u6563\u8fc7\u7a0b\u4e5f\u5c31\u662f\u4e00\u4e2a<strong>\u9a6c\u5c14\u5361\u592b\u94fe<\/strong>\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"857\" height=\"356\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-129.png\" alt=\"\" class=\"wp-image-7726\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-129.png 857w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-129-300x125.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-129-768x319.png 768w\" sizes=\"(max-width: 857px) 100vw, 857px\" \/><\/figure>\n\n\n\n<p>\u53e6\u5916\u8981\u6307\u51fa\u7684\u662f, \u6269\u6563\u8fc7\u7a0b\u5f80\u5f80\u662f\u56fa\u5b9a\u7684, \u5373\u91c7\u7528\u4e00\u4e2a\u9884\u5148\u5b9a\u4e49\u597d\u7684variance schedule, \u6bd4 \u5982DDPM\u5c31\u91c7\u7528\u4e00\u4e2a\u7ebf\u6027\u7684variance schedule\u3002\u6269\u6563\u8fc7\u7a0b\u7684\u4e00\u4e2a\u91cd\u8981\u7279\u6027\u662f\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u57fa \u4e8e\u539f\u59cb\u6570\u636e \\(\\mathbf{x}0\\) \u6765\u5bf9\u4efb\u610f \\(t\\)\u6b65\u7684 \\(\\mathbf{x}_t\\) \u8fdb\u884c\u91c7\u6837: \\(\\mathbf{x}_t \\sim q\\left(\\mathbf{x}_t \\mid \\mathbf{x}_0\\right)\\) \u3002\u8fd9\u91cc\u5b9a\u4e49  \\(\\alpha_t=1-\\beta_t\\) \u548c \\(\\bar{\\alpha}_t=\\prod{i=1}^t \\alpha_i\\) \uff0c \u901a\u8fc7\u91cd\u53c2\u6570\u6280\u5de7\uff08\u548cVAE\u7c7b\u4f3c\uff09, \u90a3\u4e48\u6709:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"278\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-130-1024x278.png\" alt=\"\" class=\"wp-image-7740\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-130-1024x278.png 1024w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-130-300x82.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-130-768x209.png 768w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-130.png 1060w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u4e0a\u8ff0\u63a8\u5230\u8fc7\u7a0b\u5229\u7528\u4e86\u4e24\u4e2a\u65b9\u5dee\u4e0d\u540c\u7684\u9ad8\u65af\u5206\u5e03\\(\\mathcal{N}\\left(\\mathbf{0}, \\sigma_1^2 \\mathbf{I}\\right)\\) \u548c  \\(\\mathcal{N}\\left(\\mathbf{0}, \\sigma_2^2 \\mathbf{I}\\right)\\) \u76f8\u52a0\u7b49\u4e8e\u4e00\u4e2a\u65b0\u7684\u9ad8\u65af\u5206 \u5e03 \\(\\mathcal{N}\\left(\\mathbf{0},\\left(\\sigma_1^2+\\sigma_2^2\\right) \\mathbf{I}\\right)\\) \u3002\u53cd\u91cd\u53c2\u6570\u5316\u540e, \u6211\u4eec\u5f97\u5230:<br>\\[<br>q\\left(\\mathbf{x}_t \\mid \\mathbf{x}_0\\right)=\\mathcal{N}\\left(\\mathbf{x}_t ; \\sqrt{\\bar{\\alpha}_t} \\mathbf{x}_0,\\left(1-\\bar{\\alpha}_t\\right) \\mathbf{I}\\right)<br>\\]<br>\u6269\u6563\u8fc7\u7a0b\u7684\u8fd9\u4e2a\u7279\u6027\u5f88\u91cd\u8981\u3002\u9996\u5148, \u6211\u4eec\u53ef\u4ee5\u770b\u5230  \\(\\mathbf{x}_t\\) \u5176\u5b9e\u53ef\u4ee5\u770b\u6210\u662f\u539f\u59cb\u6570\u636e  \\(\\mathbf{x}_0\\) \u548c\u968f\u673a\u566a\u97f3 \\(\\epsilon\\) \u7684\u7ebf\u6027\u7ec4\u5408, \u5176\u4e2d\\(\\sqrt{\\bar{\\alpha}_t}\\) \u548c  \\(\\sqrt{1-\\bar{\\alpha}_t}\\) \u4e3a\u7ec4\u5408\u7cfb\u6570, \u5b83\u4eec\u7684\u5e73\u65b9\u548c\u7b49\u4e8e 1 , \u6211\u4eec\u4e5f\u53ef\u4ee5\u79f0\u4e24\u8005\u5206\u522b \u4e3a signal_rate \u548c noise_rate (\u89c1https:\/\/keras.io\/examples\/generative\/ddim\/#diffusionschedule\u548cVariational Diffusion Models\uff09\u3002\u66f4\u8fd1\u4e00\u6b65\u5730\uff0c\u6211\u4eec\u53ef\u4ee5\u57fa\u4e8e \\(\\bar{\\alpha}_t\\) \u800c\u4e0d\u662f \\(\\beta_t\\) \u6765\u5b9a\u4e49 noise schedule (\u89c1Improved Denoising Diffusion Probabilistic Models\u6240\u8bbe\u8ba1\u7684cosine schedule\uff09, \u56e0\u4e3a\u8fd9\u6837\u5904\u7406\u66f4\u76f4\u63a5, \u6bd4\u5982\u6211\u4eec\u76f4\u63a5\u5c06 \\(\\bar{\\alpha}_T\\) \u8bbe\u5b9a\u4e3a\u4e00\u4e2a\u63a5\u8fd10\u7684\u503c, \u90a3\u4e48\u5c31\u53ef\u4ee5\u4fdd \u8bc1\u6700\u7ec8\u5f97\u5230\u7684 \\(\\mathbf{x}_T\\) \u8fd1\u4f3c\u4e3a\u4e00\u4e2a\u968f\u673a\u566a\u97f3\u3002\u5176\u6b21, \u540e\u9762\u7684\u5efa\u6a21\u548c\u5206\u6790\u8fc7\u7a0b\u5c06\u4f7f\u7528\u8fd9\u4e2a\u7279\u6027\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"854\" height=\"365\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-131.png\" alt=\"\" class=\"wp-image-7753\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-131.png 854w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-131-300x128.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-131-768x328.png 768w\" sizes=\"(max-width: 854px) 100vw, 854px\" \/><\/figure>\n\n\n\n<h4>\u53cd\u5411\u8fc7\u7a0b<\/h4>\n\n\n\n<p>   \u6269\u6563\u8fc7\u7a0b\u662f\u5c06\u6570\u636e\u566a\u97f3\u5316\uff0c\u90a3\u4e48\u53cd\u5411\u8fc7\u7a0b\u5c31\u662f<strong>\u4e00\u4e2a\u53bb\u566a\u7684\u8fc7\u7a0b<\/strong>\uff0c\u5982\u679c\u6211\u4eec\u77e5\u9053\u53cd\u5411\u8fc7\u7a0b\u7684\u6bcf\u4e00\u6b65\u7684\u771f\u5b9e\u5206\u5e03q(xt\u22121|xt)\uff0c\u90a3\u4e48\u4ece\u4e00\u4e2a\u968f\u673a\u566a\u97f3xT\u223cN(0,I)\u5f00\u59cb\uff0c\u9010\u6e10\u53bb\u566a\u5c31\u80fd\u751f\u6210\u4e00\u4e2a\u771f\u5b9e\u7684\u6837\u672c\uff0c\u6240\u4ee5\u53cd\u5411\u8fc7\u7a0b\u4e5f\u5c31\u662f<strong>\u751f\u6210\u6570\u636e\u7684\u8fc7\u7a0b<\/strong>\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"818\" height=\"168\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-132.png\" alt=\"\" class=\"wp-image-7758\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-132.png 818w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-132-300x62.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-132-768x158.png 768w\" sizes=\"(max-width: 818px) 100vw, 818px\" \/><\/figure>\n\n\n\n<p>\u4f30\u8ba1\u5206\u5e03 \\(q\\left(\\mathbf{x}{t-1} \\mid \\mathbf{x}_t\\right)\\) \u9700\u8981\u7528\u5230\u6574\u4e2a\u8bad\u7ec3\u6837\u672c, \u6211\u4eec\u53ef\u4ee5\u7528\u795e\u7ecf\u7f51\u7edc\u6765\u4f30\u8ba1\u8fd9\u4e9b\u5206\u5e03\u3002\u8fd9\u91cc, \u6211\u4eec\u5c06\u53cd\u5411\u8fc7\u7a0b\u4e5f\u5b9a\u4e49\u4e3a\u4e00\u4e2a\u9a6c\u5c14\u5361\u592b\u94fe, \u53ea\u4e0d\u8fc7\u5b83\u662f\u7531\u4e00\u7cfb\u5217\u7528\u795e\u7ecf\u7f51\u7edc\u53c2\u6570\u5316\u7684\u9ad8\u65af\u5206\u5e03\u6765\u7ec4\u6210: <\/p>\n\n\n\n<p>\\[p\\theta\\left(\\mathbf{x}{0: T}\\right)=p\\left(\\mathbf{x}_T\\right) \\prod{t=1}^T p_\\theta\\left(\\mathbf{x}{t-1} \\mid \\mathbf{x}_t\\right) \\quad p\\theta\\left(\\mathbf{x}{t-1} \\mid \\mathbf{x}_t\\right)=\\mathcal{N}\\left(\\mathbf{x}{t-1} ; \\boldsymbol{\\mu}\\theta\\left(\\mathbf{x}_t, t\\right), \\mathbf{\\Sigma}\\theta\\left(\\mathbf{x}t, t\\right)\\right)\\]<\/p>\n\n\n\n<p> \u8fd9\u91cc \\(p\\left(\\mathbf{x}_T\\right)=\\mathcal{N}\\left(\\mathbf{x}_T ; \\mathbf{0}, \\mathbf{I}\\right)\\), \u800c \\(p\\theta\\left(\\mathbf{x}{t-1} \\mid \\mathbf{x}_t\\right)\\) \u4e3a\u53c2\u6570\u5316\u7684\u9ad8\u65af\u5206\u5e03, \u5b83\u4eec\u7684\u5747\u503c\u548c\u65b9\u5dee\u7531\u8bad\u7ec3\u7684\u7f51\u7edc \\(\\boldsymbol{\\mu}\\theta\\left(\\mathbf{x}t, t\\right)\\) \u548c \\(\\boldsymbol{\\Sigma}\\theta\\left(\\mathbf{x}t, t\\right)\\) \u7ed9\u51fa\u3002<strong>\u5b9e\u9645\u4e0a, \u6269\u6563\u6a21\u578b\u5c31\u662f\u8981\u5f97\u5230\u8fd9\u4e9b\u8bad\u7ec3\u597d\u7684\u7f51\u7edc, \u56e0\u4e3a\u5b83\u4eec\u6784 \u6210\u4e86\u6700\u7ec8\u7684\u751f\u6210\u6a21\u578b\u3002<\/strong>\u867d\u7136\u5206\u5e03 \\(q\\left(\\mathbf{x}{t-1} \\mid \\mathbf{x}t\\right)\\) \u662f\u4e0d\u53ef\u76f4\u63a5\u5904\u7406\u7684, \u4f46\u662f\u52a0\u4e0a\u6761\u4ef6\\(\\mathbf{x}_0\\) \u7684\u540e\u9a8c\u5206\u5e03 \\(q\\left(\\mathbf{x}{t-1} \\mid \\mathbf{x}t, \\mathbf{x}_0\\right)\\) \u5374\u662f\u53ef\u5904\u7406\u7684, \u8fd9\u91cc\u6709: <\/p>\n\n\n\n<p>\\[q\\left(\\mathbf{x}{t-1} \\mid \\mathbf{x}t, \\mathbf{x}_0\\right)=\\mathcal{N}\\left(\\mathbf{x}{t-1} ; \\tilde{\\boldsymbol{\\mu}}\\left(\\mathbf{x}_t, \\mathbf{x}_0\\right), \\tilde{\\beta}_t \\mathbf{I}\\right)<br>\\]<\/p>\n\n\n\n<p>\u4e0b\u9762\u6211\u4eec\u6765\u5177\u4f53\u63a8\u5bfc\u8fd9\u4e2a\u5206\u5e03\uff0c\u9996\u5148\u6839\u636e\u8d1d\u53f6\u65af\u516c\u5f0f\uff0c\u6211\u4eec\u6709\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" width=\"468\" height=\"62\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-133.png\" alt=\"\" class=\"wp-image-7767\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-133.png 468w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-133-300x40.png 300w\" sizes=\"(max-width: 468px) 100vw, 468px\" \/><\/figure><\/div>\n\n\n\n<p>\u7531\u4e8e\u6269\u6563\u8fc7\u7a0b\u7684\u9a6c\u5c14\u5361\u592b\u94fe\u7279\u6027\uff0c\u6211\u4eec\u77e5\u9053\u5206\u5e03<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"824\" height=\"36\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-134.png\" alt=\"\" class=\"wp-image-7768\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-134.png 824w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-134-300x13.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-134-768x34.png 768w\" sizes=\"(max-width: 824px) 100vw, 824px\" \/><\/figure>\n\n\n\n<p>\uff0c\u800c\u7531\u524d\u9762\u5f97\u5230\u7684\u6269\u6563\u8fc7\u7a0b\u7279\u6027\u53ef\u77e5\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-135.png\" alt=\"\" class=\"wp-image-7769\" width=\"522\" height=\"81\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-135.png 623w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-135-300x47.png 300w\" sizes=\"(max-width: 522px) 100vw, 522px\" \/><\/figure><\/div>\n\n\n\n<p>\u6240\u4ee5\uff0c\u6211\u4eec\u6709\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"883\" height=\"281\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-136.png\" alt=\"\" class=\"wp-image-7770\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-136.png 883w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-136-300x95.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-136-768x244.png 768w\" sizes=\"(max-width: 883px) 100vw, 883px\" \/><\/figure>\n\n\n\n<p>\u8fd9\u91cc\u7684 \\(C\\left(\\mathbf{x}t, \\mathbf{x}_0\\right)\\) \u662f\u4e00\u4e2a\u548c \\(\\mathbf{x}{t-1}\\) \u65e0\u5173\u7684\u90e8\u5206\uff0c\u6240\u4ee5\u7701\u7565\u3002\u6839\u636e\u9ad8\u65af\u5206\u5e03\u7684\u6982\u7387\u5bc6\u5ea6\u51fd\u6570\u5b9a\u4e49\u548c\u4e0a \u8ff0\u7ed3\u679c (\u914d\u5e73\u65b9)\uff0c\u6211\u4eec\u53ef\u4ee5\u5f97\u5230\u540e\u9a8c\u5206\u5e03 \\(q\\left(\\mathbf{x}t \\mid \\mathbf{x}{t-1}, \\mathbf{x}0\\right)\\) \u7684\u5747\u503c\u548c\u65b9\u5dee: <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"802\" height=\"282\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-137.png\" alt=\"\" class=\"wp-image-7774\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-137.png 802w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-137-300x105.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-137-768x270.png 768w\" sizes=\"(max-width: 802px) 100vw, 802px\" \/><\/figure>\n\n\n\n<p><br>\u53ef\u4ee5\u770b\u5230\u65b9\u5dee\u662f\u4e00\u4e2a\u5b9a\u91cf (\u6269\u6563\u8fc7\u7a0b\u53c2\u6570\u56fa\u5b9a)\uff0c\u800c\u5747\u503c\u662f\u4e00\u4e2a\u4f9d\u8d56 \\(\\mathbf{x}_0\\) \u548c \\(\\mathbf{x}_t\\) \u7684\u51fd\u6570\u3002\u8fd9\u4e2a\u5206\u5e03\u5c06 \u4f1a\u88ab\u7528\u4e8e\u63a8\u5bfc\u6269\u6563\u6a21\u578b\u7684\u4f18\u5316\u76ee\u6807\u3002<\/p>\n\n\n\n<h3 id=\"h_563661713_3\"><strong>\u4f18\u5316\u76ee\u6807<\/strong><\/h3>\n\n\n\n<p>    \u4e0a\u9762\u4ecb\u7ecd\u4e86\u6269\u6563\u6a21\u578b\u7684\u6269\u6563\u8fc7\u7a0b\u548c\u53cd\u5411\u8fc7\u7a0b\uff0c\u73b0\u5728\u6211\u4eec\u6765\u4ece\u53e6\u5916\u4e00\u4e2a\u89d2\u5ea6\u6765\u770b\u6269\u6563\u6a21\u578b\uff1a\u5982\u679c\u6211\u4eec\u628a\u4e2d\u95f4\u4ea7\u751f\u7684\u53d8\u91cf\u770b\u6210\u9690\u53d8\u91cf\u7684\u8bdd\uff0c\u90a3\u4e48\u6269\u6563\u6a21\u578b\u5176\u5b9e\u662f\u5305\u542bT\u4e2a\u9690\u53d8\u91cf\u7684<strong>\u9690\u53d8\u91cf\u6a21\u578b\uff08latent variable model\uff09<\/strong>\uff0c\u5b83\u53ef\u4ee5\u770b\u6210\u662f\u4e00\u4e2a\u7279\u6b8a\u7684<strong>Hierarchical VAEs<\/strong>\uff08\u89c1<a rel=\"noreferrer noopener\" href=\"https:\/\/arxiv.org\/abs\/2208.11970\" target=\"_blank\">Understanding Diffusion Models: A Unified Perspective<\/a>\uff09\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"802\" height=\"432\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-138.png\" alt=\"\" class=\"wp-image-7778\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-138.png 802w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-138-300x162.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-138-768x414.png 768w\" sizes=\"(max-width: 802px) 100vw, 802px\" \/><\/figure>\n\n\n\n<p>\u76f8\u6bd4VAE\u6765\u8bf4\uff0c\u6269\u6563\u6a21\u578b\u7684\u9690\u53d8\u91cf\u662f\u548c\u539f\u59cb\u6570\u636e\u540c\u7ef4\u5ea6\u7684\uff0c\u800c\u4e14encoder\uff08\u5373\u6269\u6563\u8fc7\u7a0b\uff09\u662f\u56fa\u5b9a\u7684\u3002\u65e2\u7136\u6269\u6563\u6a21\u578b\u662f\u9690\u53d8\u91cf\u6a21\u578b\uff0c\u90a3\u4e48\u6211\u4eec\u53ef\u4ee5\u5c31\u53ef\u4ee5\u57fa\u4e8e<strong>\u53d8\u5206\u63a8\u65ad<\/strong>\u6765\u5f97\u5230<strong>variational lower bound<\/strong>\uff08<strong>VLB<\/strong>\uff0c\u53c8\u79f0<strong>ELBO<\/strong>\uff09\u4f5c\u4e3a\u6700\u5927\u5316\u4f18\u5316\u76ee\u6807\uff0c\u8fd9\u91cc\u6709\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" width=\"522\" height=\"222\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-139.png\" alt=\"\" class=\"wp-image-7780\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-139.png 522w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-139-300x128.png 300w\" sizes=\"(max-width: 522px) 100vw, 522px\" \/><\/figure><\/div>\n\n\n\n<p>\u8fd9\u91cc\u6700\u540e\u4e00\u6b65\u662f\u5229\u7528\u4e86<strong>Jensen&#8217;s inequality<\/strong>\uff08\u4e0d\u91c7\u7528\u8fd9\u4e2a\u4e0d\u7b49\u5f0f\u7684\u63a8\u5bfc\u89c1\u535a\u5ba2What are Diffusion Models?\uff09\uff0c\u5bf9\u4e8e\u7f51\u7edc\u8bad\u7ec3\u6765\u8bf4\uff0c\u5176\u8bad\u7ec3\u76ee\u6807\u4e3a<strong>VLB\u53d6\u8d1f<\/strong>\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"812\" height=\"85\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-140.png\" alt=\"\" class=\"wp-image-7781\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-140.png 812w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-140-300x31.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-140-768x80.png 768w\" sizes=\"(max-width: 812px) 100vw, 812px\" \/><\/figure>\n\n\n\n<p>\u6211\u4eec\u8fd1\u4e00\u6b65\u5bf9\u8bad\u7ec3\u76ee\u6807\u8fdb\u884c\u5206\u89e3\u53ef\u5f97\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-141.png\" alt=\"\" class=\"wp-image-7783\" width=\"710\" height=\"673\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-141.png 812w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-141-300x284.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-141-768x728.png 768w\" sizes=\"(max-width: 710px) 100vw, 710px\" \/><\/figure>\n\n\n\n<p>\u53ef\u4ee5\u770b\u5230\u6700\u7ec8\u7684\u4f18\u5316\u76ee\u6807\u5171\u5305\u542b \\(T+1\\) \u9879\uff0c\u5176\u4e2d \\(L_0\\) \u53ef\u4ee5\u770b\u6210\u662f\u539f\u59cb\u6570\u636e\u91cd\u5efa\uff0c\u4f18\u5316\u7684\u662f\u8d1f\u5bf9\u6570\u4f3c\u7136\uff0c \\(L_0\\) \u53ef\u4ee5\u7528\u4f30\u8ba1\u7684 \\(\\mathcal{N}\\left(\\mathbf{x}0 ; \\boldsymbol{\\mu}\\theta\\left(\\mathbf{x}1, 1\\right), \\mathbf{\\Sigma}\\theta\\left(\\mathbf{x}1, 1\\right)\\right)\\) \u6765\u6784\u5efa\u4e00\u4e2a\u79bb\u6563\u5316\u7684decoder\u6765\u8ba1\u7b97\uff08\u89c1 DDPM\u8bba\u65873.3\u90e8\u5206\uff09\uff1b\u800c \\(L_T\\) \u8ba1\u7b97\u7684\u662f\u6700\u540e\u5f97\u5230\u7684\u566a\u97f3\u7684\u5206\u5e03\u548c\u5148\u9a8c\u5206\u5e03\u7684KL\u6563\u5ea6\uff0c\u8fd9\u4e2aKL\u6563\u5ea6\u6ca1\u6709\u8bad\u7ec3\u53c2\u6570\uff0c\u8fd1\u4f3c\u4e3a 0 \uff0c\u56e0\u4e3a\u5148\u9a8c \\(p\\left(\\mathbf{x}_T\\right)=\\mathcal{N}(\\mathbf{0}, \\mathbf{I})\\) \u800c\u6269\u6563\u8fc7\u7a0b\u6700\u540e\u5f97\u5230\u7684\u968f\u673a\u566a\u97f3 \\(q\\left(\\mathbf{x}_T \\mid \\mathbf{x}_0\\right)\\) \u4e5f\u8fd1\u4f3c\u4e3a \\(\\mathcal{N}(\\mathbf{0}, \\mathbf{I})\\) \uff1b\u800c \\(L{t-1}\\) \u5219\u662f\u8ba1\u7b97\u7684\u662f\u4f30\u8ba1\u5206\u5e03 \\(p_\\theta\\left(\\mathbf{x}{t-1} \\mid \\mathbf{x}_t\\right)\\) \u548c\u771f\u5b9e\u540e\u9a8c\u5206\u5e03 \\(q\\left(\\mathbf{x}{t-1} \\mid \\mathbf{x}_t, \\mathbf{x}_0\\right)\\) \u7684KL\u6563\u5ea6\uff0c\u8fd9\u91cc\u5e0c\u671b\u41dd\u4eec\u4f30\u8ba1\u7684\u53bb\u566a\u8fc7\u7a0b\u548c\u4f9d\u8d56\u771f\u5b9e\u6570\u636e\u7684\u53bb\u566a\u8fc7\u7a0b\u8fd1\u4f3c\u4e00\u81f4\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"857\" height=\"388\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-142.png\" alt=\"\" class=\"wp-image-7785\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-142.png 857w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-142-300x136.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-142-768x348.png 768w\" sizes=\"(max-width: 857px) 100vw, 857px\" \/><\/figure>\n\n\n\n<p>\u4e4b\u6240\u4ee5\u524d\u9762\u6211\u4eec\u5c06 \\(p_\\theta\\left(\\mathbf{x}{t-1} \\mid \\mathbf{x}_t\\right)\\) \u5b9a\u4e49\u4e3a\u4e00\u4e2a\u7528\u7f51\u7edc\u53c2\u6570\u5316\u7684\u9ad8\u65af\u5206\u5e03 \\(\\mathcal{N}\\left(\\mathbf{x}{t-1} ; \\boldsymbol{\\mu}\\theta\\left(\\mathbf{x}_t, t\\right), \\mathbf{\\Sigma}\\theta\\left(\\mathbf{x}t, t\\right)\\right)\\), \u662f\u56e0\u4e3a\u8981\u5339\u914d\u7684\u540e\u9a8c\u5206\u5e03 \\(q\\left(\\mathbf{x}{t-1} \\mid \\mathbf{x}t, \\mathbf{x}_0\\right)\\)\u4e5f\u662f\u4e00\u4e2a\u9ad8\u65af\u5206\u5e03\u3002\u5bf9 \u4e8e\u8bad\u7ec3\u76ee\u6807 \\(L_0\\) \u548c \\(L{t-1}\\) \u6765\u8bf4, \u90fd\u662f\u5e0c\u671b\u5f97\u5230\u8bad\u7ec3\u597d\u7684\u7f51\u7edc \\(\\boldsymbol{\\mu}\\theta\\left(\\mathbf{x}_t, t\\right)\\) \u548c \\(\\boldsymbol{\\Sigma}\\theta\\left(\\mathbf{x}t, t\\right)\\) (\u5bf9\u4e8e \\(L_0, t=1\\) \uff09\u3002DDPM\u5bf9 \\(p\\theta\\left(\\mathbf{x}{t-1} \\mid \\mathbf{x}_t\\right)\\) \u505a\u4e86\u8fd1\u4e00\u6b65\u7b80\u5316, \u91c7\u7528\u5468\u5b9a\u7684\u65b9\u5dee: \\(\\boldsymbol{\\Sigma}\\theta\\left(\\mathbf{x}t, t\\right)=\\sigma_t^2 \\mathbf{I}\\), \u8fd9\u91cc\u7684 \\(\\sigma_t^2\\) \u53ef\u4ee5 \u8bbe\u5b9a\u4e3a \\(\\beta_t\\) \u6216\u8005 \\(\\tilde{\\beta}_t\\) \uff08\u8fd9\u5176\u5b9e\u662f\u4e24\u4e2a\u6781\u7aef, \u5206\u522b\u662f\u4e0a\u9650\u548c\u4e0b\u9650, \u4e5f\u53ef\u4ee5\u91c7\u7528\u53ef\u8bad\u7ec3\u7684\u65b9\u5dee, \u89c1\u8bba\u6587 Improved Denoising Diffusion Probabilistic Models \u548cAnalytic-DPM: an Analytic Estimate of the Optimal Reverse Variance in Diffusion Probabilistic Models\uff09\u3002\u8fd9\u91cc\u5047\u5b9a \\(\\sigma_t^2=\\tilde{\\beta}_t\\), \u90a3\u4e48: <\/p>\n\n\n\n<p>\\[q\\left(\\mathbf{x}{t-1} \\mid \\mathbf{x}t, \\mathbf{x}_0\\right)=\\mathcal{N}\\left(\\mathbf{x}{t-1} ; \\tilde{\\boldsymbol{\\mu}}\\left(\\mathbf{x}t, \\mathbf{x}_0\\right), \\sigma_t^2 \\mathbf{I}\\right) p\\theta\\left(\\mathbf{x}{t-1} \\mid \\mathbf{x}_t\\right)=\\mathcal{N}\\left(\\mathbf{x}{t-1} ; \\boldsymbol{\\mu}_\\theta\\left(\\mathbf{x}_t, t\\right), \\sigma_t^2 \\mathbf{I}\\right)<br>\\]<br>\u5bf9\u4e8e\u4e24\u4e2a\u9ad8\u65af\u5206\u5e03\u7684KL\u6563\u5ea6, \u5176\u8ba1\u7b97\u516c\u5f0f\u4e3a\uff08\u5177\u4f53\u63a8\u5bfc\u89c1\u751f\u6210\u6a21\u578b\u4e4bVAE\uff09:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"735\" height=\"80\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-143.png\" alt=\"\" class=\"wp-image-7787\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-143.png 735w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-143-300x33.png 300w\" sizes=\"(max-width: 735px) 100vw, 735px\" \/><\/figure>\n\n\n\n<p>\u90a3\u4e48\u5c31\u6709\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"829\" height=\"147\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-144.png\" alt=\"\" class=\"wp-image-7788\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-144.png 829w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-144-300x53.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-144-768x136.png 768w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-144-825x147.png 825w\" sizes=\"(max-width: 829px) 100vw, 829px\" \/><\/figure>\n\n\n\n<p>\u90a3\u4e48\u4f18\u5316\u76ee\u6807\u5373\\(L{t-1}\\)\u4e3a\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"443\" height=\"69\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-145.png\" alt=\"\" class=\"wp-image-7792\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-145.png 443w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-145-300x47.png 300w\" sizes=\"(max-width: 443px) 100vw, 443px\" \/><\/figure>\n\n\n\n<p>\u4ece\u4e0a\u8ff0\u516c\u5f0f\u6765\u770b, \u6211\u4eec\u662f\u5e0c\u671b\u7f51\u7edc\u5b66\u4e60\u5230\u7684\u5747\u503c \\(\\boldsymbol{\\mu}\\theta\\left(\\mathbf{x}_t, t\\right)\\) \u548c\u540e\u9a8c\u5206\u5e03\u7684\u5747\u503c \\(\\tilde{\\boldsymbol{\\mu}}\\left(\\mathbf{x}_t, \\mathbf{x}_0\\right)\\) \u4e00\u81f4\u3002\u4e0d \u8fc7DDPM\u53d1\u73b0\u9884\u6d4b\u5747\u503c\u5e76\u4e0d\u662f\u6700\u597d\u7684\u9009\u62e9\u3002\u6839\u636e\u524d\u9762\u5f97\u5230\u7684\u6269\u6563\u8fc7\u7a0b\u7684\u7279\u6027, \u6211\u4eec\u6709:<\/p>\n\n\n\n<p> \\(\\mathbf{x}{\\mathbf{t}}\\left(\\mathbf{x}_{\\mathbf{0}}, \\epsilon\\right)=\\sqrt{\\bar{\\alpha}_t} \\mathbf{x}_0+\\sqrt{1-\\bar{\\alpha}_t \\epsilon} \\quad \\text { where } \\epsilon \\sim \\mathcal{N}(\\mathbf{0}, \\mathbf{I})<br>\\)<\/p>\n\n\n\n<p>\u5c06\u8fd9\u4e2a\u516c\u5f0f\u5e26\u5165\u4e0a\u8ff0\u4f18\u5316\u76ee\u6807\uff0c\u53ef\u4ee5\u5f97\u5230\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"815\" height=\"414\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-146.png\" alt=\"\" class=\"wp-image-7795\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-146.png 815w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-146-300x152.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-146-768x390.png 768w\" sizes=\"(max-width: 815px) 100vw, 815px\" \/><\/figure>\n\n\n\n<p>\u8fd1\u4e00\u6b65\u5730, \u6211\u4eec\u5bf9 \\(\\boldsymbol{\\mu}\\theta\\left(\\mathbf{x}{\\mathbf{t}}\\left(\\mathbf{x}0, \\epsilon\\right), t\\right)\\) \u4e5f\u8fdb\u884c\u91cd\u53c2\u6570\u5316, \u53d8\u6210: <\/p>\n\n\n\n<p>\\[\\boldsymbol{\\mu}\\theta\\left(\\mathbf{x}{\\mathbf{t}}\\left(\\mathbf{x}_0, \\epsilon\\right), t\\right)=\\frac{1}{\\sqrt{\\alpha_t}}\\left(\\mathbf{x}_t\\left(\\mathbf{x}_0, \\epsilon\\right)-\\frac{\\beta_t}{\\sqrt{1-\\bar{\\alpha}_t}} \\epsilon\\theta\\left(\\mathbf{x}t\\left(\\mathbf{x}_0, \\epsilon\\right), t\\right)\\right)\\]<\/p>\n\n\n\n<p> \u8fd9\u91cc\u7684 \\(\\epsilon\\theta\\) \u662f\u4e00\u4e2a\u57fa\u4e8e\u795e\u7ecf\u7f51\u7edc\u7684\u62df\u5408\u51fd\u6570, \u8fd9\u610f\u5473\u7740\u6211\u4eec\u7531\u539f\u6765\u7684\u9884\u6d4b\u5747\u503c\u800c\u6362\u6210\u9884\u6d4b\u566a\u97f3 \\(\\epsilon\\) \u3002\u6211\u4eec\u5c06\u4e0a\u8ff0\u7b49\u5f0f\u5e26\u5165\u4f18\u5316\u76ee\u6807, \u53ef\u4ee5\u5f97\u5230:<br><\/p>\n\n\n\n<p>DDPM\u8fd1\u4e00\u6b65\u5bf9\u4e0a\u8ff0\u76ee\u6807\u8fdb\u884c\u4e86\u7b80\u5316, \u5373\u53bb\u6389\u4e86\u6743\u91cd\u7cfb\u6570, \u53d8\u6210\u4e86: \\(L{t-1}^{\\text {simple }}=\\mathbb{E}{\\mathbf{x}_0, \\epsilon \\sim \\mathcal{N}(0, \\mathrm{I})}\\left[\\left|\\epsilon-\\epsilon\\theta\\left(\\sqrt{\\bar{\\alpha}_t} \\mathbf{x}_0+\\sqrt{1-\\bar{\\alpha}_t} \\epsilon, t\\right)\\right|^2\\right]\\) \u8fd9\u91cc\u7684 \\(t\\) \u5728 \\([1, \\mathrm{~T}]\\) \u8303\u56f4\u5185\u53d6\u503c\uff08\u5982\u524d\u6240\u8ff0, \u5176\u4e2d\u53d6 1 \u65f6\u5bf9\u5e94 \\(L_0\\) )\u3002\u7531\u4e8e\u53bb\u6389\u4e86\u4e0d\u540c \\(t\\)\u7684\u6743\u91cd\u7cfb\u6570, \u6240\u4ee5\u8fd9\u4e2a\u7b80\u5316\u7684\u76ee\u6807\u5176\u5b9e\u662fVLB\u4f18\u5316 \u76ee\u6807\u8fdb\u884c\u4e86 reweight\u3002\u4eceDDPM\u7684\u5bf9\u6bd4\u5b9e\u9a8c\u7ed3\u679c\u6765\u770b, \u9884\u6d4b\u566a\u97f3\u6bd4\u9884\u6d4b\u5747\u503c\u6548\u679c\u8981\u597d, \u91c7\u7528\u7b80 \u5316\u7248\u672c\u7684\u4f18\u5316\u76ee\u6807\u6bd4VLB\u76ee\u6807\u6548\u679c\u8981\u597d:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"808\" height=\"751\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-147.png\" alt=\"\" class=\"wp-image-7799\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-147.png 808w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-147-300x279.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-147-768x714.png 768w\" sizes=\"(max-width: 808px) 100vw, 808px\" \/><\/figure>\n\n\n\n<p>\u867d\u7136\u6269\u6563\u6a21\u578b\u80cc\u540e\u7684\u63a8\u5bfc\u6bd4\u8f83\u590d\u6742\uff0c\u4f46\u662f\u6211\u4eec\u6700\u7ec8\u5f97\u5230\u7684\u4f18\u5316\u76ee\u6807\u975e\u5e38\u7b80\u5355\uff0c\u5c31\u662f\u8ba9\u7f51\u7edc\u9884\u6d4b\u7684\u566a\u97f3\u548c\u771f\u5b9e\u7684\u566a\u97f3\u4e00\u81f4\u3002DDPM\u7684\u8bad\u7ec3\u8fc7\u7a0b\u4e5f\u975e\u5e38\u7b80\u5355\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a\u968f\u673a\u9009\u62e9\u4e00\u4e2a\u8bad\u7ec3\u6837\u672c-&gt;\u4ece1-T\u968f\u673a\u62bd\u6837\u4e00\u4e2at-&gt;\u968f\u673a\u4ea7\u751f\u566a\u97f3-\u8ba1\u7b97\u5f53\u524d\u6240\u4ea7\u751f\u7684\u5e26\u566a\u97f3\u6570\u636e\uff08\u7ea2\u8272\u6846\u6240\u793a\uff09-&gt;\u8f93\u5165\u7f51\u7edc\u9884\u6d4b\u566a\u97f3-&gt;\u8ba1\u7b97\u4ea7\u751f\u7684\u566a\u97f3\u548c\u9884\u6d4b\u7684\u566a\u97f3\u7684L2\u635f\u5931-&gt;\u8ba1\u7b97\u68af\u5ea6\u5e76\u66f4\u65b0\u7f51\u7edc\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"813\" height=\"204\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-148.png\" alt=\"\" class=\"wp-image-7800\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-148.png 813w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-148-300x75.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-148-768x193.png 768w\" sizes=\"(max-width: 813px) 100vw, 813px\" \/><\/figure>\n\n\n\n<p>\u4e00\u65e6\u8bad\u7ec3\u5b8c\u6210\uff0c\u5176\u91c7\u6837\u8fc7\u7a0b\u4e5f\u975e\u5e38\u7b80\u5355\uff0c\u5982\u4e0a\u6240\u793a\uff1a\u6211\u4eec\u4ece\u4e00\u4e2a\u968f\u673a\u566a\u97f3\u5f00\u59cb\uff0c\u5e76\u7528\u8bad\u7ec3\u597d\u7684\u7f51\u7edc\u9884\u6d4b\u566a\u97f3\uff0c\u7136\u540e\u8ba1\u7b97\u6761\u4ef6\u5206\u5e03\u7684\u5747\u503c\uff08\u7ea2\u8272\u6846\u90e8\u5206\uff09\uff0c\u7136\u540e\u7528\u5747\u503c\u52a0\u6807\u51c6\u5dee\u4e58\u4ee5\u4e00\u4e2a\u968f\u673a\u566a\u97f3\uff0c\u76f4\u81f3t=0\u5b8c\u6210\u65b0\u6837\u672c\u7684\u751f\u6210\uff08\u6700\u540e\u4e00\u6b65\u4e0d\u52a0\u566a\u97f3\uff09\u3002\u4e0d\u8fc7\u5b9e\u9645\u7684\u4ee3\u7801\u5b9e\u73b0\u548c\u4e0a\u8ff0\u8fc7\u7a0b\u7565\u6709\u533a\u522b\uff08\u89c1https:\/\/github.com\/hojonathanho\/diffusion\/issues\/5\uff1a\u5148\u57fa\u4e8e\u9884\u6d4b\u7684\u566a\u97f3\u751f\u6210\uff0c\u5e76\u8fdb\u884c\u4e86<strong>clip\u5904\u7406<\/strong>\uff08\u8303\u56f4[-1, 1]\uff0c\u539f\u59cb\u6570\u636e\u5f52\u4e00\u5316\u5230\u8fd9\u4e2a\u8303\u56f4\uff09\uff0c\u7136\u540e\u518d\u8ba1\u7b97\u5747\u503c\u3002\u6211\u4e2a\u4eba\u7684\u7406\u89e3\u8fd9\u5e94\u8be5\u7b97\u662f\u4e00\u79cd\u7ea6\u675f\uff0c\u65e2\u7136\u6a21\u578b\u9884\u6d4b\u7684\u662f\u566a\u97f3\uff0c\u90a3\u4e48\u6211\u4eec\u4e5f\u5e0c\u671b\u7528\u9884\u6d4b\u566a\u97f3\u91cd\u6784\u5904\u7406\u7684\u539f\u59cb\u6570\u636e\u4e5f\u5e94\u8be5\u6ee1\u8db3\u8303\u56f4\u8981\u6c42\u3002<\/p>\n\n\n\n<h3>\u6a21\u578b\u8bbe\u8ba1<\/h3>\n\n\n\n<p>\u524d\u9762\u6211\u4eec\u4ecb\u7ecd\u4e86\u6269\u6563\u6a21\u578b\u7684\u539f\u7406\u4ee5\u53ca\u4f18\u5316\u76ee\u6807\uff0c\u90a3\u4e48\u6269\u6563\u6a21\u578b\u7684\u6838\u5fc3\u5c31\u5728\u4e8e\u8bad\u7ec3\u566a\u97f3\u9884\u6d4b\u6a21\u578b\uff0c\u7531\u4e8e\u566a\u97f3\u548c\u539f\u59cb\u6570\u636e\u662f\u540c\u7ef4\u5ea6\u7684\uff0c\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u9009\u62e9\u91c7\u7528<strong>AutoEncoder\u67b6\u6784<\/strong>\u6765\u4f5c\u4e3a\u566a\u97f3\u9884\u6d4b\u6a21\u578b\u3002DDPM\u6240\u91c7\u7528\u7684\u6a21\u578b\u662f\u4e00\u4e2a\u57fa\u4e8eresidual block\u548cattention block\u7684<strong>U-Net\u6a21\u578b<\/strong>\u3002\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"818\" height=\"263\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-149.png\" alt=\"\" class=\"wp-image-7801\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-149.png 818w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-149-300x96.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-149-768x247.png 768w\" sizes=\"(max-width: 818px) 100vw, 818px\" \/><\/figure>\n\n\n\n<p>U-Net\u5c5e\u4e8eencoder-decoder\u67b6\u6784\uff0c\u5176\u4e2dencoder\u5206\u6210\u4e0d\u540c\u7684stages\uff0c\u6bcf\u4e2astage\u90fd\u5305\u542b\u4e0b\u91c7\u6837\u6a21\u5757\u6765\u964d\u4f4e\u7279\u5f81\u7684\u7a7a\u95f4\u5927\u5c0f\uff08H\u548cW\uff09\uff0c\u7136\u540edecoder\u548cencoder\u76f8\u53cd\uff0c\u662f\u5c06encoder\u538b\u7f29\u7684\u7279\u5f81\u9010\u6e10\u6062\u590d\u3002U-Net\u5728decoder\u6a21\u5757\u4e2d\u8fd8\u5f15\u5165\u4e86<strong>skip connection<\/strong>\uff0c\u5373concat\u4e86encoder\u4e2d\u95f4\u5f97\u5230\u7684\u540c\u7ef4\u5ea6\u7279\u5f81\uff0c\u8fd9\u6709\u5229\u4e8e\u7f51\u7edc\u4f18\u5316\u3002DDPM\u6240\u91c7\u7528\u7684U-Net\u6bcf\u4e2astage\u5305\u542b<strong>2\u4e2aresidual block<\/strong>\uff0c\u800c\u4e14\u90e8\u5206stage\u8fd8\u52a0\u5165\u4e86<strong>self-attention\u6a21\u5757<\/strong>\u589e\u52a0\u7f51\u7edc\u7684\u5168\u5c40\u5efa\u6a21\u80fd\u529b\u3002 \u53e6\u5916\uff0c\u6269\u6563\u6a21\u578b\u5176\u5b9e\u9700\u8981\u7684\u662f\u4e2a\u566a\u97f3\u9884\u6d4b\u6a21\u578b\uff0c\u5b9e\u9645\u5904\u7406\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u589e\u52a0\u4e00\u4e2a<strong>time embedding<\/strong>\uff08\u7c7b\u4f3ctransformer\u4e2d\u7684position embedding\uff09\u6765\u5c06timestep\u7f16\u7801\u5230\u7f51\u7edc\u4e2d\uff0c\u4ece\u800c\u53ea\u9700\u8981\u8bad\u7ec3\u4e00\u4e2a\u5171\u4eab\u7684U-Net\u6a21\u578b\u3002\u5177\u4f53\u5730\uff0cDDPM\u5728\u5404\u4e2aresidual block\u90fd\u5f15\u5165\u4e86<strong>time embedding<\/strong>\uff0c\u5982\u4e0a\u56fe\u6240\u793a\u3002<\/p>\n\n\n\n<h2 id=\"h_563661713_5\"><strong>\u4ee3\u7801\u5b9e\u73b0<\/strong><\/h2>\n\n\n\n<p>\u6700\u540e\uff0c\u6211\u4eec\u57fa\u4e8ePyTorch\u6846\u67b6\u7ed9\u51faDDPM\u7684\u5177\u4f53\u5b9e\u73b0\uff0c\u8fd9\u91cc\u4e3b\u8981\u53c2\u8003\u4e86\u4e09\u5957\u4ee3\u7801\u5b9e\u73b0\uff1a<\/p>\n\n\n\n<ul><li><a href=\"https:\/\/github.com\/hojonathanho\/diffusion\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub &#8211; hojonathanho\/diffusion: Denoising Diffusion Probabilistic Models<\/a>\uff08\u5b98\u65b9TensorFlow\u5b9e\u73b0\uff09<\/li><li><a href=\"https:\/\/github.com\/openai\/improved-diffusion\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub &#8211; openai\/improved-diffusion: Release for Improved Denoising Diffusion Probabilistic Models<\/a>&nbsp;\uff08OpenAI\u57fa\u4e8ePyTorch\u5b9e\u73b0\u7684DDPM+\uff09<\/li><li><a href=\"https:\/\/github.com\/lucidrains\/denoising-diffusion-pytorch\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub &#8211; lucidrains\/denoising-diffusion-pytorch: Implementation of Denoising Diffusion Probabilistic Model in Pytorch<\/a><\/li><\/ul>\n\n\n\n<p>\u9996\u5148\uff0c\u662ftime embeding\uff0c\u8fd9\u91cc\u662f\u91c7\u7528<a rel=\"noreferrer noopener\" href=\"https:\/\/arxiv.org\/abs\/1706.03762\" target=\"_blank\">Attention Is All You Need<\/a>\u4e2d\u6240\u8bbe\u8ba1\u7684<strong>sinusoidal position embedding<\/strong>\uff0c\u53ea\u4e0d\u8fc7\u662f\u7528\u6765\u7f16\u7801timestep\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># use sinusoidal position embedding to encode time step (https:\/\/arxiv.org\/abs\/1706.03762)   \ndef timestep_embedding(timesteps, dim, max_period=10000):\n    \"\"\"\n    Create sinusoidal timestep embeddings.\n    :param timesteps: a 1-D Tensor of N indices, one per batch element.\n                      These may be fractional.\n    :param dim: the dimension of the output.\n    :param max_period: controls the minimum frequency of the embeddings.\n    :return: an &#91;N x dim] Tensor of positional embeddings.\n    \"\"\"\n    half = dim \/\/ 2\n    freqs = torch.exp(\n        -math.log(max_period) * torch.arange(start=0, end=half, dtype=torch.float32) \/ half\n    ).to(device=timesteps.device)\n    args = timesteps&#91;:, None].float() * freqs&#91;None]\n    embedding = torch.cat(&#91;torch.cos(args), torch.sin(args)], dim=-1)\n    if dim % 2:\n        embedding = torch.cat(&#91;embedding, torch.zeros_like(embedding&#91;:, :1])], dim=-1)\n    return embedding<\/code><\/pre>\n\n\n\n<p>\u7531\u4e8e\u53ea\u6709residual block\u624d\u5f15\u5165time embedding\uff0c\u6240\u4ee5\u53ef\u4ee5\u5b9a\u4e49\u4e00\u4e9b\u8f85\u52a9\u6a21\u5757\u6765\u81ea\u52a8\u5904\u7406\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em># define TimestepEmbedSequential to support `time_emb` as extra input<\/em>\nclass TimestepBlock(nn.Module):\n    \"\"\"\n    Any module where forward() takes timestep embeddings as a second argument.\n    \"\"\"\n\n    @abstractmethod\n    def forward(self, x, emb):\n        \"\"\"\n        Apply the module to `x` given `emb` timestep embeddings.\n        \"\"\"\n\n\nclass TimestepEmbedSequential(nn.Sequential, TimestepBlock):\n    \"\"\"\n    A sequential module that passes timestep embeddings to the children that\n    support it as an extra input.\n    \"\"\"\n\n    def forward(self, x, emb):\n        for layer in self:\n            if isinstance(layer, TimestepBlock):\n                x = layer(x, emb)\n            else:\n                x = layer(x)\n        return x<\/code><\/pre>\n\n\n\n<p>\u8fd9\u91cc\u6240\u91c7\u7528\u7684U-Net\u91c7\u7528<strong>GroupNorm\u8fdb\u884c\u5f52\u4e00\u5316<\/strong>\uff0c\u6240\u4ee5\u8fd9\u91cc\u4e5f\u7b80\u5355\u5b9a\u4e49\u4e86\u4e00\u4e2anorm layer\u4ee5\u65b9\u4fbf\u4f7f\u7528\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># use GN for norm layer\ndef norm_layer(channels):\n    return nn.GroupNorm(32, channels)<\/code><\/pre>\n\n\n\n<p>U-Net\u7684\u6838\u5fc3\u6a21\u5757\u662fresidual block\uff0c\u5b83\u5305\u542b\u4e24\u4e2a\u5377\u79ef\u5c42\u4ee5\u53cashortcut\uff0c\u540c\u65f6\u4e5f\u8981\u5f15\u5165time embedding\uff0c\u8fd9\u91cc\u989d\u5916\u5b9a\u4e49\u4e86\u4e00\u4e2alinear\u5c42\u6765\u5c06time embedding\u53d8\u6362\u4e3a\u548c\u7279\u5f81\u7ef4\u5ea6\u4e00\u81f4\uff0c\u7b2c\u4e00conv\u4e4b\u540e\u901a\u8fc7\u52a0\u4e0atime embedding\u6765\u7f16\u7801time\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Residual block\nclass ResidualBlock(TimestepBlock):\n    def __init__(self, in_channels, out_channels, time_channels, dropout):\n        super().__init__()\n        self.conv1 = nn.Sequential(\n            norm_layer(in_channels),\n            nn.SiLU(),\n            nn.Conv2d(in_channels, out_channels, kernel_size=3, padding=1)\n        )\n        \n        # pojection for time step embedding\n        self.time_emb = nn.Sequential(\n            nn.SiLU(),\n            nn.Linear(time_channels, out_channels)\n        )\n        \n        self.conv2 = nn.Sequential(\n            norm_layer(out_channels),\n            nn.SiLU(),\n            nn.Dropout(p=dropout),\n            nn.Conv2d(out_channels, out_channels, kernel_size=3, padding=1)\n        )\n\n        if in_channels != out_channels:\n            self.shortcut = nn.Conv2d(in_channels, out_channels, kernel_size=1)\n        else:\n            self.shortcut = nn.Identity()\n\n\n    def forward(self, x, t):\n        \"\"\"\n        `x` has shape `&#91;batch_size, in_dim, height, width]`\n        `t` has shape `&#91;batch_size, time_dim]`\n        \"\"\"\n        h = self.conv1(x)\n        # Add time step embeddings\n        h += self.time_emb(t)&#91;:, :, None, None]\n        h = self.conv2(h)\n        return h + self.shortcut(x)<\/code><\/pre>\n\n\n\n<p>\u8fd9\u91cc\u8fd8\u5728\u90e8\u5206residual block\u5f15\u5165\u4e86attention\uff0c\u8fd9\u91cc\u7684attention\u548ctransformer\u7684self-attention\u662f\u4e00\u81f4\u7684\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Attention block with shortcut\nclass AttentionBlock(nn.Module):\n    def __init__(self, channels, num_heads=1):\n        super().__init__()\n        self.num_heads = num_heads\n        assert channels % num_heads == 0\n        \n        self.norm = norm_layer(channels)\n        self.qkv = nn.Conv2d(channels, channels * 3, kernel_size=1, bias=False)\n        self.proj = nn.Conv2d(channels, channels, kernel_size=1)\n\n    def forward(self, x):\n        B, C, H, W = x.shape\n        qkv = self.qkv(self.norm(x))\n        q, k, v = qkv.reshape(B*self.num_heads, -1, H*W).chunk(3, dim=1)\n        scale = 1. \/ math.sqrt(math.sqrt(C \/\/ self.num_heads))\n        attn = torch.einsum(\"bct,bcs-&gt;bts\", q * scale, k * scale)\n        attn = attn.softmax(dim=-1)\n        h = torch.einsum(\"bts,bcs-&gt;bct\", attn, v)\n        h = h.reshape(B, -1, H, W)\n        h = self.proj(h)\n        return h + x<\/code><\/pre>\n\n\n\n<p>\u5bf9\u4e8e\u4e0a\u91c7\u6837\u6a21\u5757\u548c\u4e0b\u91c7\u6837\u6a21\u5757\uff0c\u5176\u5206\u522b\u53ef\u4ee5\u91c7\u7528\u63d2\u503c\u548cstride=2\u7684conv\u6216\u8005pooling\u6765\u5b9e\u73b0\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># upsample\nclass Upsample(nn.Module):\n    def __init__(self, channels, use_conv):\n        super().__init__()\n        self.use_conv = use_conv\n        if use_conv:\n            self.conv = nn.Conv2d(channels, channels, kernel_size=3, padding=1)\n\n    def forward(self, x):\n        x = F.interpolate(x, scale_factor=2, mode=\"nearest\")\n        if self.use_conv:\n            x = self.conv(x)\n        return x\n\n# downsample\nclass Downsample(nn.Module):\n    def __init__(self, channels, use_conv):\n        super().__init__()\n        self.use_conv = use_conv\n        if use_conv:\n            self.op = nn.Conv2d(channels, channels, kernel_size=3, stride=2, padding=1)\n        else:\n            self.op = nn.AvgPool2d(stride=2)\n\n    def forward(self, x):\n        return self.op(x)<\/code><\/pre>\n\n\n\n<p>\u4e0a\u9762\u6211\u4eec\u5b9e\u73b0\u4e86U-Net\u7684\u6240\u6709\u7ec4\u4ef6\uff0c\u5c31\u53ef\u4ee5\u8fdb\u884c\u7ec4\u5408\u6765\u5b9e\u73b0U-Net\u4e86\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> The full UNet model with attention and timestep embedding\nclass UNetModel(nn.Module):\n    def __init__(\n        self,\n        in_channels=3,\n        model_channels=128,\n        out_channels=3,\n        num_res_blocks=2,\n        attention_resolutions=(8, 16),\n        dropout=0,\n        channel_mult=(1, 2, 2, 2),\n        conv_resample=True,\n        num_heads=4\n    ):\n        super().__init__()\n\n        self.in_channels = in_channels\n        self.model_channels = model_channels\n        self.out_channels = out_channels\n        self.num_res_blocks = num_res_blocks\n        self.attention_resolutions = attention_resolutions\n        self.dropout = dropout\n        self.channel_mult = channel_mult\n        self.conv_resample = conv_resample\n        self.num_heads = num_heads\n        \n        # time embedding\n        time_embed_dim = model_channels * 4\n        self.time_embed = nn.Sequential(\n            nn.Linear(model_channels, time_embed_dim),\n            nn.SiLU(),\n            nn.Linear(time_embed_dim, time_embed_dim),\n        )\n        \n        # down blocks\n        self.down_blocks = nn.ModuleList(&#91;\n            TimestepEmbedSequential(nn.Conv2d(in_channels, model_channels, kernel_size=3, padding=1))\n        ])\n        down_block_chans = &#91;model_channels]\n        ch = model_channels\n        ds = 1\n        for level, mult in enumerate(channel_mult):\n            for _ in range(num_res_blocks):\n                layers = &#91;\n                    ResidualBlock(ch, mult * model_channels, time_embed_dim, dropout)\n                ]\n                ch = mult * model_channels\n                if ds in attention_resolutions:\n                    layers.append(AttentionBlock(ch, num_heads=num_heads))\n                self.down_blocks.append(TimestepEmbedSequential(*layers))\n                down_block_chans.append(ch)\n            if level != len(channel_mult) - 1: # don't use downsample for the last stage\n                self.down_blocks.append(TimestepEmbedSequential(Downsample(ch, conv_resample)))\n                down_block_chans.append(ch)\n                ds *= 2\n        \n        # middle block\n        self.middle_block = TimestepEmbedSequential(\n            ResidualBlock(ch, ch, time_embed_dim, dropout),\n            AttentionBlock(ch, num_heads=num_heads),\n            ResidualBlock(ch, ch, time_embed_dim, dropout)\n        )\n        \n        # up blocks\n        self.up_blocks = nn.ModuleList(&#91;])\n        for level, mult in list(enumerate(channel_mult))&#91;::-1]:\n            for i in range(num_res_blocks + 1):\n                layers = &#91;\n                    ResidualBlock(\n                        ch + down_block_chans.pop(),\n                        model_channels * mult,\n                        time_embed_dim,\n                        dropout\n                    )\n                ]\n                ch = model_channels * mult\n                if ds in attention_resolutions:\n                    layers.append(AttentionBlock(ch, num_heads=num_heads))\n                if level and i == num_res_blocks:\n                    layers.append(Upsample(ch, conv_resample))\n                    ds \/\/= 2\n                self.up_blocks.append(TimestepEmbedSequential(*layers))\n\n        self.out = nn.Sequential(\n            norm_layer(ch),\n            nn.SiLU(),\n            nn.Conv2d(model_channels, out_channels, kernel_size=3, padding=1),\n        )\n\n    def forward(self, x, timesteps):\n        \"\"\"\n        Apply the model to an input batch.\n        :param x: an &#91;N x C x H x W] Tensor of inputs.\n        :param timesteps: a 1-D batch of timesteps.\n        :return: an &#91;N x C x ...] Tensor of outputs.\n        \"\"\"\n        hs = &#91;]\n        # time step embedding\n        emb = self.time_embed(timestep_embedding(timesteps, self.model_channels))\n        \n        # down stage\n        h = x\n        for module in self.down_blocks:\n            h = module(h, emb)\n            hs.append(h)\n        # middle stage\n        h = self.middle_block(h, emb)\n        # up stage\n        for module in self.up_blocks:\n            cat_in = torch.cat(&#91;h, hs.pop()], dim=1)\n            h = module(cat_in, emb)\n        return self.out(h)<\/code><\/pre>\n\n\n\n<p>\u5bf9\u4e8e\u6269\u6563\u8fc7\u7a0b\uff0c\u5176\u4e3b\u8981\u7684\u53c2\u6570\u5c31\u662ftimesteps\u548cnoise schedule\uff0cDDPM\u91c7\u7528\u8303\u56f4\u4e3a[0.0001, 0.02]\u7684\u7ebf\u6027noise schedule\uff0c\u5176\u9ed8\u8ba4\u91c7\u7528\u7684\u603b\u6269\u6563\u6b65\u6570\u4e3a<strong>1000<\/strong>\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># beta schedule\ndef linear_beta_schedule(timesteps):\n    scale = 1000 \/ timesteps\n    beta_start = scale * 0.0001\n    beta_end = scale * 0.02\n    return torch.linspace(beta_start, beta_end, timesteps, dtype=torch.float64)<\/code><\/pre>\n\n\n\n<p>\u6211\u4eec\u5b9a\u4e49\u4e2a\u6269\u6563\u6a21\u578b\uff0c\u5b83\u4e3b\u8981\u8981\u63d0\u524d\u6839\u636e\u8bbe\u8ba1\u7684noise schedule\u6765\u8ba1\u7b97\u4e00\u4e9b\u7cfb\u6570\uff0c\u5e76\u5b9e\u73b0\u4e00\u4e9b\u6269\u6563\u8fc7\u7a0b\u548c\u751f\u6210\u8fc7\u7a0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class GaussianDiffusion:\n    def __init__(\n        self,\n        timesteps=1000,\n        beta_schedule='linear'\n    ):\n        self.timesteps = timesteps\n        \n        if beta_schedule == 'linear':\n            betas = linear_beta_schedule(timesteps)\n        elif beta_schedule == 'cosine':\n            betas = cosine_beta_schedule(timesteps)\n        else:\n            raise ValueError(f'unknown beta schedule {beta_schedule}')\n        self.betas = betas\n            \n        self.alphas = 1. - self.betas\n        self.alphas_cumprod = torch.cumprod(self.alphas, axis=0)\n        self.alphas_cumprod_prev = F.pad(self.alphas_cumprod&#91;:-1], (1, 0), value=1.)\n        \n        # calculations for diffusion q(x_t | x_{t-1}) and others\n        self.sqrt_alphas_cumprod = torch.sqrt(self.alphas_cumprod)\n        self.sqrt_one_minus_alphas_cumprod = torch.sqrt(1.0 - self.alphas_cumprod)\n        self.log_one_minus_alphas_cumprod = torch.log(1.0 - self.alphas_cumprod)\n        self.sqrt_recip_alphas_cumprod = torch.sqrt(1.0 \/ self.alphas_cumprod)\n        self.sqrt_recipm1_alphas_cumprod = torch.sqrt(1.0 \/ self.alphas_cumprod - 1)\n        \n        # calculations for posterior q(x_{t-1} | x_t, x_0)\n        self.posterior_variance = (\n            self.betas * (1.0 - self.alphas_cumprod_prev) \/ (1.0 - self.alphas_cumprod)\n        )\n        # below: log calculation clipped because the posterior variance is 0 at the beginning\n        # of the diffusion chain\n        self.posterior_log_variance_clipped = torch.log(self.posterior_variance.clamp(min =1e-20))\n        \n        self.posterior_mean_coef1 = (\n            self.betas * torch.sqrt(self.alphas_cumprod_prev) \/ (1.0 - self.alphas_cumprod)\n        )\n        self.posterior_mean_coef2 = (\n            (1.0 - self.alphas_cumprod_prev)\n            * torch.sqrt(self.alphas)\n            \/ (1.0 - self.alphas_cumprod)\n        )\n    \n    # get the param of given timestep t\n    def _extract(self, a, t, x_shape):\n        batch_size = t.shape&#91;0]\n        out = a.to(t.device).gather(0, t).float()\n        out = out.reshape(batch_size, *((1,) * (len(x_shape) - 1)))\n        return out\n    \n    # forward diffusion (using the nice property): q(x_t | x_0)\n    def q_sample(self, x_start, t, noise=None):\n        if noise is None:\n            noise = torch.randn_like(x_start)\n\n        sqrt_alphas_cumprod_t = self._extract(self.sqrt_alphas_cumprod, t, x_start.shape)\n        sqrt_one_minus_alphas_cumprod_t = self._extract(self.sqrt_one_minus_alphas_cumprod, t, x_start.shape)\n\n        return sqrt_alphas_cumprod_t * x_start + sqrt_one_minus_alphas_cumprod_t * noise\n    \n    # Get the mean and variance of q(x_t | x_0).\n    def q_mean_variance(self, x_start, t):\n        mean = self._extract(self.sqrt_alphas_cumprod, t, x_start.shape) * x_start\n        variance = self._extract(1.0 - self.alphas_cumprod, t, x_start.shape)\n        log_variance = self._extract(self.log_one_minus_alphas_cumprod, t, x_start.shape)\n        return mean, variance, log_variance\n    \n    # Compute the mean and variance of the diffusion posterior: q(x_{t-1} | x_t, x_0)\n    def q_posterior_mean_variance(self, x_start, x_t, t):\n        posterior_mean = (\n            self._extract(self.posterior_mean_coef1, t, x_t.shape) * x_start\n            + self._extract(self.posterior_mean_coef2, t, x_t.shape) * x_t\n        )\n        posterior_variance = self._extract(self.posterior_variance, t, x_t.shape)\n        posterior_log_variance_clipped = self._extract(self.posterior_log_variance_clipped, t, x_t.shape)\n        return posterior_mean, posterior_variance, posterior_log_variance_clipped\n    \n    # compute x_0 from x_t and pred noise: the reverse of `q_sample`\n    def predict_start_from_noise(self, x_t, t, noise):\n        return (\n            self._extract(self.sqrt_recip_alphas_cumprod, t, x_t.shape) * x_t -\n            self._extract(self.sqrt_recipm1_alphas_cumprod, t, x_t.shape) * noise\n        )\n    \n    # compute predicted mean and variance of p(x_{t-1} | x_t)\n    def p_mean_variance(self, model, x_t, t, clip_denoised=True):\n        # predict noise using model\n        pred_noise = model(x_t, t)\n        # get the predicted x_0: different from the algorithm2 in the paper\n        x_recon = self.predict_start_from_noise(x_t, t, pred_noise)\n        if clip_denoised:\n            x_recon = torch.clamp(x_recon, min=-1., max=1.)\n        model_mean, posterior_variance, posterior_log_variance = \\\n                    self.q_posterior_mean_variance(x_recon, x_t, t)\n        return model_mean, posterior_variance, posterior_log_variance\n        \n    # denoise_step: sample x_{t-1} from x_t and pred_noise\n    @torch.no_grad()\n    def p_sample(self, model, x_t, t, clip_denoised=True):\n        # predict mean and variance\n        model_mean, _, model_log_variance = self.p_mean_variance(model, x_t, t,\n                                                    clip_denoised=clip_denoised)\n        noise = torch.randn_like(x_t)\n        # no noise when t == 0\n        nonzero_mask = ((t != 0).float().view(-1, *(&#91;1] * (len(x_t.shape) - 1))))\n        # compute x_{t-1}\n        pred_img = model_mean + nonzero_mask * (0.5 * model_log_variance).exp() * noise\n        return pred_img\n    \n    # denoise: reverse diffusion\n    @torch.no_grad()\n    def p_sample_loop(self, model, shape):\n        batch_size = shape&#91;0]\n        device = next(model.parameters()).device\n        # start from pure noise (for each example in the batch)\n        img = torch.randn(shape, device=device)\n        imgs = &#91;]\n        for i in tqdm(reversed(range(0, timesteps)), desc='sampling loop time step', total=timesteps):\n            img = self.p_sample(model, img, torch.full((batch_size,), i, device=device, dtype=torch.long))\n            imgs.append(img.cpu().numpy())\n        return imgs\n    \n    # sample new images\n    @torch.no_grad()\n    def sample(self, model, image_size, batch_size=8, channels=3):\n        return self.p_sample_loop(model, shape=(batch_size, channels, image_size, image_size))\n    \n    # compute train losses\n    def train_losses(self, model, x_start, t):\n        # generate random noise\n        noise = torch.randn_like(x_start)\n        # get x_t\n        x_noisy = self.q_sample(x_start, t, noise=noise)\n        predicted_noise = model(x_noisy, t)\n        loss = F.mse_loss(noise, predicted_noise)\n        return loss<\/code><\/pre>\n\n\n\n<p>\u5176\u4e2d\u51e0\u4e2a\u4e3b\u8981\u7684\u51fd\u6570\u603b\u7ed3\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul><li><code>q_sample<\/code>\uff1a\u5b9e\u73b0\u7684\u4ecex0\u5230xt\u6269\u6563\u8fc7\u7a0b\uff1b<\/li><li><code>q_posterior_mean_variance<\/code>\uff1a\u5b9e\u73b0\u7684\u662f\u540e\u9a8c\u5206\u5e03\u7684\u5747\u503c\u548c\u65b9\u5dee\u7684\u8ba1\u7b97\u516c\u5f0f\uff1b<\/li><li><code>predict_start_from_noise<\/code>\uff1a<code>q_sample<\/code>\u7684\u9006\u8fc7\u7a0b\uff0c\u6839\u636e\u9884\u6d4b\u7684\u566a\u97f3\u6765\u751f\u6210x0\uff1b<\/li><li><code>p_mean_variance<\/code>\uff1a\u6839\u636e\u9884\u6d4b\u7684\u566a\u97f3\u6765\u8ba1\u7b97p\u03b8(xt\u22121|xt)\u7684\u5747\u503c\u548c\u65b9\u5dee\uff1b<\/li><li><code>p_sample<\/code>\uff1a\u5355\u4e2a\u53bb\u566astep\uff1b<\/li><li><code>p_sample_loop<\/code>\uff1a\u6574\u4e2a\u53bb\u566a\u97f3\u8fc7\u7a0b\uff0c\u5373\u751f\u6210\u8fc7\u7a0b\u3002<\/li><\/ul>\n\n\n\n<p>\u6269\u6563\u6a21\u578b\u7684\u8bad\u7ec3\u8fc7\u7a0b\u975e\u5e38\u7b80\u5355\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># train\nepochs = 10\n\nfor epoch in range(epochs):\n    for step, (images, labels) in enumerate(train_loader):\n        optimizer.zero_grad()\n        \n        batch_size = images.shape&#91;0]\n        images = images.to(device)\n        \n        # sample t uniformally for every example in the batch\n        t = torch.randint(0, timesteps, (batch_size,), device=device).long()\n        \n        loss = gaussian_diffusion.train_losses(model, images, t)\n        \n        if step % 200 == 0:\n            print(\"Loss:\", loss.item())\n            \n        loss.backward()\n        optimizer.step()\n\u8fd9\u91cc\u6211\u4eec\u4ee5mnist\u6570\u636e\u7b80\u5355\u5b9e\u73b0\u4e86\u4e00\u4e2amnist-demo\uff0c\u4e0b\u9762\u662f\u4e00\u4e9b\u751f\u6210\u7684\u6837\u672c\uff1a<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"644\" height=\"647\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-150.png\" alt=\"\" class=\"wp-image-7802\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-150.png 644w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-150-300x300.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-150-150x150.png 150w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-150-120x120.png 120w\" sizes=\"(max-width: 644px) 100vw, 644px\" \/><\/figure>\n\n\n\n<p>\u5bf9\u751f\u6210\u8fc7\u7a0b\u8fdb\u884c\u91c7\u6837\uff0c\u5982\u4e0b\u6240\u793a\u5c55\u793a\u4e86\u5982\u4f55\u4ece\u4e00\u4e2a\u968f\u673a\u566a\u97f3\u751f\u5c42\u4e00\u4e2a\u624b\u5199\u5b57\u4f53\u56fe\u50cf\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"648\" height=\"651\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-151.png\" alt=\"\" class=\"wp-image-7803\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-151.png 648w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-151-300x300.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-151-150x150.png 150w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-151-120x120.png 120w\" sizes=\"(max-width: 648px) 100vw, 648px\" \/><\/figure>\n\n\n\n<p>\u53e6\u5916\u8fd9\u91cc\u4e5f\u63d0\u4f9b\u4e86CIFAR10\u6570\u636e\u96c6\u7684demo\uff1addpm_cifar10\uff0c\u4e0d\u8fc7\u53ea\u8bad\u7ec3\u4e86200epochs\uff0c\u751f\u6210\u7684\u56fe\u50cf\u53ea\u662f\u521d\u89c1\u6210\u6548\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"651\" height=\"654\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-152.png\" alt=\"\" class=\"wp-image-7804\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-152.png 651w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-152-300x300.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-152-150x150.png 150w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/09\/image-152-120x120.png 120w\" sizes=\"(max-width: 651px) 100vw, 651px\" \/><\/figure>\n\n\n\n<h3>\u5c0f\u7ed3<\/h3>\n\n\n\n<p>\u76f8\u6bd4VAE\u548cGAN\uff0c\u6269\u6563\u6a21\u578b\u7684\u7406\u8bba\u66f4\u590d\u6742\u4e00\u4e9b\uff0c\u4e0d\u8fc7\u5176\u4f18\u5316\u76ee\u6807\u548c\u5177\u4f53\u5b9e\u73b0\u5374\u5e76\u4e0d\u590d\u6742\uff0c\u8fd9\u5176\u5b9e\u4e5f\u8ba9\u4eba\u611f\u53f9\uff1a<strong>\u4e00\u5806\u590d\u6742\u7684\u6570\u636e\u63a8\u5bfc\uff0c\u6700\u7ec8\u5374\u5f97\u5230\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u7ed3\u8bba<\/strong>\u3002\u8981\u6df1\u5165\u7406\u89e3\u6269\u6563\u6a21\u578b\uff0c<strong>DDPM\u53ea\u662f\u8d77\u70b9<\/strong>\uff0c\u540e\u9762\u8fd8\u6709\u6bd4\u8f83\u591a\u7684\u6539\u8fdb\u5de5\u4f5c\uff0c\u6bd4\u5982\u52a0\u901f\u91c7\u6837\u7684DDIM\u4ee5\u53caDDPM\u7684\u6539\u8fdb\u7248\u672cDDPM+\u548cDDPM++\u3002<em>\u6ce8\uff1a\u672c\u4eba\u6c34\u5e73\u6709\u9650\uff0c\u5982\u6709\u8c2c\u8bef\uff0c\u6b22\u8fce\u8ba8\u8bba\u4ea4\u6d41\u3002<\/em><\/p>\n\n\n\n<h3>\u53c2\u8003<\/h3>\n\n\n\n<ul><li>Denoising Diffusion Probabilistic Models<\/li><li>Understanding Diffusion Models: A Unified Perspective<\/li><li>https:\/\/spaces.ac.cn\/archives\/9119<\/li><li>https:\/\/keras.io\/examples\/generative\/ddim\/<\/li><li>What are Diffusion Models?<\/li><li>https:\/\/cvpr2022-tutorial-diffusion-models.github.io\/<\/li><li>https:\/\/github.com\/openai\/improved-diffusion<\/li><li>https:\/\/huggingface.co\/blog\/annotated-diffusion<\/li><li>https:\/\/github.com\/lucidrains\/denoising-diffusion-pytorch<\/li><li>https:\/\/github.com\/hojonathanho\/diffusion<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u6458\u81ea\uff1ahttps:\/\/zhuanlan.zhihu.com\/p\/563661713 \u201cWhat I canno &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/09\/13\/ddpm\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u6269\u6563\u6a21\u578bDDPM<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[29],"tags":[],"_links":{"self":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/7705"}],"collection":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/comments?post=7705"}],"version-history":[{"count":77,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/7705\/revisions"}],"predecessor-version":[{"id":10171,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/7705\/revisions\/10171"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=7705"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=7705"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=7705"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}