{"id":22997,"date":"2024-12-16T10:01:57","date_gmt":"2024-12-16T02:01:57","guid":{"rendered":"http:\/\/139.9.1.231\/?p=22997"},"modified":"2025-06-20T17:36:20","modified_gmt":"2025-06-20T09:36:20","slug":"non-causal-convolutioncausal-convolution","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2024\/12\/16\/non-causal-convolutioncausal-convolution\/","title":{"rendered":"\u975e\u56e0\u679c\u5377\u79ef\/\u56e0\u679c\u5377\u79ef"},"content":{"rendered":"\n<h2> <strong>\u56e0\u679c\u5377\u79ef:<\/strong><\/h2>\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\/2025\/06\/image-47.png\" alt=\"\" class=\"wp-image-27016\" width=\"445\" height=\"330\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2025\/06\/image-47.png 979w, http:\/\/139.9.1.231\/wp-content\/uploads\/2025\/06\/image-47-300x223.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2025\/06\/image-47-768x570.png 768w\" sizes=\"(max-width: 445px) 100vw, 445px\" \/><\/figure><\/div>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"373\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2024\/12\/image-35-1024x373.png\" alt=\"\" class=\"wp-image-23021\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2024\/12\/image-35-1024x373.png 1024w, http:\/\/139.9.1.231\/wp-content\/uploads\/2024\/12\/image-35-300x109.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2024\/12\/image-35-768x280.png 768w, http:\/\/139.9.1.231\/wp-content\/uploads\/2024\/12\/image-35.png 1063w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u56e0\u679c\u5377\u79ef\u53ef\u4ee5\u7528\u4e0a\u56fe\u76f4\u89c2\u8868\u793a\u3002\u5373\u5bf9\u4e8e\u4e0a\u4e00\u5c42<em>t<\/em>\u65f6\u523b\u7684\u503c\uff0c\u53ea\u4f9d\u8d56\u4e8e\u4e0b\u4e00\u5c42<em>t<\/em>\u65f6\u523b\u53ca\u5176\u4e4b\u524d\u7684\u503c\u3002\u548c\u4f20\u7edf\u7684\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\u7684\u4e0d\u540c\u4e4b\u5904\u5728\u4e8e\uff0c\u56e0\u679c\u5377\u79ef\u4e0d\u80fd\u770b\u5230\u672a\u6765\u7684\u6570\u636e\uff0c\u5b83\u662f\u5355\u5411\u7684\u7ed3\u6784\uff0c\u4e0d\u662f\u53cc\u5411\u7684\u3002\u4e5f\u5c31\u662f\u8bf4\u53ea\u6709\u6709\u4e86\u524d\u9762\u7684\u56e0\u624d\u6709\u540e\u9762\u7684\u679c\uff0c\u662f\u4e00\u79cd\u4e25\u683c\u7684\u65f6\u95f4\u7ea6\u675f\u6a21\u578b\uff0c\u56e0\u6b64\u88ab\u6210\u4e3a\u56e0\u679c\u5377\u79ef\u3002<\/p>\n\n\n\n<p><strong>\u4e0a\u9762\u7684\u56fe\u7247\u53ef\u4ee5\u8be6\u7ec6\u7684\u89e3\u91ca\u56e0\u679c\u5377\u79ef\uff0c\u4f46\u662f\u95ee\u9898\u5c31\u6765\uff0c\u5982\u679c\u6211\u8981\u8003\u8651\u5f88\u4e45\u4e4b\u524d\u7684\u53d8\u91cfx\uff0c\u90a3\u4e48\u5377\u79ef\u5c42\u6570\u5c31\u5fc5\u987b\u589e\u52a0\uff08\u81ea\u884c\u4f53\u4f1a\uff09\u3002\u3002\u3002\u5377\u79ef\u5c42\u6570\u7684\u589e\u52a0\u5c31\u5e26\u6765\uff1a\u68af\u5ea6\u6d88\u5931\uff0c\u8bad\u7ec3\u590d\u6742\uff0c\u62df\u5408\u6548\u679c\u4e0d\u597d\u7684\u95ee\u9898\uff0c\u4e3a\u4e86\u51b3\u7edd\u8fd9\u4e2a\u95ee\u9898\uff0c\u51fa\u73b0\u4e86\u6269\u5c55\u5377\u79ef\uff08dilated\uff09<\/strong><\/p>\n\n\n\n<p>(1) <strong>\u6d41\u5f0f\u63a8\u7406\u4e2d\u7684\u5377\u79ef\u8981\u6c42<\/strong><\/p>\n\n\n\n<ul><li><strong>\u65e0\u672a\u6765\u4fe1\u606f\u4f9d\u8d56<\/strong>\uff1a\u5377\u79ef\u6838\u53ea\u80fd\u8bbf\u95ee\u5f53\u524d\u53ca\u4e4b\u524d\u7684\u8f93\u5165\uff0c\u4e0d\u5141\u8bb8\u8bbf\u95ee\u672a\u6765\u8f93\u5165\u3002<\/li><li><strong>\u56e0\u679c\u5377\u79ef\uff08Causal Convolution\uff09<\/strong>\uff1a\u901a\u8fc7\u8c03\u6574\u5377\u79ef\u6838\u7684 Padding\uff0c\u4f7f\u5377\u79ef\u64cd\u4f5c\u4ec5\u4f9d\u8d56\u5386\u53f2\u65f6\u95f4\u6b65\u7684\u6570\u636e\u3002<\/li><\/ul>\n\n\n\n<p>(2) <strong>Padding \u8bbe\u8ba1<\/strong><\/p>\n\n\n\n<ul><li><strong>\u666e\u901a\u5377\u79ef\u7684 Padding<\/strong>\uff1a\u5728\u975e\u6d41\u5f0f\u6a21\u578b\u4e2d\uff0c\u901a\u5e38\u4f7f\u7528 <code>SAME<\/code> Padding\uff08\u5982 TensorFlow \u6216 PyTorch \u7684\u5bf9\u79f0\u586b\u5145\uff09\uff0c\u586b\u5145\u65b9\u5f0f\u4f7f\u5f97\u8f93\u5165\u548c\u8f93\u51fa\u957f\u5ea6\u4e00\u81f4\u3002\u8fd9\u4f1a\u5bfc\u81f4\u5377\u79ef\u6838\u8bbf\u95ee\u672a\u6765\u65f6\u95f4\u6b65\u6570\u636e\uff0c\u65e0\u6cd5\u5b9e\u73b0\u6d41\u5f0f\u63a8\u7406\u3002<\/li><li><strong>\u56e0\u679c\u5377\u79ef\u7684 Padding<\/strong>\uff1a<ul><li><strong>\u5bf9\u5377\u79ef\u6838\u8fdb\u884c\u4e0d\u5bf9\u79f0\u586b\u5145\uff08\u5982\u53ea\u5728\u8f93\u5165\u524d\u4fa7\u586b\u5145\uff09\uff0c\u4f7f\u5f97\u5377\u79ef\u64cd\u4f5c\u4ec5\u4f9d\u8d56\u4e8e\u5f53\u524d\u53ca\u4e4b\u524d\u7684\u65f6\u95f4\u6b65\u3002<\/strong><\/li><li><strong>\u5177\u4f53\u586b\u5145\u91cf = \u5377\u79ef\u6838\u5927\u5c0f &#8211; 1\uff0c\u4f8b\u5982 3&#215;1 \u5377\u79ef\u6838\u7684\u586b\u5145\u91cf\u662f 2\u3002<\/strong><\/li><\/ul><\/li><\/ul>\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\/2025\/06\/image-48.png\" alt=\"\" class=\"wp-image-27018\" width=\"382\" height=\"283\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2025\/06\/image-48.png 979w, http:\/\/139.9.1.231\/wp-content\/uploads\/2025\/06\/image-48-300x223.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2025\/06\/image-48-768x570.png 768w\" sizes=\"(max-width: 382px) 100vw, 382px\" \/><\/figure><\/div>\n\n\n\n<pre class=\"wp-block-code\"><code>import torch\nimport torch.nn as nn\nfrom torch.autograd import Variable\n\n__CUDA__ = torch.cuda.is_available()\n\nclass CausalConv1d(nn.Module):\n    \"\"\"\n    A causal 1D convolution.\n    \"\"\"\n    def __init__(self, kernel_size, in_channels, out_channels, dilation):\n        super(CausalConv1d, self).__init__(self)\n        \n        # attributes:\n        self.kernel_size = kernel_size\n        self.in_channels = in_channels\n        self.dilation = dilation\n        \n        # modules:\n        self.conv1d = torch.nn.Conv1d(in_channels, out_channels,\n                                      kernel_size, stride=1,\n                                      padding=padding = (kernel_size-1) * dilation,\n                                      dilation=dilation)\n\n    def forward(self, seq):\n        \"\"\"\n        Note that Conv1d expects (batch, in_channels, in_length).\n        We assume that seq ~ (len(seq), batch, in_channels), so we'll reshape it first.\n        \"\"\"\n        seq_ = seq.permute(1,2,0)\n        conv1d_out = self.conv1d(seq_).permute(2,0,1)\n        # remove k-1 values from the end:\n        return conv1d_out&#91;0:-(self.kernel_size-1)]<\/code><\/pre>\n\n\n\n<h2><strong>\u6269\u5c55\u56e0\u679c\u5377\u79ef\uff1a\u3010\u7a7a\u6d1e\u56e0\u679c\u5377\u79ef Dilated causal Conv\u3011<\/strong><\/h2>\n\n\n\n<p>\u5bf9\u4e8e\u56e0\u679c\u5377\u79ef\uff0c<strong>\u5b58\u5728\u7684\u4e00\u4e2a\u95ee\u9898\u662f\u9700\u8981\u5f88\u591a\u5c42\u6216\u8005\u5f88\u5927\u7684filter\u6765\u589e\u52a0\u5377\u79ef\u7684\u611f\u53d7\u91ce\u3002<\/strong>\u6269\u5927\u5377\u79ef\uff08dilated convolution\uff09\u662f\u901a\u8fc7\u8df3\u8fc7\u90e8\u5206\u8f93\u5165\u6765\u4f7ffilter\u53ef\u4ee5\u5e94\u7528\u4e8e\u5927\u4e8efilter\u672c\u8eab\u957f\u5ea6\u7684\u533a\u57df\u3002<strong>\u7b49\u540c\u4e8e\u901a\u8fc7\u589e\u52a0\u96f6\u6765\u4ece\u539f\u59cbfilter\u4e2d\u751f\u6210\u66f4\u5927\u7684filter\u3002<\/strong><\/p>\n\n\n\n<p>dilated\u7684\u597d\u5904\u662f\u4e0d\u505apooling\u635f\u5931\u4fe1\u606f\u7684\u60c5\u51b5\u4e0b\uff0c\u52a0\u5927\u4e86\u611f\u53d7\u91ce\uff0c\u8ba9\u6bcf\u4e2a\u5377\u79ef\u8f93\u51fa\u90fd\u5305\u542b\u8f83\u5927\u8303\u56f4\u7684\u4fe1\u606f\u3002\u5728\u56fe\u50cf\u9700\u8981\u5168\u5c40\u4fe1\u606f\u6216\u8005\u8bed\u97f3\u6587\u672c\u9700\u8981\u8f83\u957f\u7684sequence\u4fe1\u606f\u4f9d\u8d56\u7684\u95ee\u9898\u4e2d\uff0c\u90fd\u80fd\u5f88\u597d\u7684\u5e94\u7528dilated conv\uff0c\u6bd4\u5982\u56fe\u50cf\u5206\u5272\u3001\u8bed\u97f3\u5408\u6210WaveNet\u3001\u673a\u5668\u7ffb\u8bd1ByteNet\u4e2d.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"331\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2024\/12\/image-36-1024x331.png\" alt=\"\" class=\"wp-image-23033\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2024\/12\/image-36-1024x331.png 1024w, http:\/\/139.9.1.231\/wp-content\/uploads\/2024\/12\/image-36-300x97.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2024\/12\/image-36-768x248.png 768w, http:\/\/139.9.1.231\/wp-content\/uploads\/2024\/12\/image-36.png 1507w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2>Normalization \u5c42\u7684\u9009\u62e9\u4e0e\u8c03\u6574<\/h2>\n\n\n\n<p>Normalization \u662f\u6d41\u5f0f\u63a8\u7406\u4e2d\u53e6\u4e00\u4e2a\u5173\u952e\u6311\u6218\u3002<strong>\u666e\u901a\u7684\u6279\u5f52\u4e00\u5316\uff08Batch Normalization, BN\uff09\u9700\u8981\u8ba1\u7b97\u5168\u5c40\u7edf\u8ba1\u91cf\uff08\u5982\u5747\u503c\u548c\u65b9\u5dee\uff09\uff0c\u8fd9\u5728\u6d41\u5f0f\u63a8\u7406\u4e2d\u662f\u4e0d\u53ef\u80fd\u5b9e\u73b0\u7684\u3002<\/strong><\/p>\n\n\n\n<h4>(1) <strong>Batch Normalization \u7684\u95ee\u9898<\/strong><\/h4>\n\n\n\n<ul><li>\u9700\u8981\u6574\u4e2a\u6279\u6b21\u7684\u6570\u636e\u6765\u8ba1\u7b97\u7edf\u8ba1\u91cf\uff0c\u65e0\u6cd5\u5728\u5355\u6b65\u6d41\u5f0f\u63a8\u7406\u4e2d\u5b9e\u73b0\u3002<\/li><li>\u901a\u5e38\u5728\u8bad\u7ec3\u9636\u6bb5\u4f7f\u7528 <code>batch statistics<\/code>\uff0c\u5728\u63a8\u7406\u9636\u6bb5\u4f7f\u7528 <code>running statistics<\/code>\u3002<\/li><\/ul>\n\n\n\n<h4>(2) <strong>\u89e3\u51b3\u65b9\u6cd5<\/strong><\/h4>\n\n\n\n<p><strong>Layer Normalization (LN)<\/strong>\uff1a<\/p>\n\n\n\n<ul><li>\u4e0d\u4f9d\u8d56\u4e8e\u6279\u6b21\uff0c\u800c\u662f\u5bf9\u6bcf\u4e2a\u6837\u672c\u7684\u7279\u5f81\u7ef4\u5ea6\u8fdb\u884c\u5f52\u4e00\u5316\uff0c\u975e\u5e38\u9002\u5408\u6d41\u5f0f\u63a8\u7406\u3002<\/li><\/ul>\n\n\n\n<p><strong>Instance Normalization (IN)<\/strong>\uff1a<\/p>\n\n\n\n<ul><li>\u7c7b\u4f3c\u4e8e Layer Normalization\uff0c\u4f46\u64cd\u4f5c\u5728\u6bcf\u4e2a\u6837\u672c\u7684\u7a7a\u95f4\u7ef4\u5ea6\u4e0a\u8fdb\u884c\u5f52\u4e00\u5316\u3002<\/li><\/ul>\n\n\n\n<p><strong>Group Normalization (GN)<\/strong>\uff1a<\/p>\n\n\n\n<ul><li>\u4ecb\u4e8e Batch \u548c Layer Normalization \u4e4b\u95f4\uff0c\u5c06\u7279\u5f81\u5212\u5206\u4e3a\u7ec4\uff0c\u5e76\u5728\u7ec4\u5185\u8fdb\u884c\u5f52\u4e00\u5316\u3002<\/li><\/ul>\n\n\n\n<p><strong>Online Normalization\uff08\u81ea\u56de\u5f52\u7edf\u8ba1\uff09<\/strong>\uff1a<\/p>\n\n\n\n<ul><li>\u901a\u8fc7\u6ed1\u52a8\u7a97\u53e3\u6216\u6307\u6570\u79fb\u52a8\u5e73\u5747\uff08EMA\uff09\u8ba1\u7b97\u5c40\u90e8\u7edf\u8ba1\u91cf\uff0c\u4ec5\u4f9d\u8d56\u8fc7\u53bb\u7684\u4fe1\u606f\u3002<\/li><li>\u8fd9\u79cd\u65b9\u6cd5\u7279\u522b\u9002\u5408\u6d41\u5f0f\u63a8\u7406\uff0c\u4f46\u5b9e\u73b0\u8f83\u4e3a\u590d\u6742\u3002<\/li><\/ul>\n\n\n\n<h2><strong>\u5b9e\u8df5\u4e2d\u7684\u6d41\u5f0f\u63a8\u7406\u8bbe\u7f6e<\/strong><\/h2>\n\n\n\n<p>\u7ed3\u5408\u4ee5\u4e0a\u4e24\u70b9\uff0c\u5177\u4f53\u5b9e\u73b0\u6d41\u5f0f\u6a21\u578b\u65f6\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n\n\n\n<ol><li><strong>\u5377\u79ef\u5c42<\/strong>\uff1a<ul><li>\u66ff\u6362\u666e\u901a\u5377\u79ef\u4e3a\u56e0\u679c\u5377\u79ef\u3002<\/li><li>\u5982\u679c\u4f7f\u7528\u6269\u5f20\u5377\u79ef\uff08Dilated Convolution\uff09\uff0c\u9700\u8981\u4fdd\u8bc1\u6240\u6709\u5c42\u7684 Padding \u7b26\u5408\u56e0\u679c\u903b\u8f91\u3002<\/li><\/ul><\/li><li><strong>\u5f52\u4e00\u5316\u5c42<\/strong>\uff1a<ul><li>\u66ff\u6362 <code>BatchNorm<\/code> \u4e3a <code>LayerNorm<\/code> \u3002<\/li><li>\u5728\u9700\u8981\u65f6\uff0c\u5f15\u5165\u81ea\u56de\u5f52\u7edf\u8ba1\u673a\u5236\u3002<\/li><\/ul><\/li><li><strong>\u6846\u67b6\u652f\u6301<\/strong>\uff1a<ul><li>\u786e\u4fdd\u6a21\u578b\u5728\u6d41\u5f0f\u8f93\u5165\u4e2d\u53ef\u4ee5\u9010\u6b65\u66f4\u65b0\u8f93\u5165\u7a97\u53e3\uff08\u5982\u65f6\u95f4\u5e8f\u5217\u5207\u7247\uff09\u3002<\/li><\/ul><\/li><\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u56e0\u679c\u5377\u79ef: \u56e0\u679c\u5377\u79ef\u53ef\u4ee5\u7528\u4e0a\u56fe\u76f4\u89c2\u8868\u793a\u3002\u5373\u5bf9\u4e8e\u4e0a\u4e00\u5c42t\u65f6\u523b\u7684\u503c\uff0c\u53ea\u4f9d\u8d56\u4e8e\u4e0b\u4e00\u5c42t\u65f6\u523b\u53ca\u5176\u4e4b\u524d\u7684\u503c\u3002\u548c\u4f20\u7edf\u7684\u5377\u79ef &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2024\/12\/16\/non-causal-convolutioncausal-convolution\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u975e\u56e0\u679c\u5377\u79ef\/\u56e0\u679c\u5377\u79ef<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[40,4,9,38,34],"tags":[],"_links":{"self":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/22997"}],"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=22997"}],"version-history":[{"count":29,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/22997\/revisions"}],"predecessor-version":[{"id":27019,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/22997\/revisions\/27019"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=22997"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=22997"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=22997"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}