{"id":3802,"date":"2021-04-25T14:19:46","date_gmt":"2021-04-25T06:19:46","guid":{"rendered":"http:\/\/www.sniper97.cn\/?p=3802"},"modified":"2021-04-25T14:19:46","modified_gmt":"2021-04-25T06:19:46","slug":"%e3%80%90%e6%b7%b1%e5%ba%a6%e5%ad%a6%e4%b9%a0%e7%ac%94%e8%ae%b0%e3%80%91%e5%8f%82%e6%95%b0%e6%bb%91%e5%8a%a8%e5%b9%b3%e5%9d%87","status":"publish","type":"post","link":"http:\/\/www.sniper97.cn\/index.php\/note\/deep-learning\/note-deep-learning\/3802\/","title":{"rendered":"\u3010\u6df1\u5ea6\u5b66\u4e60\u7b14\u8bb0\u3011\u53c2\u6570\u6ed1\u52a8\u5e73\u5747EMA"},"content":{"rendered":"\n<p>\u6ed1\u52a8\u5e73\u5747\uff08exponential mobing average\uff09\uff0c\u4e5f\u53eb\u505a\u6307\u6570\u52a0\u6743\u5e73\u5747\uff08exponentially weighted moving average\uff09\uff0c\u53ef\u4ee5\u7528\u6765\u4f30\u8ba1\u53d8\u91cf\u7684\u5c40\u90e8\u503c\uff0c\u662f\u7684\u53d8\u91cf\u7684\u66f4\u65b0\u4e0e\u4e00\u6bb5\u65f6\u95f4\u5185\u7684\u5386\u53f2\u503c\u6709\u5173\u3002<\/p>\n\n\n<p>\u6bd4\u5982\u4e0b\u56fe\uff1a<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"594\" height=\"399\" src=\"\/wp-content\/uploads\/2021\/04\/\u56fe\u7247-6.png\" alt=\"\" class=\"wp-image-3803\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2021\/04\/\u56fe\u7247-6.png 594w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2021\/04\/\u56fe\u7247-6-300x202.png 300w\" sizes=\"(max-width: 594px) 100vw, 594px\" \/><\/figure><\/div>\n\n\n<p>\u5c31\u662f\u4e0d\u4f7f\u7528\u6ed1\u52a8\u5e73\u5747\u548c\u4f7f\u7528\u6ed1\u52a8\u5e73\u5747\u7684\u533a\u522b\u3002\u53ef\u4ee5\u53d1\u73b0\u4f7f\u7528\u6ed1\u52a8\u5e73\u5747\u540e\uff0c\u503c\u66f4\u80fd\u53cd\u5e94\u7ed3\u679c\u5728\u4e00\u6bb5\u65f6\u95f4\u5185\u7684\u53d8\u5316\u3002<\/p>\n\n\n<p>\u90a3\u8fd9\u4e2a\u56fe\u662f\u4e0d\u662f\u548cbatch\u4e0b\u7684\u7ed3\u679c\u5f88\u50cf\u5462\uff1f\u5982\u679c\u6211\u4eec\u5bf9\u7f51\u7edc\u53c2\u6570\u8fdb\u884c\u6ed1\u52a8\u5e73\u5747\uff0c\u8fd9\u6837\u5c31\u4f1a\u4f7f\u5f97\u7f51\u7edc\u5177\u6709\u66f4\u597d\u7684\u9c81\u68d2\u6027\uff08robust\uff09\u3002<\/p>\n\n\n<p>\u56e0\u6b64\u8fd9\u4e2a\u65b9\u6cd5\u901a\u5e38\u5728\u6d4b\u8bd5\u6570\u636e\u4e0a\u4f7f\u7528\u3002\u5728\u91c7\u7528\u968f\u673a\u68af\u5ea6\u4e0b\u964d\u7b97\u6cd5\u8bad\u7ec3\u7684\u6a21\u578b\u4e2d\uff0c\u4f7f\u7528\u6ed1\u52a8\u5e73\u5747\u5728\u5f88\u591a\u573a\u666f\u4e0b\u90fd\u53ef\u4ee5\u63d0\u9ad8\u6700\u7ec8\u6a21\u578b\u5728\u6d4b\u8bd5\u96c6\u4e0a\u7684\u8868\u73b0\u3002<\/p>\n\n\n<p>\u56e0\u4e3aEMA\u7ef4\u62a4\u4e86\u4e00\u4e2ashadow weight\uff0c\u8fd9\u4e2ashadow weight\u5c31\u662f\u4eceweight\u4e0a\u5e73\u5747\u800c\u6765\u7684\uff0c\u4e5f\u5c31\u5177\u5907\u4e86\u66f4\u591a\u7684\u9c81\u68d2\u6027\u3002\u800c\u8bad\u7ec3\u9636\u6bb5\uff0c\u6211\u4eec\u9700\u8981\u771f\u5b9e\u7684weight\u6765\u8fdb\u884c\u4e0b\u4e00\u6b21\u68af\u5ea6\u4e0b\u964d\u3002<\/p>\n\n\n<p>\u800c\u53c2\u6570decay[ema_momentum]\u5219\u662f\u6296\u52a8\u7a0b\u5ea6\uff0c\u5982\u679cdecay=0.999\uff0c\u76f4\u89c2\u6765\u8bf4\u5219\u662f\u5c06\u6700\u540e1000\u6b21\u7684\u8bad\u7ec3\u6296\u52a8\u8fdb\u884c\u4e86\u5e73\u5747\u3002<\/p>\n\n\n<p>\u90a3\u4e48\u600e\u4e48\u4f7f\u7528\u5462\uff1f<\/p>\n\n\n<p>\u4e0b\u9762\u63cf\u8ff0\u5728bert4keras\u4e2d\u5982\u4f55\u4f7f\u7528ema\u5e73\u6ed1\u3002<\/p>\n\n\n<p>\u5728\u4f18\u5316\u5668\u5b9a\u4e49\u65f6\uff1a<\/p>\n\n\n<pre class=\"wp-block-code\"><code>from bert4keras.optimizers import Adam, extend_with_exponential_moving_average\nAdamEMA = extend_with_exponential_moving_average(Adam, 'AdamEMA')\noptimizer = AdamEMA(learning_rate, ema_momentum=0.999)<\/code><\/pre>\n\n\n<p>\u5728\u6d4b\u8bd5\u65f6\uff1a<\/p>\n\n\n<pre class=\"wp-block-code\"><code>optimizer.apply_ema_weights()\nres = model.predict(data)\noptimizer.reset_old_weights()<\/code><\/pre>\n\n\n<p>\u4e4b\u6240\u4ee5\u5728\u6d4b\u8bd5\u7684\u65f6\u5019\u8981\u5e94\u7528\uff0c\u800c\u6d4b\u8bd5\u4e4b\u540e\u6062\u590d\uff0c\u662f\u56e0\u4e3a\u8fd9\u4e2a\u5e73\u5747\uff0c\u53ea\u5728\u6d4b\u8bd5\u9636\u6bb5\u624d\u6709\u6548\uff0c\u8bad\u7ec3\u9636\u6bb5\u8fd8\u662f\u8981\u6839\u636e\u5b9e\u9645\u6570\u636e\u5f97\u51fa\u7ed3\u679c\uff08\u56e0\u4e3a\u53c2\u6570\u5e73\u5747\u662f\u6839\u636e\u771f\u5b9e\u7ed3\u679c\u8fdb\u884c\u5e73\u5747\uff09\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6ed1\u52a8\u5e73\u5747\uff08exponential mobing average\uff09\uff0c\u4e5f\u53eb\u505a\u6307\u6570\u52a0\u6743\u5e73\u5747\uff08exponen [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[9],"tags":[37,39],"views":4467,"_links":{"self":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/3802"}],"collection":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/comments?post=3802"}],"version-history":[{"count":0,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/3802\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/media?parent=3802"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/categories?post=3802"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/tags?post=3802"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}