{"id":2117,"date":"2024-09-23T21:03:35","date_gmt":"2024-09-23T13:03:35","guid":{"rendered":"https:\/\/www.gnn.club\/?p=2117"},"modified":"2025-03-12T15:05:33","modified_gmt":"2025-03-12T07:05:33","slug":"%e6%89%a9%e6%95%a3%e6%a8%a1%e5%9e%8b%ef%bc%88ddpm%ef%bc%89","status":"publish","type":"post","link":"http:\/\/gnn.club\/?p=2117","title":{"rendered":"\u6269\u6563\u6a21\u578b\uff08DDPM\uff09"},"content":{"rendered":"<h1><img decoding=\"async\" src=\"https:\/\/gnnclub-1311496010.cos.ap-beijing.myqcloud.com\/wp-content\/uploads\/2024\/09\/20240923210439155.png\" style=\"height:50px;display:inline\"> Deep Learning<\/h1>\n<hr \/>\n<p>create by Arwin Yu<\/p>\n<h2>Tutorial 07 - Denoising Diffusion Probabilistic Models (DDPM)<\/h2>\n<hr \/>\n<p align=\"center\">\n  <img decoding=\"async\" src=\"https:\/\/gnnclub-1311496010.cos.ap-beijing.myqcloud.com\/wp-content\/uploads\/2024\/09\/20240923210539350.png\" style=\"height:400px\">\n<\/p>\n<h3><img decoding=\"async\" src=\"https:\/\/img.icons8.com\/bubbles\/50\/000000\/checklist.png\" style=\"height:50px;display:inline\"> Agenda<\/h3>\n<hr \/>\n<ul>\n<li>\u6269\u6563\u6a21\u578b\u7684\u57fa\u672c\u539f\u7406<\/li>\n<li>\u524d\u5411\u6269\u6563<\/li>\n<li>\u635f\u5931\u51fd\u6570\u4e0e\u8bad\u7ec3<\/li>\n<li>\u53cd\u5411\u53bb\u566a\n<ul>\n<li>\u751f\u6210\u6a21\u578b\u603b\u4f53\u6846\u67b6<\/li>\n<li>VAE\u7684\u53d8\u5206\u4e0b\u754c<\/li>\n<li>DDPM\u7684\u53d8\u5206\u4e0b\u754c<\/li>\n<\/ul>\n<\/li>\n<li>Demo\uff1a\u751f\u6210\u745e\u58eb\u5377<\/li>\n<\/ul>\n<h2><img decoding=\"async\" src=\"https:\/\/img.icons8.com\/cute-clipart\/64\/000000\/alarm.png\" style=\"height:50px;display:inline\"> \u6269\u6563\u6a21\u578b\u7684\u57fa\u672c\u539f\u7406<\/h2>\n<hr \/>\n<p>Denoising Diffusion Probabilistic Models (DDPM) \u662f\u4e00\u79cd\u5229\u7528\u6269\u6563\u8fc7\u7a0b\u6765\u751f\u6210\u6837\u672c\u7684\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u3002\u5176\u4e3b\u8981\u7684\u7075\u611f\u6765\u6e90\u4e8e\u6269\u6563\u8fc7\u7a0b\uff0c\u901a\u8fc7\u9010\u6e10\u589e\u52a0\u566a\u97f3\u6765\u6a21\u7cca\u4e00\u4e2a\u521d\u59cb\u7684\u56fe\u50cf\uff0c\u5e76\u901a\u8fc7\u5b66\u4e60\u4e00\u4e2a\u53bb\u566a\u6a21\u578b\u6765\u9006\u5411\u56de\u5230\u539f\u59cb\u56fe\u50cf\u3002\u8fd9\u79cd\u65b9\u6cd5\u4e3a\u9ad8\u8d28\u91cf\u7684\u6837\u672c\u751f\u6210\u548c\u53d8\u6362\u63d0\u4f9b\u4e86\u4e00\u79cd\u65b0\u9896\u7684\u89c6\u89d2\u3002<\/p>\n<p>\u6269\u6563\u6a21\u578b\u4e3b\u8981\u6982\u5ff5\u548c\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li>\u6dfb\u52a0\u566a\u58f0\uff1a\u6a21\u578b\u4ece\u4e00\u5f20\u771f\u5b9e\u7684\u56fe\u50cf\u5f00\u59cb\uff0c\u7136\u540e\u9010\u6b65\u589e\u52a0\u566a\u58f0\u3002\u5728\u8fd9\u4e2a\u8fc7\u7a0b\u4e2d\uff0c\u56fe\u50cf\u7684\u7ec6\u8282\u548c\u7ed3\u6784\u9010\u6e10\u88ab\u566a\u58f0\u6240\u8986\u76d6\uff0c\u6700\u7ec8\u8f6c\u53d8\u6210\u968f\u673a\u566a\u58f0\u3002<\/li>\n<li>\u9006\u5411\u8fc7\u7a0b\uff1a\u5728\u751f\u6210\u8fc7\u7a0b\u4e2d\uff0c\u6a21\u578b\u6267\u884c\u4e0e\u6dfb\u52a0\u566a\u58f0\u76f8\u53cd\u7684\u64cd\u4f5c\u3002\u5b83\u4ece\u566a\u58f0\u56fe\u50cf\u5f00\u59cb\uff0c\u9010\u6b65\u53bb\u9664\u566a\u58f0\u5e76\u6062\u590d\u56fe\u50cf\u7684\u7ed3\u6784\u548c\u7ec6\u8282\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u662f\u901a\u8fc7\u8bad\u7ec3\u6a21\u578b\u6765\u5b66\u4e60\u5982\u4f55\u4ece\u566a\u58f0\u56fe\u50cf\u4e2d\u9010\u6b65\u6062\u590d\u51fa\u539f\u59cb\u56fe\u50cf\u6765\u5b9e\u73b0\u7684\u3002<\/li>\n<li>\u8bad\u7ec3\u8fc7\u7a0b\uff1a\u6a21\u578b\u901a\u8fc7\u5927\u91cf\u7684\u771f\u5b9e\u56fe\u50cf\u53ca\u5176\u566a\u58f0\u7248\u672c\u8fdb\u884c\u8bad\u7ec3\u3002\u5b83\u5b66\u4e60\u5982\u4f55\u9884\u6d4b\u5728\u6dfb\u52a0\u566a\u58f0\u7684\u8fc7\u7a0b\u4e2d\u4e22\u5931\u7684\u56fe\u50cf\u4fe1\u606f\uff0c\u4ece\u800c\u80fd\u591f\u5728\u751f\u6210\u8fc7\u7a0b\u4e2d\u9010\u6b65\u91cd\u5efa\u56fe\u50cf\u3002<\/li>\n<li>\u63a7\u5236\u751f\u6210\uff1a\u5728\u6a21\u578b\u8bad\u7ec3\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u5229\u7528\u5b83\u6765\u751f\u6210\u65b0\u7684\u56fe\u50cf\u3002\u8fd9\u901a\u5e38\u662f\u901a\u8fc7\u63d0\u4f9b\u4e00\u4e2a\u542b\u6709\u566a\u58f0\u7684\u8d77\u59cb\u56fe\u50cf\u548c\u4e00\u4e9b\u6307\u5bfc\u6761\u4ef6\uff08\u5982\u6587\u672c\u63cf\u8ff0\uff09\u6765\u5b9e\u73b0\u7684\u3002\u6a21\u578b\u7136\u540e\u6839\u636e\u8fd9\u4e9b\u6761\u4ef6\u53bb\u9664\u566a\u58f0\uff0c\u751f\u6210\u4e0e\u6761\u4ef6\u5339\u914d\u7684\u56fe\u50cf\u3002<\/li>\n<\/ol>\n<p align=\"center\">\n  <img decoding=\"async\" src=\"https:\/\/gnnclub-1311496010.cos.ap-beijing.myqcloud.com\/wp-content\/uploads\/2024\/09\/20240923210648495.png\" style=\"height:600px\">\n<\/p>\n<h2><img decoding=\"async\" src=\"https:\/\/img.icons8.com\/?size=100&id=71044&format=png&color=000000\" style=\"height:50px;display:inline\"> DDPM \u524d\u5411\u6269\u6563<\/h2>\n<hr \/>\n<p>\u5728\u6269\u6563\u6a21\u578b\u4e2d\uff0c\u566a\u58f0\u6ce8\u5165\u7684\u57fa\u672c\u601d\u60f3\u662f\u901a\u8fc7\u52a0\u5165\u968f\u673a\u566a\u58f0\uff0c\u4f7f\u5f97\u6570\u636e\u7684\u5206\u5e03\u8fdb\u884c\u53d8\u5316\uff0c\u4f7f\u5f97\u6a21\u578b\u5728\u8bad\u7ec3\u65f6\u9700\u8981\u9002\u5e94\u8fd9\u4e9b\u53d8\u5316\uff0c\u4ece\u800c\u53ef\u4ee5\u63d0\u9ad8\u6a21\u578b\u7684\u6cdb\u5316\u80fd\u529b\u3002<\/p>\n<p>\u6269\u6563\u6a21\u578b\u4e2d\u566a\u58f0\u6ce8\u5165\u7684\u5177\u4f53\u8fc7\u7a0b\u901a\u5e38\u5982\u4e0b\uff1a<\/p>\n<p>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u56fe\u7247\u6570\u636e\u96c6\u7684\u6982\u7387\u5206\u5e03 $P(x)$, \u6211\u4eec\u60f3\u8981\u6a21\u578b\u5b66\u4e60\u8fd9\u4e2a\u5206\u5e03\u3002<\/p>\n<p>\u5728\u6269\u6563\u6a21\u578b\u4e2d, \u6211\u4eec\u4e0d\u76f4\u63a5\u5bf9 $P(x)$ \u5efa\u6a21, \u800c\u662f\u5bf9\u4e00\u4e2a\u7531 $P(x)$ \u901a\u8fc7\u6269\u6563\u8fc7\u7a0b\u5f97\u5230\u7684\u5206\u5e03 $q\\left(x^{\\prime}\\right)$ \u5efa\u6a21\u3002<\/p>\n<p>\u8fd9\u4e2a\u6269\u6563\u8fc7\u7a0b\u53ef\u4ee5\u770b\u4f5c\u662f\u5411 $P(x)$ \u4e2d\u6ce8\u5165\u566a\u58f0\u3002<\/p>\n<p>\u5bf9\u4e8e\u6bcf\u4e00\u4e2a\u6570\u636e\u70b9 $x$, \u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u8fdb\u884c\u566a\u58f0\u6ce8\u5165:<\/p>\n<ul>\n<li>\u9009\u53d6\u4e00\u4e2a\u566a\u58f0\u5206\u5e03, \u4f8b\u5982\u9ad8\u65af\u566a\u58f0\u5206\u5e03 $N\\left(0, \\sigma^2\\right)$ \u3002<\/li>\n<li>\u4ece\u8fd9\u4e2a\u566a\u58f0\u5206\u5e03\u4e2d\u91c7\u6837\u51fa\u566a\u58f0 $\\varepsilon$, \u5e76\u5c06\u5176\u52a0\u5165\u5230\u6570\u636e\u70b9 $x$ \u4e2d, \u5f97\u5230\u65b0\u7684\u6570\u636e\u70b9 $x^{\\prime}$ \u3002\u5373:$x^{\\prime}=x+\\varepsilon \\text {, \u5176\u4e2d } \\varepsilon \\sim N\\left(0, \\sigma^2\\right)$<\/li>\n<li>\u8fd9\u5c31\u662f\u6269\u6563\u6a21\u578b\u4e2d\u566a\u58f0\u6ce8\u5165\u7684\u57fa\u672c\u8fc7\u7a0b\u3002\u5728\u8fd9\u4e2a\u8fc7\u7a0b\u4e2d, $\\sigma$ \u63a7\u5236\u4e86\u566a\u58f0\u7684\u5f3a\u5ea6\u3002 $\\sigma$ \u8d8a\u5927,\u566a\u58f0\u8d8a\u5f3a, \u6570\u636e\u70b9 $x^{\\prime}$ \u4e0e\u539f\u59cb\u6570\u636e\u70b9 $x$ \u7684\u5dee\u8ddd\u8d8a\u5927\u3002<\/li>\n<\/ul>\n<p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d, \u8fd9\u4e2a\u8fc7\u7a0b\u901a\u5e38\u4f1a\u88ab\u91cd\u590d\u591a\u6b21, \u6bcf\u6b21\u6ce8\u5165\u7684\u566a\u58f0\u53ef\u4ee5\u76f8\u540c, \u4e5f\u53ef\u4ee5\u4e0d\u540c\u3002\u4f8b\u5982, \u6211\u4eec\u53ef\u4ee5\u5728\u6bcf\u4e00\u6b65\u4e2d\u9010\u6e10\u589e\u5927 $\\sigma$, \u4f7f\u5f97\u566a\u58f0\u9010\u6e10\u589e\u5f3a\u3002\u5f53\u52a0\u4e0a\u65f6\u95f4\u6982\u5ff5\u5bf9\u52a0\u566a\u8fc7\u7a0b\u8fdb\u884c\u6570\u5b66\u63cf\u8ff0\u65f6\uff0c\u516c\u5f0f\u5982\u4e0b\uff1a<\/p>\n<p>$$<br \/>\nq\\left(x_{1: T} \\mid x_0\\right)=\\prod_{t \\geq 0} q\\left(x_t \\mid x_{t-1}\\right), \\quad q\\left(x_t \\mid x_{t-1}\\right)=N\\left(x_t ; \\sqrt{1-\\beta_t} x_{t-1}, \\beta_t I\\right)<br \/>\n$$<\/p>\n<p>\u89e3\u91ca\u4e00\u4e0b\u4e0a\u8ff0\u516c\u5f0f, \u6211\u4eec\u8003\u8651\u4e00\u4e2a\u968f\u65f6\u95f4\u53d8\u5316\u7684\u6570\u636e\u5e8f\u5217 $x_0, x_1, \\ldots, x_T$, \u5176\u4e2d $x_0$ \u662f\u539f\u59cb\u6570\u636e,  $x_{1: T}$ \u662f\u5728\u4e00\u7cfb\u5217\u566a\u58f0\u6269\u6563\u8fc7\u7a0b\u540e\u5f97\u5230\u7684\u6570\u636e\u3002<\/p>\n<ul>\n<li>\n<p>\u5bf9\u4e8e\u4efb\u610f\u7684 $t, q\\left(x_t \\mid x_{t-1}\\right)$ \u8868\u793a\u5728\u7ed9\u5b9a $x_{t-1}$\u7684\u60c5\u51b5\u4e0b$x_t$ \u7684\u6761\u4ef6\u6982\u7387\u5206\u5e03\u3002<\/p>\n<\/li>\n<li>\n<p>\u5728\u8fd9\u91cc, \u8fd9\u4e2a\u5206\u5e03\u88ab\u5b9a\u4e49\u4e3a\u4e00\u4e2a\u9ad8\u65af\u5206\u5e03, \u5176\u5747\u503c\u662f $1-\\beta_t x_{t-1}$,\u65b9\u5dee\u662f $\\beta_t I$ \u3002\u5176\u4e2d $I$ \u662f\u5355\u4f4d\u77e9\u9635, \u8868\u793a\u7684\u662f\u6bcf\u4e2a\u7ef4\u5ea6\u4e0a\u7684\u566a\u58f0\u662f\u72ec\u7acb\u7684\u3002\u8fd9\u4e2a\u9ad8\u65af\u5206\u5e03\u5c31\u4ee3\u8868\u4e86\u5728\u65f6\u95f4 $t$ \u6240\u6ce8\u5165\u7684\u566a\u58f0\u3002<\/p>\n<\/li>\n<li>\n<p>$N\\left(x_t ; \\sqrt{1-\\beta_t} x_{t-1}, \\beta_t I\\right)$ \u8868\u793a\u5f53\u524d\u6b65\u9aa4\u7684\u56fe\u50cf\u72b6\u6001 $x_t$ \u662f\u4ece\u4e00\u4e2a\u4ee5 $\\sqrt{1-\\beta_t} x_{t-1}$ \u4e3a\u5747\u503c\u3001 $\\beta_t I$  \u4e3a\u65b9\u5dee\u7684\u6b63\u6001\u5206\u5e03\u4e2d\u91c7\u6837\u5f97\u5230\u7684\u3002\u8fd9\u91cc, $\\beta_t$ \u662f\u4e00\u4e2a\u9884\u5148\u5b9a\u4e49\u7684\u566a\u58f0\u7ea7\u522b\u53c2\u6570, \u7528\u4e8e\u63a7\u5236\u6bcf\u4e00\u6b65\u6dfb\u52a0\u7684\u566a\u58f0\u91cf\u3002<\/p>\n<\/li>\n<li>\n<p>\u5176\u4e2d, $\\beta_t$ \u662f\u4e00\u4e2a\u4ecb\u4e8e 0 \u548c 1 \u4e4b\u95f4\u7684\u53c2\u6570, \u63a7\u5236\u4e86\u566a\u58f0\u6ce8\u5165\u7684\u5f3a\u5ea6\u3002\u5177\u4f53\u6765\u8bf4, $1-\\beta_t$ \u662f\u566a\u58f0\u6ce8\u5165\u524d\u7684\u6570\u636e\u6240\u5360\u6bd4\u91cd, \u800c$\\beta_t$ \u662f\u566a\u58f0\u7684\u65b9\u5dee\u3002<\/p>\n<\/li>\n<li>\n<p>\u56e0\u6b64, \u5f53$\\beta_t$ \u63a5\u8fd1 0 \u65f6, \u566a\u58f0\u7684\u5f71\u54cd\u8f83\u5c0f,  $x_t$ \u4e3b\u8981\u7531 $x_{t-1}$ \u51b3\u5b9a; \u5f53 $\\beta_t$ \u63a5\u8fd1 1 \u65f6, \u566a\u58f0\u7684\u5f71\u54cd\u8f83\u5927, $x_t$ \u66f4\u591a\u5730\u7531\u566a\u58f0\u51b3\u5b9a\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u5b9e\u9645\u4e0a\uff0c\u8fd9\u4e2a<strong>\u52a0\u566a\u7684\u8fc7\u7a0b\u5c31\u662f\u4e00\u4e2a\u9a6c\u5c14\u53ef\u592b\u94fe\u7b97\u6cd5<\/strong>\uff0c\u5728\u9a6c\u5c14\u53ef\u592b\u94fe\u4e2d\uff0c\u4e00\u4e2a\u72b6\u6001\u7684\u4e0b\u4e00\u72b6\u6001\u53ea\u4f9d\u8d56\u4e8e\u5f53\u524d\u72b6\u6001\uff0c\u800c\u4e0e\u8fc7\u53bb\u7684\u72b6\u6001\u65e0\u5173\uff0c\u8fd9\u5c31\u662f\u6240\u8c13\u7684\u201c\u65e0\u8bb0\u5fc6\u6027\u201d\u3002<\/p>\n<p>\u5bf9\u4e8e\u7ed9\u5b9a\u7684\u516c\u5f0f\uff1a<br \/>\n$$<br \/>\nq\\left(x_{1: T} \\mid x_0\\right)=\\prod_{t \\geq 0} q\\left(x_t \\mid x_{t-1}\\right)<br \/>\n$$<br \/>\n\u5176\u4e2d, $x_{t-1}$ \u662f\u524d\u4e00\u4e2a\u72b6\u6001, $x_t$ \u662f\u4e0b\u4e00\u4e2a\u72b6\u6001, \u516c\u5f0f\u8868\u660e\u4e0b\u4e00\u4e2a\u72b6\u6001 $x_t$ \u53ea\u4f9d\u8d56\u4e8e\u524d\u4e00\u4e2a\u72b6\u6001 $x_{t-1}$ \u3002\u6240\u4ee5, \u6574\u4e2a\u5e8f\u5217  $x_0, x_1, \\ldots, x_T$  \u5b9e\u9645\u4e0a\u6784\u6210\u4e86\u4e00\u4e2a\u9a6c\u5c14\u53ef\u592b\u94fe\u3002<\/p>\n<p>\u6b64\u5916,<br \/>\n$$<br \/>\nq\\left(x_t \\mid x_{t-1}\\right)=N\\left(x_t ; \\sqrt{1-\\beta_t} x_{t-1}, \\beta_t I\\right)<br \/>\n$$<\/p>\n<p>\u516c\u5f0f\u8868\u793a\u4e86\u5728\u7ed9\u5b9a\u524d\u4e00\u4e2a\u72b6\u6001 $x_{t-1}$ \u7684\u60c5\u51b5\u4e0b, \u4e0b\u4e00\u4e2a\u72b6\u6001 $x_t$ \u7684\u6982\u7387\u5206\u5e03\u3002\u8fd9\u5b9e\u9645\u4e0a\u662f\u9a6c\u5c14\u53ef\u592b\u94fe\u4e2d\u7684\u72b6\u6001\u8f6c\u79fb\u6982\u7387\u3002<\/p>\n<p>\u6240\u4ee5\uff0c\u4ece\u8fd9\u4e2a\u89d2\u5ea6\u770b\uff0c\u8fd9\u4e2a\u516c\u5f0f\u5b9e\u9645\u4e0a\u63cf\u8ff0\u4e86\u4e00\u4e2a\u9a6c\u5c14\u53ef\u592b\u94fe\uff0c\u5e76\u4e14\u8fd9\u4e2a\u9a6c\u5c14\u53ef\u592b\u94fe\u7684\u72b6\u6001\u8f6c\u79fb\u6982\u7387\u662f\u9ad8\u65af\u5206\u5e03\u3002\u8fd9\u6837\u7684\u9a6c\u5c14\u53ef\u592b\u94fe\u4e5f\u88ab\u79f0\u4e3a\u9ad8\u65af\u9a6c\u5c14\u53ef\u592b\u94fe\u3002<\/p>\n<p>\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u6211\u4eec\u6bcf\u6b21\u8fdb\u884c\u566a\u58f0\u52a0\u5165\u7684\u65f6\u5019\u90fd\u662f\u5f88\u6709\u89c4\u77e9\u7684\u52a0\u5165\u4e00\u5b9a\u7684\u9ad8\u65af\u566a\u58f0\uff0c\u90a3\u6211\u4eec\u662f\u5426\u53ef\u4ee5\u6253\u7834\u8fd9\u79cd\u5faa\u89c4\u8e48\u77e9\uff0c\u4e0d\u7528\u591a\u6b21\u7684\u52a0\u5165\u800c\u662f<strong>\u4e00\u6b65\u5230\u4f4d<\/strong>\u5462\uff1f<\/p>\n<p><strong>\u524d\u5411\u52a0\u566a\u8fc7\u7a0b\u7684\u7b80\u5316<\/strong><\/p>\n<hr \/>\n<p>\u5728\u539f\u8bba\u6587\u5df2\u7ecf\u7ed9\u51fa\u4e86\u76f8\u5173\u7684\u63a8\u5bfc, \u8bba\u6587\u4e2d\u7ed9\u5230\u7684\u516c\u5f0f\u662f$x_t=\\sqrt{\\bar{\\alpha}_t} x_0+\\sqrt{1-\\bar{\\alpha}_t} \\epsilon$, \u8fd9\u4e2a\u516c\u5f0f\u4e0e\u4e0a\u6587\u63a8\u5bfc\u7684\u516c\u5f0f $q\\left(x_t \\mid x_{t-1}\\right)=N\\left(x_t ; \\sqrt{1-\\beta_t} x_{t-1}, \\beta_t I\\right)$ \u6700\u5927\u7684\u4e0d\u4e00\u6837\u5728\u4e8e  $x_t$ \u7684\u751f\u6210\u4e0d\u4f9d\u8d56\u4e8e $x_{t-1}$, \u800c\u662f\u6839\u636e\u521d\u59cb\u56fe\u7247 $x_0$ \u548c\u6269\u6563\u6b21\u6570 $t$ \u5373\u53ef\u751f\u6210, <\/p>\n<p>\u6362\u53e5\u8bdd\u8bf4, \u539f\u8bba\u6587\u4e2d\u7ed9\u51fa\u7684\u516c\u5f0f\u5141\u8bb8\u4e00\u6b65\u5230\u4f4d\u751f\u6210\u566a\u58f0\u56fe\u7247, \u800c\u4e0d\u9700\u8981\u591a\u6b21\u7684\u8fed\u4ee3\u53e0\u52a0\u566a\u58f0, \u8fd9\u5927\u5927\u7684\u7b80\u5316\u7684\u751f\u6210\u566a\u58f0\u56fe\u7247\u7684\u6d41\u7a0b\u3002<\/p>\n<p>\u8fd9\u4e2a\u516c\u5f0f\u7684\u63a8\u5bfc\u8981\u4f9d\u8d56\u4e8e\u91cd\u53c2\u6570\u5316\u6280\u5de7, \u4e0b\u9762\u8fdb\u884c\u8be6\u7ec6\u7684\u6570\u5b66\u63a8\u5bfc\u3002<\/p>\n<p>\u91cd\u53c2\u6570\u5316\u662f\u4e00\u79cd\u7528\u4e8e\u8bad\u7ec3\u6df1\u5ea6\u6982\u7387\u6a21\u578b\u7684\u7b56\u7565, \u5728\u53d8\u5206\u81ea\u7f16\u7801\u5668 (VAE) \u548c\u6269\u6563\u6a21\u578b\u4e2d\u7ecf\u5e38\u4f7f\u7528\u3002\u8003\u8651\u4e00\u4e2a\u57fa\u672c\u7684\u566a\u58f0\u6ce8\u5165\u8fc7\u7a0b: \u6211\u4eec\u6709\u4e00\u4e2a\u6570\u636e\u70b9 $x$, \u6211\u4eec\u60f3\u8981\u5411\u5176\u6ce8\u5165\u670d\u4ece\u9ad8\u65af\u5206\u5e03 $N\\left(0, \\sigma^2\\right)$ \u7684\u566a\u58f0\u3002\u5982\u679c\u6211\u4eec\u76f4\u63a5\u4ece\u8fd9\u4e2a\u5206\u5e03\u4e2d\u91c7\u6837\u566a\u58f0 $\\varepsilon$, \u5e76\u5c06\u5176\u52a0\u5230 $x$ \u4e0a, \u90a3\u4e48\u8fd9\u4e2a\u8fc7\u7a0b\u5c31\u6d89\u53ca\u5230\u968f\u673a\u6027, \u65e0\u6cd5\u76f4\u63a5\u8fdb\u884c\u53cd\u5411\u4f20\u64ad\u3002<\/p>\n<p>\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898, \u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u91cd\u53c2\u6570\u5316\u6280\u5de7\u3002\u5177\u4f53\u6765\u8bf4, \u6211\u4eec\u4e0d\u662f\u76f4\u63a5\u4ece $N\\left(0, \\sigma^2\\right)$\u4e2d\u91c7\u6837\u566a\u58f0, \u800c\u662f\u5148\u4ece\u6807\u51c6\u6b63\u6001\u5206\u5e03 $N(0, I)$ \u4e2d\u91c7\u6837, \u7136\u540e\u518d\u901a\u8fc7\u9002\u5f53\u7684\u53d8\u6362\u5f97\u5230\u6211\u4eec\u60f3\u8981\u7684\u566a\u58f0\u3002\u8fd9\u6837, \u8fd9\u4e2a\u566a\u58f0\u6ce8\u5165\u8fc7\u7a0b\u5c31\u53ef\u4ee5\u5206\u89e3\u4e3a\u4e24\u6b65:<\/p>\n<p>(1) \u4ece\u6807\u51c6\u6b63\u6001\u5206\u5e03 $N(0, I)$ \u4e2d\u91c7\u6837\u566a\u58f0 $\\boldsymbol{\\varepsilon}$ \u3002<\/p>\n<p>(2) \u5c06\u566a\u58f0 $\\boldsymbol{\\varepsilon}$ \u8fdb\u884c\u53d8\u6362, \u5f97\u5230\u6211\u4eec\u60f3\u8981\u7684\u566a\u58f0 $\\varepsilon=\\sigma \\varepsilon^2$ \u3002<\/p>\n<p>\u7136\u540e, \u6211\u4eec\u5c31\u53ef\u4ee5\u5c06\u8fd9\u4e2a\u566a\u58f0 $\\varepsilon$ \u52a0\u5230\u6570\u636e\u70b9 $x$ \u4e0a, \u5f97\u5230\u65b0\u7684\u6570\u636e\u70b9 $x^{\\prime}=x+\\varepsilon$ \u3002<\/p>\n<p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f, \u6211\u4eec\u5c31\u5c06\u566a\u58f0\u6ce8\u5165\u8fc7\u7a0b\u4e2d\u7684\u968f\u673a\u6027\u79fb\u5230\u4e86\u7b2c\u4e00\u6b65, \u8fd9\u4e00\u6b65\u662f\u53ef\u4ee5\u8fdb\u884c\u53cd\u5411\u4f20\u64ad\u7684\u3002\u56e0\u4e3a\u6807\u51c6\u6b63\u6001\u5206\u5e03 $N(0, I)$ \u662f\u56fa\u5b9a\u7684, \u4e0d\u6d89\u53ca\u5230\u6a21\u578b\u7684\u53c2\u6570, \u6240\u4ee5\u4ece\u4e2d\u91c7\u6837\u7684\u8fc7\u7a0b\u662f\u53ef\u4ee5\u8fdb\u884c\u53cd\u5411\u4f20\u64ad\u7684\u3002<\/p>\n<p>\u7136\u540e, \u7b2c\u4e8c\u6b65\u4e2d\u7684\u53d8\u6362\u4e5f\u662f\u53ef\u4ee5\u8fdb\u884c\u53cd\u5411\u4f20\u64ad\u7684, \u56e0\u4e3a\u8fd9\u4e2a\u53d8\u6362\u53ea\u6d89\u53ca\u5230\u4e58\u6cd5\u548c\u52a0\u6cd5, \u8fd9\u4e24\u79cd\u64cd\u4f5c\u90fd\u662f\u53ef\u5bfc\u7684\u3002\u8fd9\u6837, \u6574\u4e2a\u566a\u58f0\u6ce8\u5165\u8fc7\u7a0b\u5c31\u53ef\u4ee5\u8fdb\u884c\u53cd\u5411\u4f20\u64ad, \u53ef\u4ee5\u88ab\u4f18\u5316\u3002\u8fd9\u5c31\u662f\u91cd\u53c2\u6570\u5316\u6280\u5de7\u3002<\/p>\n<p><strong>\u4e3a\u4ec0\u4e48\u566a\u58f0\u4e3a\u4ec0\u4e48\u4e0d\u76f4\u63a5\u4ece\u6807\u51c6\u6b63\u6001\u5206\u5e03\u4e2d\u91c7\u6837\uff1f\u8fd8\u8981\u7ecf\u8fc7\u53d8\u6362\uff1f<\/strong><\/p>\n<p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6211\u4eec\u901a\u5e38\u9700\u8981\u4ece<strong>\u4e0d\u540c\u5c3a\u5ea6<\/strong>\u7684\u6b63\u6001\u5206\u5e03\u4e2d\u91c7\u6837\u566a\u58f0\uff08\u5373\u5177\u6709\u4e0d\u540c\u65b9\u5dee\u7684\u5206\u5e03\uff09\u3002\u901a\u8fc7\u53d8\u6362\u6807\u51c6\u6b63\u6001\u5206\u5e03\u7684\u566a\u58f0\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u5730\u751f\u6210\u7b26\u5408\u4e0d\u540c\u5c3a\u5ea6\u7684\u566a\u58f0\uff0c\u800c\u4e0d\u9700\u8981\u76f4\u63a5\u91c7\u6837\u4e0d\u540c\u7684\u6b63\u6001\u5206\u5e03\u3002<\/p>\n<p>\u5728\u6269\u6563\u6a21\u578b\u4e2d, \u8fd9\u79cd\u6280\u5de7\u4e5f\u88ab\u5e7f\u6cdb\u4f7f\u7528\u3002<\/p>\n<ul>\n<li>\u6211\u4eec\u53ef\u4ee5\u5148\u4ece\u6807\u51c6\u6b63\u6001\u5206\u5e03 $N(0, I)$ \u4e2d\u91c7\u6837\u566a\u58f0 $\\varepsilon$, \u7136\u540e\u5c06\u8fd9\u4e2a\u566a\u58f0\u901a\u8fc7\u53d8\u6362 $\\varepsilon=\\beta_t \\varepsilon^{\\prime}$,\u5f97\u5230\u6211\u4eec\u60f3\u8981\u7684\u566a\u58f0\u3002<\/li>\n<li>\u7136\u540e\u518d\u5c06\u8fd9\u4e2a\u566a\u58f0\u52a0\u5230 $x_{t-1}$ \u4e0a, \u5f97\u5230\u65b0\u7684\u6570\u636e\u70b9:<br \/>\n$$<br \/>\nx_t=\\sqrt{1-\\beta_t} x_{t-1}+\\sqrt{\\beta_t} \\varepsilon_{t-1}<br \/>\n$$<\/li>\n<\/ul>\n<p>\u5728\u4e0a\u8ff0\u516c\u5f0f\u4e2d:<\/p>\n<ul>\n<li>$x_t$ \u662f\u5728\u65f6\u95f4\u6b65 $t$ \u7684\u72b6\u6001; $\\beta_t$\u662f\u4e00\u4e2a\u4ecb\u4e8e 0 \u548c 1 \u4e4b\u95f4\u7684\u53c2\u6570, \u63a7\u5236\u7740\u524d\u4e00\u4e2a\u72b6\u6001 $x_{t-1}$ \u548c\u65b0\u5f15\u5165\u7684\u566a\u58f0 $\\varepsilon_{t-1}$\u5bf9\u5f53\u524d\u72b6\u6001 $x_t$ \u7684\u8d21\u732e\u3002<\/li>\n<li>$\\varepsilon_t$ \u662f\u566a\u58f0\u9879, \u901a\u5e38\u5047\u5b9a\u670d\u4ece\u6807\u51c6\u6b63\u6001\u5206\u5e03, \u8868\u793a\u5728\u65f6\u95f4 $t$ \u5f15\u5165\u7684\u968f\u673a\u566a\u58f0\u3002<\/li>\n<li>\u5728\u5b9e\u8df5\u4e2d, $\\beta_t$ \u901a\u5e38\u662f\u9884\u5148\u5b9a\u4e49\u7684, \u53ef\u4ee5\u6839\u636e\u7279\u5b9a\u7684\u6269\u6563\u8fc7\u7a0b\u8fdb\u884c\u8bbe\u5b9a\u3002<\/li>\n<\/ul>\n<p><strong>\u7ee7\u7eed\u63a8\u5bfc\u4e0b\u53bb<\/strong><\/p>\n<ul>\n<li>\u4ee4 $\\alpha_t=1-\\beta_t, \\bar{\\alpha}_i=\\prod_{s=0}^t \\alpha_s, \\epsilon_0, \\epsilon_1, \\ldots, \\epsilon_{t-2}, \\epsilon_{t-1} \\sim \\mathcal{N}(0, I)$<\/li>\n<li>\u5bf9\u4e8e $x_t$,\u6211\u4eec\u53ef\u4ee5\u5c06\u5176\u5199\u4e3a: $x_t=\\sqrt{\\alpha_i} x_{t-1}+\\sqrt{1-\\alpha_t} \\epsilon_{t-1}$<\/li>\n<li>\u7136\u540e, \u6211\u4eec\u5c06 $x_{t-1}$ \u8fdb\u4e00\u6b65\u5c55\u5f00:<br \/>\n$$<br \/>\nx_{t-1}=\\sqrt{\\alpha_{t-1}} x_{t-2}+\\sqrt{1-\\alpha_{t-1}} \\epsilon_{t-2}<br \/>\n$$<\/li>\n<\/ul>\n<p>\u73b0\u5728, \u6211\u4eec\u5c06\u8fd9\u4e2a\u8868\u8fbe\u5f0f\u4ee3\u5165\u5230 $x_t$ \u7684\u516c\u5f0f\u4e2d:<br \/>\n$$<br \/>\nx_t=\\sqrt{\\alpha_t}\\left(\\sqrt{\\alpha_{t-1}} x_{t-2}+\\sqrt{1-\\alpha_{t-1}} \\epsilon_{t-1}\\right)+\\sqrt{1-\\alpha_t} \\epsilon_{t-1}<br \/>\n$$<\/p>\n<p>\u53ef\u4ee5\u6574\u7406\u4e3a:<br \/>\n$$<br \/>\nx_t=\\sqrt{\\alpha_t \\alpha_{t-1}} x_{t-2}+\\sqrt{\\alpha_t\\left(1-\\alpha_{t-1}\\right)} \\epsilon_{t-2}+\\sqrt{1-\\alpha_t} \\epsilon_{t-1} .<br \/>\n$$<br \/>\n\u7531\u4e8e $\\epsilon_{t-2}$ \u548c $\\epsilon_{t-1}$  \u90fd\u662f\u72ec\u7acb\u7684\u9ad8\u65af\u968f\u673a\u53d8\u91cf, \u6211\u4eec\u53ef\u4ee5\u5c06\u8fd9\u4e24\u9879\u5408\u5e76, \u5f97\u5230:<br \/>\n$$<br \/>\n\\begin{aligned}<br \/>\n&amp; \\sqrt{\\alpha_t \\alpha_{t-1}} x_{t-2}+\\sqrt{\\alpha_t\\left(1-\\alpha_{t-1}\\right)} \\epsilon+\\sqrt{1-\\alpha_t} \\epsilon \\\\<br \/>\n&amp; =\\sqrt{\\alpha_t \\alpha_{t-1}} x_{t-2}+\\mathcal{N}\\left(0, \\alpha_t\\left(1-\\alpha_{t-1}\\right)\\right)+\\mathcal{N}\\left(0,1-\\alpha_t\\right) \\\\<br \/>\n&amp; =\\sqrt{\\alpha_t \\alpha_{t-1}} x_{t-2}+\\mathcal{N}\\left(0,1-\\alpha_t \\alpha_{t-1}\\right) \\\\<br \/>\n&amp; =\\sqrt{\\alpha_t \\alpha_{t-1}} x_{t-2}+\\sqrt{1-\\alpha_t \\alpha_{t-1}} \\epsilon^{\\prime}<br \/>\n\\end{aligned}<br \/>\n$$<br \/>\n\u5176\u4e2d $\\epsilon^{\\prime}$ \u662f\u65b0\u7684\u968f\u673a\u566a\u58f0, \u5176\u5206\u5e03\u4e3a $\\mathcal{N}(0, I)$ \u3002\u7136\u540e, \u6211\u4eec\u53ef\u4ee5\u7ee7\u7eed\u8fd9\u4e2a\u8fc7\u7a0b, \u5c06 $x_{t-2}$ \u7ee7\u7eed\u5c55\u5f00,\u76f4\u5230 $x_0$ \u3002\u6700\u540e\u6211\u4eec\u4f1a\u5f97\u5230:<br \/>\n$$<br \/>\nx_t=\\sqrt{\\bar{\\alpha}_t} x_0+\\sqrt{1-\\bar{\\alpha}_t} \\epsilon^{\\prime \\prime}<br \/>\n$$<\/p>\n<p>\u5176\u4e2d $\\epsilon^{\\prime \\prime}$ \u4e5f\u662f\u968f\u673a\u566a\u58f0, \u5206\u5e03\u4e3a $\\mathcal{N}(0, I)$ \u3002<br \/>\n\u6700\u540e, \u7531\u4e8e $x_t$ \u662f $x_0$ \u548c\u968f\u673a\u566a\u58f0 $\\epsilon^{\\prime \\prime}$ \u7684\u7ebf\u6027\u7ec4\u5408, \u56e0\u6b64 $x_t$ \u7684\u5206\u5e03\u4e3a\u6b63\u6001\u5206\u5e03<br \/>\n$$<br \/>\nN\\left(\\sqrt{\\alpha_t} x_0,\\left(1-\\bar{\\alpha}_t\\right) I\\right)<br \/>\n$$<\/p>\n<p><strong>\u901a\u8fc7\u8fd9\u79cd\u65b9\u6cd5\uff0c\u53ef\u4ee5\u76f4\u63a5\u8ba1\u7b97\u51fa\u4efb\u610f\u65f6\u95f4\u70b9\u7684\u566a\u58f0\u56fe\u50cf\uff0c\u800c\u65e0\u9700\u9010\u6b65\u901a\u8fc7\u6bcf\u4e2a\u566a\u58f0\u7ea7\u522b\u3002\u8fd9\u5728\u7406\u8bba\u4e0a\u7b80\u5316\u4e86\u52a0\u566a\u8fc7\u7a0b\uff0c\u5e76\u4f7f\u5f97\u5728\u751f\u6210\u548c\u5904\u7406\u6570\u636e\u65f6\u66f4\u52a0\u9ad8\u6548\u3002<\/strong><\/p>\n<h3><img decoding=\"async\" src=\"https:\/\/img.icons8.com\/?size=100&id=48250&format=png&color=000000\" style=\"height:50px;display:inline\"> \u524d\u5411\u6269\u6563\u4ee3\u7801\u793a\u4f8b<\/h3>\n<p>DDPM \u524d\u5411\u8fc7\u7a0b\u5982\u4e0b:<br \/>\n$$<br \/>\nq_\\sigma\\left(\\mathbf{x}_t \\mid \\mathbf{x}_0\\right)=\\sqrt{\\bar{\\alpha}_t} \\mathbf{x}_0+\\sqrt{1-\\bar{\\alpha}_t \\epsilon}<br \/>\n$$<\/p>\n<p>\u5f0f\u4e2d\uff0c $\\bar{\\alpha}_t=\\prod_{i=1}^T\\left(1-\\beta_i\\right) \uff0c \\bar{\\alpha}_t$ \u8ba1\u7b97\u65b9\u6cd5\u5982\u4e0b:<\/p>\n<pre><code class=\"language-python\">import torch\nimport numpy as np\n%matplotlib inline\nimport matplotlib.pyplot as plt\nimport os\nos.environ[&quot;KMP_DUPLICATE_LIB_OK&quot;]=&quot;TRUE&quot;\n\n# \u751f\u6210beta\u53c2\u6570\u7684\u8c03\u5ea6\u8868\n# schedule: \u8c03\u5ea6\u7c7b\u578b\uff08&#039;linear&#039;, &#039;quad&#039;, &#039;sigmoid&#039;\uff09\n# n_timesteps: \u603b\u7684\u65f6\u95f4\u6b65\u6570\n# start: beta\u7684\u8d77\u59cb\u503c\n# end: beta\u7684\u7ed3\u675f\u503c\ndef make_beta_schedule(schedule=&#039;linear&#039;, n_timesteps=1000, start=1e-5, end=1e-2):\n    if schedule == &#039;linear&#039;:\n        betas = torch.linspace(start, end, n_timesteps)\n    elif schedule == &quot;quad&quot;:\n        betas = torch.linspace(start ** 0.5, end ** 0.5, n_timesteps) ** 2\n    elif schedule == &quot;sigmoid&quot;:\n        betas = torch.linspace(-6, 6, n_timesteps)\n        betas = torch.sigmoid(betas) * (end - start) + start\n    return betas\n\n# \u7ed8\u5236\u4e0d\u540c\u8c03\u5ea6\u7c7b\u578b\u7684beta\u53c2\u6570\u548c\u76f8\u5173\u53c2\u6570\u968f\u65f6\u95f4\u6b65\u7684\u53d8\u5316\u66f2\u7ebf\n# n_steps: \u603b\u7684\u65f6\u95f4\u6b65\u6570\n# schedule: \u8c03\u5ea6\u7c7b\u578b\ndef plot_schedule(n_steps,schedule):\n    plt.plot(list(range(n_steps)),betas.numpy(),label=&#039;betas&#039;)\n    plt.plot(list(range(n_steps)),torch.sqrt(alphas_prod).numpy(),label=&#039;sqrt_alphas_prod&#039;)\n    plt.plot(list(range(n_steps)),torch.sqrt(1-alphas_prod).numpy(),label=&#039;sqrt_one_minus_alphas_prod&#039;)\n    plt.legend([&#039;betas&#039;,&#039;sqrt_alphas_prod&#039;,&#039;sqrt_one_minus_alphas_prod&#039;],loc = &#039;upper left&#039;)\n    plt.xlabel(&#039;steps&#039;)\n    plt.ylabel(&#039;value&#039;)\n    plt.title(&#039;{} schedule&#039;.format(schedule))\n    plt.show()\n\n# \u8bbe\u7f6e\u65f6\u95f4\u6b65\u6570\nn_steps = 1000\n\n# \u7ebf\u6027\u8c03\u5ea6\nschedule = &#039;linear&#039;\nbetas = make_beta_schedule(schedule=schedule, n_timesteps=n_steps, start=1e-5, end=1e-1)\nalphas = 1 - betas\nalphas_prod = torch.cumprod(alphas, 0)\nplot_schedule(n_steps, schedule)\n\n# \u4e8c\u6b21\u65b9\u8c03\u5ea6\nschedule = &#039;quad&#039;\nbetas = make_beta_schedule(schedule=schedule, n_timesteps=n_steps, start=1e-5, end=1e-1)\nalphas = 1 - betas\nalphas_prod = torch.cumprod(alphas, 0)\nplot_schedule(n_steps, schedule)\n\n# Sigmoid\u8c03\u5ea6\nschedule = &#039;sigmoid&#039;\nbetas = make_beta_schedule(schedule=schedule, n_timesteps=n_steps, start=1e-5, end=1e-1)\nalphas = 1 - betas\nalphas_prod = torch.cumprod(alphas, 0)\nplot_schedule(n_steps, schedule)\n<\/code><\/pre>\n<p align=\"center\">\n  <img decoding=\"async\" src=\"https:\/\/gnnclub-1311496010.cos.ap-beijing.myqcloud.com\/wp-content\/uploads\/2024\/09\/20240923214623669.png\" style=\"height:400px\">\n<\/p>\n<p align=\"center\">\n  <img decoding=\"async\" src=\"https:\/\/gnnclub-1311496010.cos.ap-beijing.myqcloud.com\/wp-content\/uploads\/2024\/09\/20240923214647492.png\" style=\"height:400px\">\n<\/p>\n<p align=\"center\">\n  <img decoding=\"async\" src=\"https:\/\/gnnclub-1311496010.cos.ap-beijing.myqcloud.com\/wp-content\/uploads\/2024\/09\/20240923214707408.png\" style=\"height:400px\">\n<\/p>\n<ol>\n<li>Beta\u8c03\u5ea6\u8868 (betas)\uff1a\u5728\u4e0d\u540c\u7684\u65f6\u95f4\u6b65 (steps) \u4e0a, \u751f\u6210\u4e0d\u540c\u7c7b\u578b\u7684beta\u503c, \u8fd9\u4e9bbeta\u503c\u7528\u4e8e\u63a7\u5236\u566a\u58f0\u7684\u6ce8\u5165\u91cf\u3002<br \/>\n2.$\\sqrt{\\alpha_{\\text {prod }}}$  : \u8868\u793a\u7d2f\u79ef\u7684alpha\u503c\u7684\u5e73\u65b9\u6839\uff0c\u8fd9\u53cd\u6620\u4e86\u56fe\u50cf\u5728\u6bcf\u4e2a\u65f6\u95f4\u6b65\u7684\u4fdd\u7559\u90e8\u5206\u3002<\/li>\n<li>$\\sqrt{1-\\alpha_{\\text {prod }}}$ : \u8868\u793a\u7d2f\u79ef\u76841\u51cf\u53bbalpha\u503c\u7684\u5e73\u65b9\u6839\uff0c\u8fd9\u53cd\u6620\u4e86\u56fe\u50cf\u5728\u6bcf\u4e2a\u65f6\u95f4\u6b65\u6ce8\u5165\u7684\u566a\u58f0\u90e8\u5206\u3002<\/li>\n<\/ol>\n<h2><img decoding=\"async\" src=\"https:\/\/img.icons8.com\/?size=100&id=4gGn3e2hrpRy&format=png&color=000000\" style=\"height:50px;display:inline\">  DDPM \u7684\u635f\u5931\u51fd\u6570<\/h2>\n<hr \/>\n<p>DDPM\u7684\u635f\u5931\u51fd\u6570\u5982\u4e0b\u622a\u56fe\u4e2d\u7684Algorithm 1 Training step5\u6240\u793a:<\/p>\n<p align=\"center\">\n  <img decoding=\"async\" src=\"https:\/\/gnnclub-1311496010.cos.ap-beijing.myqcloud.com\/wp-content\/uploads\/2024\/09\/20240923214752639.png\" style=\"height:200px\">\n<\/p>\n<p>\u8bad\u7ec3\u8fc7\u7a0b\u901a\u8fc7\u4e0d\u65ad\u91c7\u6837\u6570\u636e\u70b9\u548c\u65f6\u95f4\u6b65\u957f\uff0c\u7ed3\u5408\u566a\u58f0\u9884\u6d4b\u6a21\u578b\u8fdb\u884c\u68af\u5ea6\u66f4\u65b0\uff0c\u4ece\u800c\u4f18\u5316\u6a21\u578b\u53c2\u6570\u3002\u635f\u5931\u51fd\u6570\u7684\u76ee\u6807\u662f\u4f7f\u5f97\u6a21\u578b\u80fd\u591f\u51c6\u786e\u9884\u6d4b\u7ed9\u5b9a\u65f6\u95f4\u6b65\u957f\u4e0a\u7684\u566a\u58f0\u3002<\/p>\n<p>\u4ee3\u7801\u5b9e\u73b0\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python\">def noise_estimation_loss(model, x_0, n_steps):\n    # \u83b7\u53d6\u6279\u6b21\u5927\u5c0f\n    batch_size = x_0.shape[0]\n\n    # \u4e3a\u6bcf\u4e2a\u6837\u672c\u9009\u62e9\u4e00\u4e2a\u968f\u673a\u6b65\u9aa4\n    t = torch.randint(0, n_steps, size=(batch_size \/\/ 2 + 1,))\n    # \u751f\u6210\u5bf9\u79f0\u7684 t \u503c\uff0c\u5e76\u62fc\u63a5\u6210\u6279\u6b21\u5927\u5c0f\n    t = torch.cat([t, n_steps - t - 1], dim=0)[:batch_size].long()\n\n    # \u4ece alphas_bar_sqrt \u63d0\u53d6\u76f8\u5e94\u7684\u503c\u4f5c\u4e3a x0 \u7684\u4e58\u5b50\n    a = extract(alphas_bar_sqrt, t, x_0)\n\n    # \u4ece one_minus_alphas_bar_sqrt \u63d0\u53d6\u76f8\u5e94\u7684\u503c\u4f5c\u4e3a eps \u7684\u4e58\u5b50\n    am1 = extract(one_minus_alphas_bar_sqrt, t, x_0)\n    # \u751f\u6210\u4e0e x0 \u5f62\u72b6\u76f8\u540c\u7684\u6807\u51c6\u6b63\u6001\u5206\u5e03\u566a\u58f0\n    e = torch.randn_like(x_0)\n\n    # \u8ba1\u7b97\u6a21\u578b\u8f93\u5165\n    x = x_0 * a + e * am1\n    # \u83b7\u53d6\u6a21\u578b\u8f93\u51fa\n    output = model(x, t)\n\n    # \u8fd4\u56de\u566a\u58f0\u4f30\u8ba1\u7684\u635f\u5931\u503c\n    return (e - output).square().mean()<\/code><\/pre>\n<h2><img decoding=\"async\" src=\"https:\/\/img.icons8.com\/?size=100&id=71043&format=png&color=000000\" style=\"height:50px;display:inline\"> DDPM \u53cd\u5411\u53bb\u566a<\/h2>\n<hr \/>\n<ul>\n<li>\u5f53\u6a21\u578b\u6309\u7167Algorithm 1\u7684\u4f2a\u4ee3\u7801\u8bad\u7ec3\u5b8c\u6bd5\u4e4b\u540e \uff0c\u5373\u53ef\u4f7f\u7528\u8bad\u7ec3\u597d\u7684\u6a21\u578b\u6765\u8fdb\u884c\u65b0\u56fe\u50cf\u7684\u751f\u6210\u3002<\/li>\n<li>\u65b0\u56fe\u50cf\u7684\u751f\u6210\u662f\u4e00\u4e2a\u53cd\u5411\u53bb\u566a\u7684\u8fc7\u7a0b\uff0c\u8be6\u89c1<strong>Algorithm 2<\/strong> Sampling<\/li>\n<\/ul>\n<p align=\"center\">\n  <img decoding=\"async\" src=\"https:\/\/gnnclub-1311496010.cos.ap-beijing.myqcloud.com\/wp-content\/uploads\/2024\/09\/20240923214911460.png\" style=\"height:300px\">\n<\/p>\n<ul>\n<li>\n<p>\u6b65\u9aa41: \u4ece\u6807\u51c6\u6b63\u6001\u5206\u5e03 $\\mathcal{N}(0, I)$ \u4e2d\u62bd\u53d6\u521d\u59cb\u566a\u58f0 $x_T$ \u3002<\/p>\n<\/li>\n<li>\n<p>\u6b65\u9aa42: \u9010\u6b65\u4ece $t=T$ \u5230 $t=1$ \u6267\u884c\u4ee5\u4e0b\u6b65\u9aa4\u3002<\/p>\n<\/li>\n<li>\n<p>\u6b65\u9aa43: \u5982\u679c $t&gt;1$ \uff0c\u4ece $\\mathcal{N}(0, I)$ \u4e2d\u62bd\u53d6\u566a\u58f0 $z$ \uff0c\u5426\u5219 $z=0$ \u3002<\/p>\n<\/li>\n<li>\n<p>\u6b65\u9aa44: \u4f7f\u7528\u4ee5\u4e0b\u516c\u5f0f\u53bb\u9664\u566a\u58f0\uff0c\u751f\u6210  $x_{t-1}$ :<br \/>\n$$<br \/>\nx_{t-1}=\\frac{1}{\\sqrt{\\alpha_t}}\\left(x_t-\\frac{1-\\alpha_t}{\\sqrt{1-\\bar{\\alpha}_t}} \\epsilon_\\theta\\left(x_t, t\\right)\\right)+\\sigma_t z<br \/>\n$$<\/p>\n<\/li>\n<li>\n<p>\u91cd\u70b9\u6765\u4e86\uff01\uff01\uff01\u8fd9\u4e2a\u516c\u5f0f\u548b\u6765\u7684\uff1f\uff1f\uff1f<\/p>\n<ul>\n<li>\u8fd9\u5c31\u8981\u8bdd\u8bf4\u4ece\u5934\uff0c\u4ece\u751f\u6210\u6a21\u578b\u7684\u603b\u7edf\u6846\u67b6\u5f00\u59cb\u63a8\u5bfc\u4e86...<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3><img decoding=\"async\" src=\"https:\/\/img.icons8.com\/?size=100&id=46498&format=png&color=000000\" style=\"height:50px;display:inline\"> \u751f\u6210\u6a21\u578b\u7684\u603b\u4f53\u6846\u67b6<\/h3>\n<hr \/>\n<p align=\"center\">\n  <img decoding=\"async\" src=\"https:\/\/gnnclub-1311496010.cos.ap-beijing.myqcloud.com\/wp-content\/uploads\/2024\/09\/20240923215150776.png\" style=\"height:400px\">\n<\/p>\n<ul>\n<li><strong>\u91c7\u6837<\/strong>: \u4ece\u771f\u5b9e\u6570\u636e\u5206\u5e03$P_{\\text {data }}(x)$ \u4e2d\u91c7\u6837$\\lbrace{x^1, x^2, \\ldots, x^m} \\rbrace$ \u3002<\/li>\n<li><strong>MLE\u76ee\u6807<\/strong>: \u627e\u5230\u4f7f\u89c2\u6d4b\u6570\u636e\u7684\u4f3c\u7136\u6700\u5927\u5316\u7684\u53c2\u6570 $\\theta^*$ :<br \/>\n$$<br \/>\n\\theta^*=\\arg \\max _\\theta \\prod_{i=1}^m P_\\theta\\left(x^i\\right)<br \/>\n$$<\/li>\n<\/ul>\n<p>\u4e3e\u4e2a\u62df\u5408\u82b1\u540d\u518c\u4f8b\u5b50\uff1a<\/p>\n<ul>\n<li>\n<p>\u771f\u5b9e\u82b1\u540d\u518c\uff1a\u5305\u542b\u73ed\u7ea7\u4e2d\u6240\u6709\u5b66\u751f\u7684\u540d\u5b57\uff0c\u6bcf\u4e2a\u540d\u5b57\u5728\u771f\u5b9e\u82b1\u540d\u518c\u4e2d\u53ea\u51fa\u73b0\u4e00\u6b21\u3002\u771f\u5b9e\u82b1\u540d\u518c\u662f\u56fa\u5b9a\u4e0d\u53d8\u7684\uff0c\u4ee3\u8868\u4e86\u771f\u5b9e\u7684\u6570\u636e\u5206\u5e03\u3002<\/p>\n<\/li>\n<li>\n<p>\u731c\u6d4b\u82b1\u540d\u518c\u7684\u4eba\u4ee3\u8868\u751f\u6210\u6a21\u578b\uff0c\u53c2\u6570\u5b9a\u4e49\u4e86\u8fd9\u4e2a\u4eba\u7684\u731c\u6d4b\u884c\u4e3a<\/p>\n<\/li>\n<li>\n<p>\u901a\u8fc7\u63a7\u5236\u53c2\u6570\uff0c\u8ba9\u8fd9\u4e2a\u4eba\u4e0d\u65ad\u8c03\u6574\u5176\u731c\u6d4b\u7684\u82b1\u540d\u518c\uff0c\u4f7f\u5176\u4e2d\u51fa\u73b0\u7684\u771f\u5b9e\u82b1\u540d\u518c\u7684\u540d\u5b57\u51fa\u73b0\u7684\u6982\u7387\u8d8a\u5927\u8d8a\u597d<\/p>\n<\/li>\n<li>\n<p>\u7406\u60f3\u60c5\u51b5\u4e0b\uff0c\u5982\u679c\u771f\u5b9e\u82b1\u540d\u518c\u4e2d\u7684\u540d\u5b57\u5728\u5176\u9884\u6d4b\u7684\u82b1\u540d\u518c\u4e2d\u51fa\u73b0\u7684\u6982\u7387\u90fd\u4e3a1\uff0c\u90a3\u610f\u5473\u7740\u9884\u6d4b\u7684\u82b1\u540d\u518c\u5206\u5e03\u5b8c\u5168\u62df\u5408\u4e86\u771f\u5b9e\u5206\u5e03\u3002<\/p>\n<ul>\n<li>\u5728\u5b9e\u9645\u4e2d\uff0c\u4e0d\u592a\u53ef\u80fd\u6bcf\u4e2a\u540d\u5b57\u7684\u51fa\u73b0\u6982\u7387\u90fd\u4e3a1\uff0c\u56e0\u4e3a\u8fd9\u662f\u4e00\u4e2a\u8fc7\u62df\u5408\u7684\u60c5\u51b5\u3002\u5982\u679c\u6a21\u578b\u5728\u8bad\u7ec3\u6570\u636e\u4e0a\u8868\u73b0\u5b8c\u7f8e\uff0c\u53ef\u80fd\u4f1a\u5728\u65b0\u6570\u636e\u4e0a\u8868\u73b0\u4e0d\u4f73\uff08\u5373\u6cdb\u5316\u80fd\u529b\u5dee\uff09\u3002<\/li>\n<li>\u6211\u4eec\u5e0c\u671b\u6a21\u578b\u751f\u6210\u7684\u540d\u5b57\u5206\u5e03\u63a5\u8fd1\u771f\u5b9e\u5206\u5e03\uff0c\u4f46\u4e0d\u4e00\u5b9a\u6bcf\u4e2a\u540d\u5b57\u7684\u6982\u7387\u90fd\u662f1\u3002\u6211\u4eec\u5e0c\u671b\u6a21\u578b\u80fd\u591f\u5728\u8bad\u7ec3\u548c\u6d4b\u8bd5\u6570\u636e\u4e0a\u90fd\u80fd\u8868\u73b0\u826f\u597d\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5bf9\u6570\u4f3c\u7136<\/strong>: \u4e3a\u4e86\u7b80\u5316\u4f18\u5316\uff0c\u5bf9\u4f3c\u7136\u53d6\u5bf9\u6570:<br \/>\n$$<br \/>\n\\theta^*=\\arg \\max _\\theta \\log \\prod_{i=1}^m P_\\theta\\left(x^i\\right)=\\arg \\max _\\theta \\sum_{i=1}^m \\log P_\\theta\\left(x^i\\right)<br \/>\n$$<\/p>\n<\/li>\n<li>\n<p><strong>\u671f\u671b<\/strong>: \u6839\u636e\u5927\u6570\u5b9a\u5f8b\uff0c\u5f53\u6837\u672c\u6570\u91cf\u8db3\u591f\u5927\u65f6\uff0c\u6837\u672c\u5747\u503c\u5c06\u63a5\u8fd1\u4e8e\u603b\u4f53\u5747\u503c\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u5bf9\u6570\u4f3c\u7136\u548c\u8fd1\u4f3c\u4e3a\u6570\u636e\u5206\u5e03\u4e0b\u7684\u671f\u671b\uff1a<br \/>\n$$<br \/>\n\\frac{1}{m} \\sum_{i=1}^m \\log P_\\theta\\left(x^i\\right) \\approx \\mathbb{E}_{x \\sim P_{\\text {data }}}\\left[\\log P_\\theta(x)\\right]<br \/>\n$$<\/p>\n<\/li>\n<li>\n<p>\u5c06\u4e0a\u5f0f\u4e2d\u7684 $m$ \u79fb\u5230\u53f3\u4fa7\uff0c\u5f97\u5230:<br \/>\n$$<br \/>\n\\sum_{i=1}^m \\log P_\\theta\\left(x^i\\right) \\approx m \\cdot \\mathbb{E}_{x \\sim P_{\\text {data }}}\\left[\\log P_\\theta(x)\\right]<br \/>\n$$<\/p>\n<\/li>\n<li>\n<p>\u56e0\u4e3a $m$ \u662f\u4e00\u4e2a\u5e38\u6570\uff0c\u6240\u4ee5\u5728\u6700\u5927\u5316 $\\sum_{i=1}^m \\log P_\\theta\\left(x^i\\right)$ \u65f6\uff0c\u4e0e\u6700\u5927\u5316 $\\mathbb{E}_{x \\sim P_{\\text {data }}}\\left[\\log P_\\theta(x)\\right]$  \u662f\u7b49\u4ef7\u7684\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u7ee7\u7eed\u63a8\u5bfc<\/strong><\/p>\n<\/li>\n<\/ul>\n<p>$$<br \/>\n\\begin{aligned}<br \/>\n&amp;  \\arg \\max _\\theta E_{x \\sim P_{\\text {data }}}\\left[\\log P_\\theta(x)\\right] \\\\<br \/>\n&amp; =\\arg \\max _\\theta \\int_x P_{d a t a}(x) \\log P_\\theta(x) d x-\\int_x P_{d a t a}(x) \\log P_{d a t a}(x) d x (\u8fd9\u4e00\u9879\u4e0e \\theta \u65e0\u5173)\\\\<br \/>\n&amp; =\\arg \\max _\\theta \\int_x P_{\\text {data }}(x) \\log \\frac{P_\\theta(x)}{P_{d a t a}(x)} d x \\\\<br \/>\n&amp; =\\arg \\min _\\theta K L\\left(P_{\\text {data }} | P_\\theta\\right)<br \/>\n\\end{aligned}<br \/>\n$$<\/p>\n<pre><code>Maximum Likelihood = Minimize KL Divergence<\/code><\/pre>\n<h3><strong>VAE\u7684\u6c42\u89e3\u8fc7\u7a0b<\/strong><\/h3>\n<p align=\"center\">\n  <img decoding=\"async\" src=\"https:\/\/gnnclub-1311496010.cos.ap-beijing.myqcloud.com\/wp-content\/uploads\/2024\/09\/20240923215833125.png\" style=\"height:400px\">\n<\/p>\n<ul>\n<li>\u7f51\u7edc\u7ed3\u6784: \u5c06\u6f5c\u5728\u53d8\u91cf $z$ \u901a\u8fc7\u795e\u7ecf\u7f51\u7edc\u751f\u6210\u6570\u636e $x$ \u3002<\/li>\n<li>\u751f\u6210\u6a21\u578b $P_\\theta(x)$ :<br \/>\n$$<br \/>\nP_\\theta(x)=\\int_z P(z) P_\\theta(x \\mid z) d z<br \/>\n$$<\/li>\n<\/ul>\n<p>\u5176\u4e2d $P(z)$ \u662f\u5148\u9a8c\u5206\u5e03\uff08\u901a\u5e38\u662f\u9ad8\u65af\u5206\u5e03\uff09\uff0c $P_\\theta(x \\mid z)$ \u662f\u6761\u4ef6\u5206\u5e03\u3002<\/p>\n<ul>\n<li>\u6761\u4ef6\u5206\u5e03 $P_\\theta(x \\mid z)$:<br \/>\n$$<br \/>\nP_\\theta(x \\mid z)= \\begin{cases}1, &amp; \\text { \u5982\u679c } G(z)=x \\\\ 0, &amp; \\text { \u5982\u679c } G(z) \\neq x\\end{cases}<br \/>\n$$<\/li>\n<\/ul>\n<p>\u8fd9\u91cc $G(z)$ \u662f\u901a\u8fc7\u795e\u7ecf\u7f51\u7edc\u751f\u6210\u7684\u6570\u636e $x$ \u3002\u8fd9\u79cd\u65b9\u6cd5\u7684\u95ee\u9898\u662f\uff0c  $P_\\theta(x \\mid z)$ \u53ef\u80fd\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\u90fd\u4e3a 0 \uff0c\u56e0\u6b64\u76f4\u63a5\u8ba1\u7b97 $P_\\theta(x)$ \u4f1a\u975e\u5e38\u56f0\u96be\u3002<\/p>\n<p>\u56e0\u6b64\uff0cVAE\u4f7f\u5f97$z$\u5bf9\u4e8e\u7684\u4e0d\u662f\u4e00\u4e2a\u6837\u672c\u70b9\uff0c\u800c\u662f\u4e00\u4e2a\u9ad8\u65af\u5206\u5e03\uff0c\u8be6\u89c1\u6559\u7a0b4\uff1aEncoder-Decoder<\/p>\n<p><strong>VAE\u7684\u53d8\u5206\u4e0b\u754c<\/strong><\/p>\n<ol>\n<li>\u76ee\u6807:\n<ul>\n<li>\u6211\u4eec\u5e0c\u671b\u8ba1\u7b97 $\\log P_\\theta(x)$ \uff0c\u5373\u89c2\u6d4b\u6570\u636e $x$ \u7684\u5bf9\u6570\u4f3c\u7136\u3002<\/li>\n<li>\u4f46\u662f\u5f88\u96be\u6c42\u89e3\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u5f15\u5165\u53d8\u5206\u5206\u5e03 $q(z)$ :\n<ul>\n<li>$q(z)$ \u53ef\u4ee5\u662f\u4efb\u610f\u5206\u5e03\uff0c\u7528\u6765\u8fd1\u4f3c\u540e\u9a8c\u5206\u5e03 $P(z \\mid x)$ \u3002<\/li>\n<li>\u4f7f\u7528 $q(z)$ \u91cd\u65b0\u8868\u8fbe $\\log P_\\theta(x)$ :<br \/>\n$$<br \/>\n\\log P_\\theta(x)=\\int q(z) \\log P_\\theta(x) d z<br \/>\n$$<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><strong>\u8be6\u89c1\u6559\u7a0b4\u4e2d\u7684\u6f5c\u53d8\u91cf\u6a21\u578b<\/strong><\/p>\n<ol start=\"3\">\n<li>\u5c06\u5bf9\u6570\u4f3c\u7136\u5206\u89e3<br \/>\n$$<br \/>\n\\log P_\\theta(x)=\\int q(z) \\log \\left(\\frac{P_\\theta(z, x)}{P_\\theta(z \\mid x)}\\right) d z<br \/>\n$$<\/li>\n<\/ol>\n<p>\u8fd9\u4e00\u6b65\u9aa4\u662f\u5c06\u5bf9\u6570\u4f3c\u7136 $\\log P_\\theta(x)$ \u91cd\u5199\u4e3a\u8054\u5408\u5206\u5e03 $P_\\theta(z, x)$ \u4e0e\u6761\u4ef6\u5206\u5e03 $P_\\theta(z \\mid x)$ \u7684\u6bd4\u7387\u3002\u8fd9\u662f\u57fa\u4e8e\u6982\u7387\u8bba\u4e2d\u7684\u4e58\u6cd5\u89c4\u5219 $P_\\theta(x)=\\frac{P_\\theta(z, x)}{P_\\theta(z \\mid x)}$\u3002<\/p>\n<ol start=\"4\">\n<li>\u518d\u6b21\u5f15\u5165\u53d8\u5206\u5206\u5e03:<br \/>\n$$<br \/>\n\\log P_\\theta(x)=\\int q(z) \\log \\left(\\frac{P_\\theta(z, x)}{q(z)} \\frac{q(z)}{P_\\theta(z \\mid x)}\\right) d z<br \/>\n$$<\/li>\n<\/ol>\n<p>\u8fd9\u91cc\uff0c\u6211\u4eec\u5728\u5206\u5b50\u5f0f\u7684\u5206\u5b50\u5206\u6bcd\u4e0a\u540c\u65f6\u5f15\u5165\u4e86\u53d8\u5206\u5206\u5e03 $q(z)$ \u5e76\u5c06\u5176\u4e0e\u6761\u4ef6\u5206\u5e03 $P_\\theta(z \\mid x)$  \u76f8\u6bd4\u8f83\u3002\u8be5\u6b65\u9aa4\u662f\u4e3a\u4e86\u521b\u5efa\u4e00\u4e2a\u9879\uff0c\u8be5\u9879\u540e\u7eed\u53ef\u4ee5\u8f6c\u5316\u4e3a KL\u6563\u5ea6\uff0c\u8fd9\u662f\u4e00\u4e2a\u8861\u91cf\u4e24\u4e2a\u6982\u7387\u5206\u5e03\u76f8\u4f3c\u5ea6\u7684\u5ea6\u91cf\u3002<\/p>\n<ol start=\"5\">\n<li>\n<p>\u5206\u89e3\u5bf9\u6570:<br \/>\n$$<br \/>\n\\log P_\\theta(x)=\\int q(z) \\log \\left(\\frac{P_\\theta(z, x)}{q(z)}\\right) d z+\\int q(z) \\log \\left(\\frac{q(z)}{P_\\theta(z \\mid x)}\\right) d z<br \/>\n$$<\/p>\n<\/li>\n<li>\n<p>\u5e94\u7528 Jensen \u4e0d\u7b49\u5f0f:<br \/>\n$$<br \/>\n\\log P_\\theta(x) \\geq \\int q(z) \\log \\left(\\frac{P_\\theta(z, x)}{q(z)}\\right) d z<br \/>\n$$<br \/>\n\u5728\u8fd9\u91cc\uff0c\u901a\u8fc7\u5e94\u7528 Jensen \u4e0d\u7b49\u5f0f\uff0c\u53ef\u4ee5\u63a8\u5bfc\u51fa KL \u6563\u5ea6\u662f\u975e\u8d1f\u7684\uff0c\u5373\u5927\u4e8e\u7b49\u4e8e 0 \uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u5220\u9664 $K L$ \u6563\u5ea6\u7684\u540c\u65f6\u5f97\u5230\u4e00\u4e2a\u5927\u4e8e\u7b49\u4e8e\u7684\u4e0d\u7b49\u5f0f\uff0c\u5373\u5bf9\u6570\u4f3c\u7136\u7684\u4e00\u4e2a\u4e0b\u754c\u3002<\/p>\n<\/li>\n<li>\n<p>\u53d8\u5206\u4e0b\u754c:<br \/>\n$$<br \/>\n\\log P_\\theta(x) \\geq \\mathrm{E}_{q(z)}\\left[\\log \\left(\\frac{P_\\theta(x, z)}{q(z)}\\right)\\right]<br \/>\n$$<\/p>\n<\/li>\n<\/ol>\n<p>\u6700\u7ec8\uff0c\u6211\u4eec\u5c06\u79ef\u5206\u91cd\u5199\u4e3a\u671f\u671b\u503c\u7684\u5f62\u5f0f\u3002<\/p>\n<h3><strong>DDPM\u7684\u6c42\u89e3\u8fc7\u7a0b<\/strong><\/h3>\n<p align=\"center\">\n  <img decoding=\"async\" src=\"https:\/\/gnnclub-1311496010.cos.ap-beijing.myqcloud.com\/wp-content\/uploads\/2024\/09\/20240923222048802.png\" style=\"height:400px\">\n<\/p>\n<ol>\n<li>\u76ee\u6807\n<ul>\n<li>\u6211\u4eec\u5e0c\u671b\u6700\u5927\u5316$\\log P_\\theta\\left(x_0\\right)$ \uff0c\u5373\u89c2\u6d4b\u6570\u636e $x_0$ \u7684\u5bf9\u6570\u4f3c\u7136\u3002<\/li>\n<li>\u76f4\u63a5\u6c42\u89e3 $\\log P_\\theta\\left(x_0\\right)$ \u5f88\u56f0\u96be\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u5f15\u5165\u53d8\u5206\u5206\u5e03  $q\\left(x_1: x_T \\mid x_0\\right)$\n<ul>\n<li>$q\\left(x_1: x_T \\mid x_0\\right)$ \u53ef\u4ee5\u662f\u4efb\u610f\u5206\u5e03\uff0c\u7528\u6765\u8fd1\u4f3c\u540e\u9a8c\u5206\u5e03 $P\\left(x_1: x_T \\mid x_0\\right)$ \u3002<\/li>\n<li>\u4f7f\u7528 $q\\left(x_1: x_T \\mid x_0\\right)$ \u91cd\u65b0\u8868\u8fbe $\\log P_\\theta\\left(x_0\\right)$ :<br \/>\n$$<br \/>\n\\log P_\\theta\\left(x_0\\right)=\\mathbb{E}_{q\\left(x_1: x_T \\mid x_0\\right)}\\left[\\log \\left(\\frac{P_\\theta\\left(x_0\\right)}{q\\left(x_1: x_T \\mid x_0\\right)}\\right)\\right]<br \/>\n$$<\/li>\n<\/ul>\n<\/li>\n<li>\u5c06\u5bf9\u6570\u4f3c\u7136\u5206\u89e3\n<ul>\n<li>\u5c06  $\\log P_\\theta\\left(x_0\\right)$ \u8fdb\u884c\u5206\u89e3\uff0c\u5f97\u5230\u8054\u5408\u5206\u5e03 $P\\left(x_0: x_T\\right)$  \u4e0e\u6761\u4ef6\u5206\u5e03 $P\\left(x_1: x_T \\mid x_0\\right)$ \u7684\u6bd4\u7387:<br \/>\n$$<br \/>\n\\log P_\\theta\\left(x_0\\right)=\\mathbb{E}_{q\\left(x_1: x_T \\mid x_0\\right)}\\left[\\log \\left(\\frac{P_\\theta\\left(x_0, x_1, \\ldots, x_T\\right)}{P\\left(x_1: x_T \\mid x_0\\right)}\\right)\\right]<br \/>\n$$<\/li>\n<\/ul>\n<\/li>\n<li>\u518d\u6b21\u5f15\u5165\u53d8\u5206\u5206\u5e03\n<ul>\n<li>\u5728\u5206\u5b50\u548c\u5206\u6bcd\u4e0a\u5f15\u5165\u53d8\u5206\u5206\u5e03 $q\\left(x_1: x_T \\mid x_0\\right)$ :<br \/>\n$$<br \/>\n\\log P_\\theta\\left(x_0\\right)=\\mathbb{E}_{q\\left(x_1: x_T \\mid x_0\\right)}\\left[\\log \\left(\\frac{P_\\theta\\left(x_0, x_1, \\ldots, x_T\\right)}{q\\left(x_1: x_T \\mid x_0\\right)} \\cdot \\frac{q\\left(x_1: x_T \\mid x_0\\right)}{P\\left(x_1: x_T \\mid x_0\\right)}\\right)\\right]<br \/>\n$$<\/li>\n<\/ul>\n<\/li>\n<li>\u5206\u89e3\u5bf9\u6570\n<ul>\n<li>\u5c06\u5bf9\u6570\u9879\u5206\u89e3\u6210\u4e24\u90e8\u5206:<br \/>\n$$<br \/>\n\\log P_\\theta\\left(x_0\\right)=\\mathbb{E}_{q\\left(x_1: x_T \\mid x_0\\right)}\\left[\\log \\left(\\frac{P_\\theta\\left(x_0, x_1, \\ldots, x_T\\right)}{q\\left(x_1: x_T \\mid x_0\\right)}\\right)+\\log \\left(\\frac{q\\left(x_1: x_T \\mid x_0\\right)}{P\\left(x_1: x_T \\mid x_0\\right)}\\right)\\right]<br \/>\n$$<\/li>\n<\/ul>\n<\/li>\n<li>\u5f15\u5165 KL \u6563\u5ea6\n<ul>\n<li>\u7b2c\u4e8c\u9879\u662f $q\\left(x_1: x_T \\mid x_0\\right)$ \u548c $P\\left(x_1: x_T \\mid x_0\\right)$ \u4e4b\u95f4\u7684KL\u6563\u5ea6\uff1a<br \/>\n$$<br \/>\n\\log P_\\theta\\left(x_0\\right)=\\mathbb{E}_{q\\left(x_1: x_T \\mid x_0\\right)}\\left[\\log \\left(\\frac{P_\\theta\\left(x_0, x_1, \\ldots, x_T\\right)}{q\\left(x_1: x_T \\mid x_0\\right)}\\right)\\right]+\\mathbb{E}_{q\\left(x_1: x_T \\mid x_0\\right)}\\left[\\log \\left(\\frac{q\\left(x_1: x_T \\mid x_0\\right)}{P\\left(x_1: x_T \\mid x_0\\right)}\\right)\\right]<br \/>\n$$<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>\u5176\u4e2d\u7b2c\u4e8c\u9879\u662fKL\u6563\u5ea6\uff0c\u8bb0\u4f5c $K L\\left(q\\left(x_1: x_T \\mid x_0\\right) | P\\left(x_1: x_T \\mid x_0\\right)\\right)$ \u3002<\/p>\n<ol start=\"7\">\n<li>\u5e94\u7528 Jensen \u4e0d\u7b49\u5f0f\n<ul>\n<li>\u7531\u4e8eKL\u6563\u5ea6\u603b\u662f\u975e\u8d1f\u7684\uff0c\u56e0\u6b64:<br \/>\n$$<br \/>\n\\log P_\\theta\\left(x_0\\right) \\geq \\mathbb{E}_{q\\left(x_1: x_T \\mid x_0\\right)}\\left[\\log \\left(\\frac{P_\\theta\\left(x_0, x_1, \\ldots, x_T\\right)}{q\\left(x_1: x_T \\mid x_0\\right)}\\right)\\right]<br \/>\n$$<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>\u8fd9\u4e00\u6b65\u6211\u4eec\u5e94\u7528\u4e86Jensen\u4e0d\u7b49\u5f0f\uff0c\u5f97\u5230\u4e00\u4e2a\u5bf9\u6570\u4f3c\u7136\u7684\u4e0b\u754c\u3002<br \/>\n\u53d8\u5206\u4e0b\u754c (ELBO)<\/p>\n<ul>\n<li>\u6700\u7ec8\uff0c\u6211\u4eec\u5f97\u5230\u53d8\u5206\u4e0b\u754c (Evidence Lower Bound, ELBO)\uff0c\u5b83\u662f\u4e00\u4e2a\u671f\u671b\u503c\u7684\u5f62\u5f0f:<br \/>\n$$<br \/>\n\\log P_\\theta\\left(x_0\\right) \\geq \\mathbb{E}_{q\\left(x_1: x_T \\mid x_0\\right)}\\left[\\log \\left(\\frac{P_\\theta\\left(x_0, x_1, \\ldots, x_T\\right)}{q\\left(x_1: x_T \\mid x_0\\right)}\\right)\\right]<br \/>\n$$<\/li>\n<\/ul>\n<p><strong>$\\mathbb{E}_{q\\left(x_1: x_T \\mid x_0\\right)}$  \u53ef\u4ee5\u770b\u4f5cDDPM\u4e2d\u7684\u7f16\u7801\u8fc7\u7a0b\uff0c\u5373\u4ece\u6570\u636e$x_0$ \u7f16\u7801\u5230\u591a\u4e2a\u4e2d\u95f4\u72b6\u6001 $x_1, x_2, \\ldots, x_T$<\/strong><\/p>\n<h3><img decoding=\"async\" src=\"https:\/\/img.icons8.com\/?size=100&id=42897&format=png&color=000000\" style=\"height:50px;display:inline\"> \u7ee7\u7eed\uff01\u518d\u6765\u4e00\u6ce2\u5c0f\u5c0f\u7684\u63a8\u5bfc\uff0c\u5c31\u53ef\u4ee5\u5f97\u51faDDPM\u6a21\u578b\u7684\u6700\u7ec8\u635f\u5931<img decoding=\"async\" src=\"https:\/\/img.icons8.com\/?size=100&id=98huvVUFtEyB&format=png&color=000000\" style=\"height:50px;display:inline\"><\/h3>\n<hr \/>\n<p align=\"center\">\n  <img decoding=\"async\" src=\"https:\/\/gnnclub-1311496010.cos.ap-beijing.myqcloud.com\/wp-content\/uploads\/2024\/09\/20240926142254119.png\" style=\"height:900px\">\n<\/p>\n<p><a href=\"https:\/\/arxiv.org\/pdf\/2208.11970\">\u53c2\u8003\uff1aUnderstanding Diffusion Models: A Unified Perspective<\/a><\/p>\n<p>\u901a\u8fc7\u53d8\u5206\u4e0b\u754c\u63a8\u5bfc\uff0cDDPM (Denoising Diffusion Probabilistic Models) \u7684\u76ee\u6807\u662f\u6700\u5927\u5316\u5bf9\u6570\u4f3c\u7136 $\\log P_\\theta\\left(\\boldsymbol{x}_0\\right)$ \u3002\u6700\u7ec8\uff0c\u6211\u4eec\u5c06\u5bf9\u6570\u4f3c\u7136\u5206\u89e3\u4e3a\u4e09\u4e2a\u635f\u5931\u9879\uff1a<\/p>\n<ul>\n<li>\u91cd\u6784\u9879<\/li>\n<li>\u5148\u9a8c\u5339\u914d\u9879<\/li>\n<li>\u53bb\u566a\u5339\u914d\u9879\u3002<\/li>\n<\/ul>\n<p>\u4e0b\u9762\u8be6\u7ec6\u89e3\u91ca\u8fd9\u4e09\u79cd\u635f\u5931\u9879\u3002<\/p>\n<ol>\n<li>\u91cd\u6784\u9879\uff08Reconstruction Term\uff09<br \/>\n$$<br \/>\n\\mathbb{E}_{q\\left(\\boldsymbol{x}_1 \\mid \\boldsymbol{x}_0\\right)}\\left[\\log p_\\theta\\left(\\boldsymbol{x}_0 \\mid \\boldsymbol{x}_1\\right)\\right]<br \/>\n$$<\/li>\n<\/ol>\n<p>\u89e3\u91ca:<\/p>\n<ul>\n<li>\u91cd\u6784\u9879\u63cf\u8ff0\u4e86\u4ece\u4e2d\u95f4\u72b6\u6001 $\\boldsymbol{x}_1$ \u91cd\u6784\u539f\u59cb\u6570\u636e $\\boldsymbol{x}_0$ \u7684\u8d28\u91cf\u3002<\/li>\n<li>\u901a\u8fc7\u671f\u671b$\\mathbb{E}_{q\\left(\\boldsymbol{x}_1 \\mid \\boldsymbol{x}_0\\right)}$\uff0c\u6211\u4eec\u5728\u53d8\u5206\u5206\u5e03 $q\\left(\\boldsymbol{x}_1 \\mid \\boldsymbol{x}_0\\right)$ \u4e0b\u8ba1\u7b97\u5bf9\u6570\u4f3c\u7136\u3002<\/li>\n<li>\u8fd9\u4e2a\u9879\u786e\u4fdd\u751f\u6210\u7684\u56fe\u50cf\u5728\u7ecf\u8fc7\u6269\u6563\u8fc7\u7a0b\u5e76\u4ece\u4e2d\u95f4\u72b6\u6001\u56de\u5f52\u65f6\u80fd\u591f\u903c\u8fd1\u539f\u59cb\u6570\u636e\u3002<\/li>\n<\/ul>\n<ol start=\"2\">\n<li>\u5148\u9a8c\u5339\u914d\u9879\uff08Prior Matching Term)<br \/>\n$$<br \/>\n-D_{\\mathrm{KL}}\\left(q\\left(\\boldsymbol{x}_T \\mid \\boldsymbol{x}_0\\right) | p\\left(\\boldsymbol{x}_T\\right)\\right)<br \/>\n$$<\/li>\n<\/ol>\n<p>\u89e3\u91ca:<\/p>\n<ul>\n<li>\u5148\u9a8c\u5339\u914d\u9879\u662f\u7ec8\u72b6\u6001 $\\boldsymbol{x}_T$ \u7684\u540e\u9a8c\u5206\u5e03 $q\\left(\\boldsymbol{x}_T \\mid \\boldsymbol{x}_0\\right)$ \u548c\u5148\u9a8c\u5206\u5e03 $p\\left(\\boldsymbol{x}_T\\right)$ \u4e4b\u95f4\u7684KL\u6563\u5ea6\u3002<\/li>\n<li>$D_{\\mathrm{KL}}(q | p)$  \u8868\u793a\u4e24\u4e2a\u5206\u5e03\u4e4b\u95f4\u7684\u5dee\u5f02\uff0c\u8d8a\u5c0f\u8d8a\u597d\u3002<\/li>\n<li>\u8fd9\u4e2a\u9879\u786e\u4fdd\u6269\u6563\u8fc7\u7a0b\u7684\u6700\u7ec8\u72b6\u6001$\\boldsymbol{x}_T$ \u63a5\u8fd1\u4e8e\u9884\u5148\u5b9a\u4e49\u7684\u5148\u9a8c\u5206\u5e03  $p\\left(\\boldsymbol{x}_T\\right)$ \uff0c\u901a\u5e38\u662f\u6807\u51c6\u9ad8\u65af\u5206\u5e03\u3002<\/li>\n<li>\u66f4\u91cd\u8981\u7684\u662f\uff0c\u8fd9\u4e00\u9879\u5b9e\u9645\u4e0a\u4e0e\u635f\u5931\u8ba1\u7b97\u6ca1\u6709\u4efb\u4f55\u5173\u7cfb\uff0c\u56e0\u4e3a\u4e0d\u6d89\u53ca\u795e\u7ecf\u7f51\u7edc\u7684\u53c2\u4e0e\uff08\u6ca1\u6709 \u03b8\uff09<\/li>\n<\/ul>\n<ol start=\"3\">\n<li>\u53bb\u566a\u5339\u914d\u9879 (Denoising Matching Term)<br \/>\n$$<br \/>\n-\\sum_{t=2}^T \\mathbb{E}_{q\\left(\\boldsymbol{x}_t \\mid \\boldsymbol{x}_0\\right)}\\left[D_{\\mathrm{KL}}\\left(q\\left(\\boldsymbol{x}_{t-1} \\mid \\boldsymbol{x}_t, \\boldsymbol{x}_0\\right) | p_\\theta\\left(\\boldsymbol{x}_{t-1} \\mid \\boldsymbol{x}_t\\right)\\right)\\right]<br \/>\n$$<\/li>\n<\/ol>\n<p>\u89e3\u91ca:<\/p>\n<ul>\n<li>\u53bb\u566a\u5339\u914d\u9879\u662f\u6bcf\u4e00\u6b65\u53bb\u566a\u8fc7\u7a0b\u7684\u540e\u9a8c\u5206\u5e03$q\\left(\\boldsymbol{x}_{t-1} \\mid \\boldsymbol{x}_t, \\boldsymbol{x}_0\\right)$ \u548c\u6a21\u578b\u5206\u5e03 $p_\\theta\\left(\\boldsymbol{x}_{t-1} \\mid \\boldsymbol{x}_t\\right)$ \u4e4b\u95f4\u7684 KL\u6563\u5ea6\u3002<\/li>\n<li>\u8fd9\u4e2a\u9879\u786e\u4fdd\u5728\u6bcf\u4e00\u6b65\u53bb\u566a\u8fc7\u7a0b\u4e2d\uff0c\u6a21\u578b\u5206\u5e03 $p_\\theta$ \u80fd\u591f\u903c\u8fd1\u771f\u5b9e\u7684\u540e\u9a8c\u5206\u5e03 $q$ \uff0c\u4ece\u800c\u4fdd\u8bc1\u53bb\u566a\u8fc7\u7a0b\u7684\u8d28\u91cf\u548c\u7a33\u5b9a\u6027\u3002<\/li>\n<\/ul>\n<p>\u5728\u53bb\u566a\u5339\u914d\u9879\u4e2d\uff0c<strong>\u5982\u4f55\u7406\u89e3\u540e\u9a8c\u5206\u5e03 $q\\left(\\boldsymbol{x}_{t-1} \\mid \\boldsymbol{x}_t, \\boldsymbol{x}_0\\right)$\uff1f<\/strong><\/p>\n<p align=\"center\">\n  <img decoding=\"async\" src=\"https:\/\/gnnclub-1311496010.cos.ap-beijing.myqcloud.com\/wp-content\/uploads\/2024\/09\/20240923223803320.png\" style=\"height:200px\">\n<\/p>\n<p>$q\\left(\\boldsymbol{x}_{t-1} \\mid \\boldsymbol{x}_t, \\boldsymbol{x}_0\\right)$  \u662f\u5728\u7ed9\u5b9a\u5f53\u524d\u72b6\u6001 $\\boldsymbol{x}_t$ \u548c\u539f\u59cb\u72b6\u6001 $\\boldsymbol{x}_0$ \u7684\u6761\u4ef6\u4e0b\uff0c\u524d\u4e00\u6b65\u72b6\u6001 $\\boldsymbol{x}_{t-1}$ \u7684\u540e\u9a8c\u5206\u5e03\u3002\u53ef\u4ee5\u7406\u89e3\u4e3a\u6269\u6563\u8fc7\u7a0b\u751f\u6210\u7684\u201c\u771f\u503c\u201d\u6216\u201c\u771f\u5b9e\u5206\u5e03\u201d\u3002<\/p>\n<p>\u6a21\u578b\u5206\u5e03 $p_\\theta\\left(\\boldsymbol{x}_{t-1} \\mid \\boldsymbol{x}_t\\right)$ \u662f\u53bb\u566a\u8fc7\u7a0b\u6a21\u578b\u7684\u9884\u6d4b\u503c\u3002<\/p>\n<p>\u8fdb\u4e00\u6b65\u7684\uff1a<\/p>\n<p>$$<br \/>\nq\\left(\\boldsymbol{x}_{t-1} \\mid \\boldsymbol{x}_t, \\boldsymbol{x}_0\\right)=\\frac{q\\left(x_{t-1}, x_t, x_0\\right)}{q\\left(x_t, x_0\\right)}=\\frac{q\\left(x_t \\mid x_{t-1}\\right) q\\left(x_{t-1} \\mid x_0\\right) q\\left(x_0\\right)}{q\\left(x_t \\mid x_0\\right) q\\left(x_0\\right)}=\\frac{q\\left(x_t \\mid x_{t-1}\\right) q\\left(x_{t-1} \\mid x_0\\right)}{q\\left(x_t \\mid x_0\\right)}<br \/>\n$$<\/p>\n<p align=\"center\">\n  <img decoding=\"async\" src=\"https:\/\/gnnclub-1311496010.cos.ap-beijing.myqcloud.com\/wp-content\/uploads\/2024\/09\/20240924191028807.png\" style=\"height:300px\">\n<\/p>\n<h3><img decoding=\"async\" src=\"https:\/\/img.icons8.com\/?size=100&id=42897&format=png&color=000000\" style=\"height:50px;display:inline\"> \u9a6c\u4e0a\u7ed3\u675f\u5566\uff01\u518d\u6765\u4e00\u6ce2\u5c0f\u5c0f\u7684\u63a8\u5bfc...<img decoding=\"async\" src=\"https:\/\/img.icons8.com\/?size=100&id=hFgSvrOBPpEc&format=png&color=000000\" style=\"height:50px;display:inline\"><\/h3>\n<hr \/>\n<p align=\"center\">\n  <img decoding=\"async\" src=\"https:\/\/gnnclub-1311496010.cos.ap-beijing.myqcloud.com\/wp-content\/uploads\/2024\/09\/20240926142123830.png\" style=\"height:900px\">\n<\/p>\n<p align=\"center\">\n  <img decoding=\"async\" src=\"https:\/\/gnnclub-1311496010.cos.ap-beijing.myqcloud.com\/wp-content\/uploads\/2024\/09\/20240924193555748.png\" style=\"height:400px\">\n<\/p>\n<p align=\"center\">\n  <img decoding=\"async\" src=\"https:\/\/gnnclub-1311496010.cos.ap-beijing.myqcloud.com\/wp-content\/uploads\/2024\/09\/20240924193655538.png\" style=\"height:300px\">\n<\/p>\n<p align=\"center\">\n  <img decoding=\"async\" src=\"https:\/\/gnnclub-1311496010.cos.ap-beijing.myqcloud.com\/wp-content\/uploads\/2024\/09\/20240926135546477.png\" style=\"height:300px\">\n<\/p>\n<h3><img decoding=\"async\" src=\"https:\/\/img.icons8.com\/?size=100&id=42897&format=png&color=000000\" style=\"height:50px;display:inline\"> \u771f\u7684\u8981\u7ed3\u675f\u4e86\uff0c\u8fd8\u8981\u4e00\u70b9\u5c0f\u63a8\u5bfc...<img decoding=\"async\" src=\"https:\/\/img.icons8.com\/?size=100&id=rkENV9NtQtRr&format=png&color=000000\" style=\"height:50px;display:inline\"><\/h3>\n<hr \/>\n<p>\u7531\u4e8e\uff1a<\/p>\n<p>$$<br \/>\n\\begin{aligned}<br \/>\n&amp; x_t=\\sqrt{\\bar{\\alpha}_t} x_0+\\sqrt{1-\\bar{\\alpha}_t \\epsilon_\\theta} \\\\<br \/>\n&amp; x_t-\\sqrt{1-\\bar{\\alpha}_t} \\epsilon_\\theta=\\sqrt{\\bar{\\alpha}_t} x_0 \\\\<br \/>\n&amp; \\frac{x_t-\\sqrt{1-\\bar{\\alpha}_t} \\epsilon_\\theta}{\\sqrt{\\bar{\\alpha}_t}}=x_0<br \/>\n\\end{aligned}<br \/>\n$$<\/p>\n<p>\u5c06 $x_0$\u4ee3\u5165$\\frac{\\sqrt{\\bar{\\alpha}_{t-1}} \\beta_t x_0+\\sqrt{\\alpha_t}\\left(1-\\bar{\\alpha}_{t-1}\\right) x_t}{1-\\bar{\\alpha}_t}$\uff1a\u518d\u63a8\u5bfc\u4e00\u5c0f\u4f1a\u513f<\/p>\n<p>$$<br \/>\n\\begin{aligned}<br \/>\n&amp; \\frac{\\sqrt{\\alpha_t}\\left(1-\\bar{\\alpha}_{t-1}\\right) \\boldsymbol{x}_t+\\sqrt{\\bar{\\alpha}_{t-1}}\\left(1-\\alpha_t\\right) \\boldsymbol{x}_0}{1-\\bar{\\alpha}_t} \\\\<br \/>\n&amp; =\\frac{\\sqrt{\\alpha_t}\\left(1-\\bar{\\alpha}_{t-1}\\right) \\boldsymbol{x}_t+\\sqrt{\\bar{\\alpha}_{t-1}}\\left(1-\\alpha_t\\right) \\frac{\\boldsymbol{x}_t-\\sqrt{1-\\bar{\\alpha}_t} \\epsilon_\\theta}{\\sqrt{\\bar{\\alpha}_t}}}{1-\\bar{\\alpha}_t} \\\\<br \/>\n&amp; =\\frac{\\sqrt{\\alpha_t}\\left(1-\\bar{\\alpha}_{t-1}\\right) \\boldsymbol{x}_t+\\left(1-\\alpha_t\\right) \\frac{\\boldsymbol{x}_t-\\sqrt{1-\\bar{\\alpha}_t} \\epsilon_\\theta}{\\sqrt{\\alpha_t}}}{1-\\bar{\\alpha}_t} \\\\<br \/>\n&amp; =\\frac{\\sqrt{\\alpha_t}\\left(1-\\bar{\\alpha}_{t-1}\\right) \\boldsymbol{x}_t}{1-\\bar{\\alpha}_t}+\\frac{\\left(1-\\alpha_t\\right) \\boldsymbol{x}_t}{\\left(1-\\bar{\\alpha}_t\\right) \\sqrt{\\alpha_t}}-\\frac{\\left(1-\\alpha_t\\right) \\sqrt{1-\\bar{\\alpha}_t} \\epsilon_\\theta}{\\left(1-\\bar{\\alpha}_t\\right) \\sqrt{\\alpha_t}} \\\\<br \/>\n&amp; =\\left(\\frac{\\sqrt{\\alpha_t}\\left(1-\\bar{\\alpha}_{t-1}\\right)}{1-\\bar{\\alpha}_t}+\\frac{1-\\alpha_t}{\\left(1-\\bar{\\alpha}_t\\right) \\sqrt{\\alpha_t}}\\right) \\boldsymbol{x}_t-\\frac{\\left(1-\\alpha_t\\right) \\sqrt{1-\\bar{\\alpha}_t}}{\\left(1-\\bar{\\alpha}_t\\right) \\sqrt{\\alpha_t}} \\boldsymbol{\\epsilon}_\\theta \\\\<br \/>\n&amp; =\\left(\\frac{\\alpha_t\\left(1-\\bar{\\alpha}_{t-1}\\right)}{\\left(1-\\bar{\\alpha}_t\\right) \\sqrt{\\alpha_t}}+\\frac{1-\\alpha_t}{\\left(1-\\bar{\\alpha}_t\\right) \\sqrt{\\alpha_t}}\\right) \\boldsymbol{x}_t-\\frac{1-\\alpha_t}{\\sqrt{1-\\bar{\\alpha}_t} \\sqrt{\\alpha_t}} \\boldsymbol{\\epsilon}_\\theta \\\\<br \/>\n&amp; =\\frac{\\alpha_t-\\bar{\\alpha}_t+1-\\alpha_t}{\\left(1-\\bar{\\alpha}_t\\right) \\sqrt{\\alpha_t}} \\boldsymbol{x}_t-\\frac{1-\\alpha_t}{\\sqrt{1-\\bar{\\alpha}_t} \\sqrt{\\alpha_t}} \\boldsymbol{\\epsilon}_\\theta \\\\<br \/>\n&amp; =\\frac{1-\\bar{\\alpha}_t}{\\left(1-\\bar{\\alpha}_t\\right) \\sqrt{\\alpha_t}} \\boldsymbol{x}_t-\\frac{1-\\alpha_t}{\\sqrt{1-\\bar{\\alpha}_t} \\sqrt{\\alpha_t}} \\boldsymbol{\\epsilon}_\\theta \\\\<br \/>\n&amp; =\\frac{1}{\\sqrt{\\alpha_t}} \\boldsymbol{x}_t-\\frac{1-\\alpha_t}{\\sqrt{1-\\bar{\\alpha}_t} \\sqrt{\\alpha_t}} \\boldsymbol{\\epsilon}_\\theta<br \/>\n\\end{aligned}<br \/>\n$$<\/p>\n<p align=\"center\">\n  <img decoding=\"async\" src=\"https:\/\/gnnclub-1311496010.cos.ap-beijing.myqcloud.com\/wp-content\/uploads\/2024\/09\/20240926135857733.png\" style=\"height:300px\">\n<\/p>\n<p>\u8fd9\u5c31\u5f97\u51fa\u4e86\u6269\u6563\u6a21\u578b\u4e2d\u53bb\u566a\u7684\u8fc7\u7a0b\u5b9a\u4e49\uff0c\u53c2\u7167\u4e0b\u56fe\uff08\u6765\u81ea\u539f\u8bba\u6587\uff09\u7684Sampling\uff0cstep4<\/p>\n<p align=\"center\">\n  <img decoding=\"async\" src=\"https:\/\/gnnclub-1311496010.cos.ap-beijing.myqcloud.com\/wp-content\/uploads\/2024\/09\/20240926135950690.png\" style=\"height:300px\">\n<\/p>\n<h3><img decoding=\"async\" src=\"https:\/\/img.icons8.com\/?size=100&id=42897&format=png&color=000000\" style=\"height:50px;display:inline\"> \u7b49\u7b49 \u03c3z \u53c8\u662f\u4ec0\u4e48\uff1f\uff1fwtf\uff01\uff01! <img decoding=\"async\" src=\"https:\/\/img.icons8.com\/?size=100&id=VPImuRG4xXS2&format=png&color=000000\" style=\"height:50px;display:inline\"><\/h3>\n<hr \/>\n<p>\u4f5c\u7528<\/p>\n<ol>\n<li>\n<p>\u6a21\u62df\u9006\u5411\u6269\u6563\u8fc7\u7a0b\u7684\u968f\u673a\u6027:<\/p>\n<ul>\n<li>\u6269\u6563\u8fc7\u7a0b\u4ece\u6570\u636e\u5230\u566a\u58f0\u662f\u4e00\u4e2a\u968f\u673a\u8fc7\u7a0b\uff0c\u9006\u5411\u8fc7\u7a0b\u4ece\u566a\u58f0\u5230\u6570\u636e\u540c\u6837\u9700\u8981\u6a21\u62df\u8fd9\u79cd\u968f\u673a\u6027\u3002<\/li>\n<li>$\\sigma_t z$ \u5f15\u5165\u4e86\u8fd9\u79cd\u968f\u673a\u6027\uff0c\u4f7f\u5f97\u6bcf\u4e00\u6b65\u7684\u9006\u5411\u8fc7\u7a0b\u4e0d\u4ec5\u4f9d\u8d56\u4e8e\u5f53\u524d\u72b6\u6001\u548c\u6a21\u578b\u9884\u6d4b\u7684\u566a\u58f0\uff0c\u8fd8\u5305\u62ec\u4e86\u4e00\u4e2a\u968f\u673a\u566a\u58f0\u9879\u3002<\/li>\n<li>\u53c2\u8003\u4e00\u7bc7<a href=\"https:\/\/arxiv.org\/abs\/1712.05884\">\u8bed\u97f3\u5408\u6210\u7684\u6587\u7ae0<\/a><\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u9632\u6b62\u6a21\u5f0f\u5d29\u6e83:<\/p>\n<ul>\n<li>\u6a21\u5f0f\u5d29\u6e83\u662f\u751f\u6210\u6a21\u578b\u4e2d\u5e38\u89c1\u7684\u95ee\u9898\uff0c\u6307\u7684\u662f\u6a21\u578b\u751f\u6210\u7684\u6837\u672c\u7f3a\u4e4f\u591a\u6837\u6027\uff0c\u4ec5\u96c6\u4e2d\u5728\u67d0\u4e9b\u7279\u5b9a\u6a21\u5f0f\u4e0a\u3002<\/li>\n<li>\u901a\u8fc7\u5728\u6bcf\u4e00\u6b65\u6dfb\u52a0\u968f\u673a\u566a\u58f0\uff0c\u53ef\u4ee5\u6709\u6548\u9632\u6b62\u6a21\u5f0f\u5d29\u6e83\uff0c\u786e\u4fdd\u751f\u6210\u7684\u6837\u672c\u8986\u76d6\u66f4\u5e7f\u7684\u6a21\u5f0f\u3002<\/li>\n<li>\u53c2\u8003Beam Search<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h3><img decoding=\"async\" src=\"https:\/\/img.icons8.com\/?size=100&id=48250&format=png&color=000000\" style=\"height:50px;display:inline\"> \u53cd\u5411\u8fc7\u7a0b\u4ee3\u7801\u793a\u4f8b<\/h3>\n<p>DDPM \u53cd\u5411\u53bb\u566a\u8fc7\u7a0b:<br \/>\n$$<br \/>\n\\mathbf{x}_{t-1}=\\frac{1}{\\sqrt{\\alpha_t}}\\left(\\mathbf{x}_t-\\frac{1-\\alpha_t}{\\sqrt{1-\\bar{\\alpha}_t}} \\epsilon_\\theta\\left(\\mathbf{x}_t, t\\right)\\right)+\\sigma_t \\mathbf{z}<br \/>\n$$<\/p>\n<pre><code class=\"language-python\">def p_sample(model, x, t,alphas):\n    t = torch.tensor([t])\n\n    # \u8bad\u7ec3\u597d\u7684\u6269\u6563\u6a21\u578b\uff0c\u7528\u4e8e\u9884\u6d4b\u566a\u58f0\n    eps_theta = model(x, t)\n\n    # Final values\n    eps_factor = ((1 - extract(alphas, t, x)) \/ extract(one_minus_alphas_bar_sqrt, t, x)) # \u8ba1\u7b97\u566a\u58f0\u7684\u7f29\u653e\u56e0\u5b50\n    mean = (1 \/ extract(alphas, t, x).sqrt()) * (x - (eps_factor * eps_theta))\n\n    # Generate z\n    z = torch.randn_like(x)\n\n    # Fixed sigma\n    sigma_t = extract(betas, t, x).sqrt()\n    sample = mean + sigma_t * z\n\n    return (sample)\n\n# \u5728\u91c7\u6837\u8fc7\u7a0b\u4e2d\uff0c\u4ece\u5305\u542b\u4e0d\u540c\u65f6\u95f4\u6b65\u7684\u5f20\u91cf\u4e2d\u63d0\u53d6\u5f53\u524d\u65f6\u95f4\u6b65\u7684\u53c2\u6570\n# input: \u8f93\u5165\u5f20\u91cf\n# t: \u65f6\u95f4\u6b65\u5f20\u91cf\n# x: \u7528\u4e8e\u83b7\u53d6\u5f62\u72b6\u7684\u53c2\u8003\u5f20\u91cf\ndef extract(input, t, x):\n    shape = x.shape\n    out = torch.gather(input, 0, t.to(input.device))\n    reshape = [t.shape[0]] + [1] * (len(shape) - 1)\n    return out.reshape(*reshape)<\/code><\/pre>\n<h3><img decoding=\"async\" src=\"https:\/\/img.icons8.com\/?size=100&id=48250&format=png&color=000000\" style=\"height:50px;display:inline\"> Demo\u9879\u76ee\uff1aDDPM\u751f\u6210\u745e\u58eb\u5377<\/h3>\n<hr \/>\n<pre><code class=\"language-python\">import torch\nimport torch.nn as nn\nimport torch.optim as optim\nimport torch.nn.functional as F\nimport matplotlib.pyplot as plt\nfrom sklearn.datasets import make_swiss_roll\n\n# \u751f\u6210\u745e\u58eb\u5377\u6570\u636e\u96c6\u7684\u6837\u672c\ndef sample_batch(size, noise=1.0):\n    x, _ = make_swiss_roll(size, noise=noise)\n    return x[:, [0, 2]] \/ 10.0\n\n# \u4ece\u8f93\u5165\u5f20\u91cf\u4e2d\u63d0\u53d6\u6307\u5b9a\u65f6\u95f4\u6b65\u7684\u5143\u7d20\ndef extract(input, t, x):\n    shape = x.shape\n    out = torch.gather(input, 0, t.to(input.device))\n    reshape = [t.shape[0]] + [1] * (len(shape) - 1)\n    return out.reshape(*reshape)\n\n# \u751f\u6210beta\u8c03\u5ea6\u8868\uff0c\u7528\u4e8e\u63a7\u5236\u6bcf\u4e2a\u65f6\u95f4\u6b65\u7684\u566a\u58f0\u5f3a\u5ea6\ndef make_beta_schedule(schedule=&#039;linear&#039;, n_timesteps=1000, start=1e-5, end=1e-2):\n    if schedule == &#039;linear&#039;:\n        betas = torch.linspace(start, end, n_timesteps)\n    elif schedule == &quot;quad&quot;:\n        betas = torch.linspace(start ** 0.5, end ** 0.5, n_timesteps) ** 2\n    elif schedule == &quot;sigmoid&quot;:\n        betas = torch.linspace(-6, 6, n_timesteps)\n        betas = torch.sigmoid(betas) * (end - start) + start\n    return betas\n\n# \u53ef\u89c6\u5316\u745e\u58eb\u5377\u6570\u636e\ndef visualize_swiss_roll():\n    data = sample_batch(1000)\n    plt.figure(figsize=(10, 7))\n    plt.scatter(data[:, 0], data[:, 1], c=&#039;blue&#039;, marker=&#039;o&#039;, s=10, alpha=0.5)\n    plt.title(&#039;Swiss Roll Data Visualization&#039;)\n    plt.xlabel(&#039;X&#039;)\n    plt.ylabel(&#039;Y&#039;)\n    plt.grid(True)\n    plt.show()\n\n# \u53ef\u89c6\u5316\u745e\u58eb\u5377\u6570\u636e\nvisualize_swiss_roll()<\/code><\/pre>\n<p align=\"center\">\n  <img decoding=\"async\" src=\"https:\/\/gnnclub-1311496010.cos.ap-beijing.myqcloud.com\/wp-content\/uploads\/2024\/09\/20240926140039260.png\" style=\"height:400px\">\n<\/p>\n<pre><code class=\"language-python\"># ConditionalLinear \u662f\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7ebf\u6027\u5c42\uff0c\u5305\u542b\u65f6\u95f4\u6b65\u5d4c\u5165\uff0c\u7528\u4e8e\u6761\u4ef6\u5316\u8f93\u5165\u7279\u5f81\nclass ConditionalLinear(nn.Module):\n    def __init__(self, num_in, num_out, n_steps):\n        super(ConditionalLinear, self).__init__()\n        self.num_out = num_out\n        self.lin = nn.Linear(num_in, num_out)  # \u7ebf\u6027\u53d8\u6362\u5c42\n        self.embed = nn.Embedding(n_steps, num_out)  # \u65f6\u95f4\u6b65\u5d4c\u5165\u5c42\n        self.embed.weight.data.uniform_()  # \u521d\u59cb\u5316\u5d4c\u5165\u6743\u91cd\n\n    def forward(self, x, y):\n        out = self.lin(x)  # \u5bf9\u8f93\u5165\u7279\u5f81\u8fdb\u884c\u7ebf\u6027\u53d8\u6362\n        gamma = self.embed(y)  # \u83b7\u53d6\u65f6\u95f4\u6b65\u5d4c\u5165\u5411\u91cf\n        # gamma \u7684\u7ef4\u5ea6\u662f [batch_size, num_out]\uff0c\u901a\u8fc7 view(-1, self.num_out) \u4fdd\u6301\u8fd9\u4e2a\u7ef4\u5ea6\n        # \u9010\u5143\u7d20\u4e58\u6cd5\u4f7f\u5f97\u7ebf\u6027\u53d8\u6362\u7684\u8f93\u51fa\u6839\u636e\u65f6\u95f4\u6b65\u8fdb\u884c\u6761\u4ef6\u5316\n        out = gamma.view(-1, self.num_out) * out\n        return out\n\n# ConditionalModel \u662f\u4e00\u4e2a\u4f7f\u7528 ConditionalLinear \u5c42\u7684\u795e\u7ecf\u7f51\u7edc\u6a21\u578b\nclass ConditionalModel(nn.Module):\n    def __init__(self, n_steps):\n        super(ConditionalModel, self).__init__()\n        self.lin1 = ConditionalLinear(2, 128, n_steps)  # \u7b2c\u4e00\u5c42\u6761\u4ef6\u7ebf\u6027\u5c42\n        self.lin2 = ConditionalLinear(128, 128, n_steps)  # \u7b2c\u4e8c\u5c42\u6761\u4ef6\u7ebf\u6027\u5c42\n        self.lin3 = ConditionalLinear(128, 128, n_steps)  # \u7b2c\u4e09\u5c42\u6761\u4ef6\u7ebf\u6027\u5c42\n        self.lin4 = nn.Linear(128, 2)  # \u6700\u540e\u4e00\u5c42\u666e\u901a\u7ebf\u6027\u5c42\n\n    def forward(self, x, y):\n        x = F.softplus(self.lin1(x, y))  # \u901a\u8fc7\u7b2c\u4e00\u5c42\u5e76\u4f7f\u7528 softplus \u6fc0\u6d3b\u51fd\u6570\n        x = F.softplus(self.lin2(x, y))  # \u901a\u8fc7\u7b2c\u4e8c\u5c42\u5e76\u4f7f\u7528 softplus \u6fc0\u6d3b\u51fd\u6570\n        x = F.softplus(self.lin3(x, y))  # \u901a\u8fc7\u7b2c\u4e09\u5c42\u5e76\u4f7f\u7528 softplus \u6fc0\u6d3b\u51fd\u6570\n        return self.lin4(x)  # \u8f93\u51fa\u6700\u7ec8\u7ed3\u679c<\/code><\/pre>\n<p>EMA <\/p>\n<p>\u6307\u6570\u79fb\u52a8\u5e73\u5747 Exponential Moving Average (EMA)\u662f\u5e38\u5e38\u7528\u5230\u7684\u8bad\u7ec3 trick\uff0c\u4e0d\u540c\u4e8e\u76f4\u63a5\u66f4\u65b0\u6a21\u578b\u6743\u91cd\uff0c\u9996\u5148\u4fdd\u7559\u4e00\u4e9b\u4e4b\u524d\u7684\u6743\u91cd\uff0c\u7136\u540e\u57fa\u4e8e\u5f53\u524d\u6743\u91cd\u548c\u4e4b\u524d\u7684\u6743\u91cd\u5f97\u5230\u66f4\u65b0\u7684\u6743\u91cd\u5747\u503c\uff0c\u8fd9\u91cc\u53c2\u8003<a href=\"https:\/\/github.com\/ermongroup\/ddim\">DDIM<\/a> \u7684\u4ee3\u7801\uff1a<\/p>\n<pre><code class=\"language-python\">class EMA(object):\n    def __init__(self, mu=0.999):\n        self.mu = mu\n        self.shadow = {}\n\n    def register(self, module):\n        for name, param in module.named_parameters():\n            if param.requires_grad:\n                self.shadow[name] = param.data.clone()\n\n    def update(self, module):\n        for name, param in module.named_parameters():\n            if param.requires_grad:\n                self.shadow[name].data = (1. - self.mu) * param.data + self.mu * self.shadow[name].data\n\n    def ema(self, module):\n        for name, param in module.named_parameters():\n            if param.requires_grad:\n                param.data.copy_(self.shadow[name].data)\n\n    def ema_copy(self, module):\n        module_copy = type(module)(module.config).to(module.config.device)\n        module_copy.load_state_dict(module.state_dict())\n        self.ema(module_copy)\n        return module_copy\n\n    def state_dict(self):\n        return self.shadow\n\n    def load_state_dict(self, state_dict):\n        self.shadow = state_dict<\/code><\/pre>\n<p>\u8bad\u7ec3\u8fc7\u7a0b\u5b9a\u4e49\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python\">def p_sample_loop(model, shape,n_steps,alphas):\n    cur_x = torch.randn(shape)\n    x_seq = [cur_x]\n    for i in reversed(range(n_steps)):\n        cur_x = p_sample(model, cur_x, i,alphas)\n        x_seq.append(cur_x)\n    return x_seq\n\nn_steps = 100\n\nbetas = make_beta_schedule(schedule=&#039;sigmoid&#039;, n_timesteps=n_steps, start=1e-5, end=1e-2)\nalphas = 1 - betas\nalphas_prod = torch.cumprod(alphas, 0)\nalphas_prod_p = torch.cat([torch.tensor([1]).float(), alphas_prod[:-1]], 0)\nalphas_bar_sqrt = torch.sqrt(alphas_prod)\none_minus_alphas_bar_log = torch.log(1 - alphas_prod)\none_minus_alphas_bar_sqrt = torch.sqrt(1 - alphas_prod)\n\n# data\ndata = sample_batch(10**4).T\ndataset = torch.tensor(data.T).float()\n\n# create EMA model\nmodel = ConditionalModel(n_steps)\nema = EMA(0.9)\nema.register(model)\n\n# optimizer\noptimizer = optim.Adam(model.parameters(), lr=1e-3)\n\n# batch size\nbatch_size = 128\n\n# train\nfor t in range(1000):\n    # X is a torch Variable\n    permutation = torch.randperm(dataset.size()[0])\n    for i in range(0, dataset.size()[0], batch_size):\n        # Retrieve current batch\n        indices = permutation[i:i+batch_size]\n        batch_x = dataset[indices]\n        # Compute the loss.\n        loss = noise_estimation_loss(model, batch_x,n_steps)\n        # Before the backward pass, zero all of the network gradients\n        optimizer.zero_grad()\n        # Backward pass: compute gradient of the loss with respect to parameters\n        loss.backward()\n        # Perform gradient clipping\n        torch.nn.utils.clip_grad_norm_(model.parameters(), 1.)\n        # Calling the step function to update the parameters\n        optimizer.step()\n        # Update the exponential moving average\n        ema.update(model)\n\n    # Print loss\n    if (t % 100 == 0):\n        print(loss)\n        x_seq = p_sample_loop(model, dataset.shape,n_steps,alphas)\n        fig, axs = plt.subplots(1, 10, figsize=(28, 3))\n        for i in range(1, 11):\n            cur_x = x_seq[i * 10].detach()\n            axs[i-1].scatter(cur_x[:, 0], cur_x[:, 1], s=10);\n            #axs[i-1].set_axis_off(); \n            axs[i-1].set_title(&#039;$q(\\mathbf{x}_{&#039;+str(i*100)+&#039;})$&#039;)<\/code><\/pre>\n<pre><code>tensor(0.6020, grad_fn=<MeanBackward0>)\ntensor(0.7829, grad_fn=<MeanBackward0>)\ntensor(0.9490, grad_fn=<MeanBackward0>)\ntensor(0.5602, grad_fn=<MeanBackward0>)\ntensor(0.7271, grad_fn=<MeanBackward0>)\ntensor(1.0588, grad_fn=<MeanBackward0>)\ntensor(0.4761, grad_fn=<MeanBackward0>)\ntensor(0.7699, grad_fn=<MeanBackward0>)\ntensor(0.7214, grad_fn=<MeanBackward0>)\ntensor(0.7370, grad_fn=<MeanBackward0>)<\/code><\/pre>\n<p align=\"center\">\n  <img decoding=\"async\" src=\"https:\/\/gnnclub-1311496010.cos.ap-beijing.myqcloud.com\/wp-content\/uploads\/2024\/09\/20240926140130891.png\" style=\"height:150px\">\n<\/p>\n<p align=\"center\">\n  <img decoding=\"async\" src=\"https:\/\/gnnclub-1311496010.cos.ap-beijing.myqcloud.com\/wp-content\/uploads\/2024\/09\/20240926140256787.png\" style=\"height:150px\">\n<\/p>\n<p align=\"center\">\n  <img decoding=\"async\" src=\"https:\/\/gnnclub-1311496010.cos.ap-beijing.myqcloud.com\/wp-content\/uploads\/2024\/09\/20240926140318240.png\" style=\"height:150px\">\n<\/p>\n<p align=\"center\">\n  <img decoding=\"async\" src=\"https:\/\/gnnclub-1311496010.cos.ap-beijing.myqcloud.com\/wp-content\/uploads\/2024\/09\/20240926140334180.png\" style=\"height:150px\">\n<\/p>\n<p align=\"center\">\n  <img decoding=\"async\" src=\"https:\/\/gnnclub-1311496010.cos.ap-beijing.myqcloud.com\/wp-content\/uploads\/2024\/09\/20240926140350383.png\" style=\"height:150px\">\n<\/p>\n<p align=\"center\">\n  <img decoding=\"async\" src=\"https:\/\/gnnclub-1311496010.cos.ap-beijing.myqcloud.com\/wp-content\/uploads\/2024\/09\/20240926140407867.png\" style=\"height:150px\">\n<\/p>\n<p align=\"center\">\n  <img decoding=\"async\" src=\"https:\/\/gnnclub-1311496010.cos.ap-beijing.myqcloud.com\/wp-content\/uploads\/2024\/09\/20240926140423492.png\" style=\"height:150px\">\n<\/p>\n<p align=\"center\">\n  <img decoding=\"async\" src=\"https:\/\/gnnclub-1311496010.cos.ap-beijing.myqcloud.com\/wp-content\/uploads\/2024\/09\/20240926140440732.png\" style=\"height:150px\">\n<\/p>\n<p align=\"center\">\n  <img decoding=\"async\" src=\"https:\/\/gnnclub-1311496010.cos.ap-beijing.myqcloud.com\/wp-content\/uploads\/2024\/09\/20240926140454192.png\" style=\"height:150px\">\n<\/p>\n<p align=\"center\">\n  <img decoding=\"async\" src=\"https:\/\/gnnclub-1311496010.cos.ap-beijing.myqcloud.com\/wp-content\/uploads\/2024\/09\/20240926140511219.png\" style=\"height:150px\">\n<\/p>\n<h2><img decoding=\"async\" src=\"https:\/\/img.icons8.com\/dusk\/64\/000000\/prize.png\" style=\"height:50px;display:inline\"> Credits<\/h2>\n<hr \/>\n<ul>\n<li>Icons made by <a href=\"https:\/\/www.flaticon.com\/authors\/becris\" title=\"Becris\">Becris<\/a> from <a href=\"https:\/\/www.flaticon.com\/\" title=\"Flaticon\">www.flaticon.com<\/a><\/li>\n<li>Icons from <a href=\"https:\/\/icons8.com\/\">Icons8.com<\/a> - <a href=\"https:\/\/icons8.com\">https:\/\/icons8.com<\/a><\/li>\n<li><a href=\"https:\/\/d2l.ai\/chapter_recurrent-neural-networks\/index.html\">Dive Into Deep Learning - Recurrent Neural Networks<\/a><\/li>\n<li><a href=\"https:\/\/atcold.github.io\/pytorch-Deep-Learning\/en\/week12\/12-1\/\">DS-GA 1008 - NYU CENTER FOR DATA SCIENCE - Deep Sequence Modeling<\/a><\/li>\n<li><a href=\"https:\/\/pytorch.org\/tutorials\/beginner\/text_sentiment_ngrams_tutorial.html\">Text classification with the torchtext library<br \/>\n<\/a><\/li>\n<li><a href=\"https:\/\/www.borealisai.com\/research-blogs\/tutorial-17-transformers-iii-training\/\">Tricks For Training Transformers - Borealis AI - P. Xu, S. Prince<\/a><\/li>\n<li><a href=\"https:\/\/taldatech.github.io\">Tal Daniel<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Deep Learning create by Arwin Yu Tutorial 07 &#8211; Denoisin [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2120,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,24],"tags":[19],"class_list":["post-2117","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-18","category-24","tag-19"],"_links":{"self":[{"href":"http:\/\/gnn.club\/index.php?rest_route=\/wp\/v2\/posts\/2117","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/gnn.club\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/gnn.club\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/gnn.club\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/gnn.club\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2117"}],"version-history":[{"count":21,"href":"http:\/\/gnn.club\/index.php?rest_route=\/wp\/v2\/posts\/2117\/revisions"}],"predecessor-version":[{"id":2169,"href":"http:\/\/gnn.club\/index.php?rest_route=\/wp\/v2\/posts\/2117\/revisions\/2169"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/gnn.club\/index.php?rest_route=\/wp\/v2\/media\/2120"}],"wp:attachment":[{"href":"http:\/\/gnn.club\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2117"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/gnn.club\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2117"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/gnn.club\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2117"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}