{"id":15914,"date":"2026-04-26T08:30:41","date_gmt":"2026-04-26T00:30:41","guid":{"rendered":"https:\/\/top.duoku.icu\/libs\/15914.html"},"modified":"2026-04-26T08:30:41","modified_gmt":"2026-04-26T00:30:41","slug":"%e6%b1%a0%e5%8c%96%e6%8a%80%e6%9c%af%e8%af%a6%e8%a7%a3%ef%bc%9a%e6%b7%b1%e5%ba%a6%e5%ad%a6%e4%b9%a0%e4%b8%ad%e7%9a%84%e9%99%8d%e7%bb%b4%e8%89%ba%e6%9c%af","status":"publish","type":"post","link":"https:\/\/www.srclibs.com\/index.php\/2026\/04\/26\/%e6%b1%a0%e5%8c%96%e6%8a%80%e6%9c%af%e8%af%a6%e8%a7%a3%ef%bc%9a%e6%b7%b1%e5%ba%a6%e5%ad%a6%e4%b9%a0%e4%b8%ad%e7%9a%84%e9%99%8d%e7%bb%b4%e8%89%ba%e6%9c%af\/","title":{"rendered":"\u6c60\u5316\u6280\u672f\u8be6\u89e3\uff1a\u6df1\u5ea6\u5b66\u4e60\u4e2d\u7684\u964d\u7ef4\u827a\u672f"},"content":{"rendered":"<div style=\"text-align:center;margin:30px 0;\"><img decoding=\"async\" src=\"https:\/\/top.duoku.icu\/wp-content\/uploads\/2026\/04\/image-84.png\" alt=\"\u6c60\u5316\u6280\u672f\u8be6\u89e3\uff1a\u6df1\u5ea6\u5b66\u4e60\u4e2d\u7684\u964d\u7ef4\u827a\u672f\" style=\"max-width:100%;height:auto;border-radius:12px;box-shadow:0 4px 12px rgba(0,0,0,0.1);\"><\/div>\n<h1>\u6c60\u5316\u6280\u672f\u8be6\u89e3\uff1a\u6df1\u5ea6\u5b66\u4e60\u4e2d\u7684\u964d\u7ef4\u827a\u672f<\/h1>\n<h2>\u5f15\u8a00<\/h2>\n<p>\u5728\u6df1\u5ea6\u5b66\u4e60\u7684\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\uff08CNN\uff09\u4e2d\uff0c\u6c60\u5316\u5c42\u662f\u4e00\u4e2a\u4e0d\u53ef\u6216\u7f3a\u7684\u91cd\u8981\u7ec4\u6210\u90e8\u5206\u3002\u5b83\u5c31\u50cf\u662f\u89c6\u89c9\u7cfb\u7edf\u7684&#8221;\u6ce8\u610f\u529b\u673a\u5236&#8221;\uff0c\u5e2e\u52a9\u7f51\u7edc\u805a\u7126\u4e8e\u6700\u91cd\u8981\u7684\u7279\u5f81\uff0c\u540c\u65f6\u964d\u4f4e\u8ba1\u7b97\u590d\u6742\u5ea6\u3002\u672c\u6587\u5c06\u6df1\u5165\u6d45\u51fa\u5730\u89e3\u6790\u6c60\u5316\u6280\u672f\u7684\u539f\u7406\u3001\u5b9e\u73b0\u548c\u5e94\u7528\u3002<\/p>\n<h2>\u4e00\u3001\u4ec0\u4e48\u662f\u6c60\u5316\u6280\u672f<\/h2>\n<h3>1.1 \u57fa\u672c\u6982\u5ff5<\/h3>\n<p>\u6c60\u5316\uff08Pooling\uff09\u662f\u4e00\u79cd\u4e0b\u91c7\u6837\uff08Downsampling\uff09\u64cd\u4f5c\uff0c\u5176\u6838\u5fc3\u76ee\u7684\u662f\uff1a<\/p>\n<ul>\n<li><strong>\u964d\u4f4e\u7279\u5f81\u56fe\u7ef4\u5ea6<\/strong>\uff1a\u51cf\u5c11\u6570\u636e\u91cf\u548c\u8ba1\u7b97\u91cf<\/li>\n<li><strong>\u4fdd\u7559\u91cd\u8981\u7279\u5f81<\/strong>\uff1a\u63d0\u53d6\u4e3b\u8981\u7684\u89c6\u89c9\u7279\u5f81<\/li>\n<li><strong>\u589e\u52a0\u611f\u53d7\u91ce<\/strong>\uff1a\u6269\u5927\u7f51\u7edc\u5bf9\u8f93\u5165\u56fe\u50cf\u7684\u611f\u77e5\u8303\u56f4<\/li>\n<li><strong>\u9632\u6b62\u8fc7\u62df\u5408<\/strong>\uff1a\u901a\u8fc7\u964d\u7ef4\u51cf\u5c11\u6a21\u578b\u590d\u6742\u5ea6<\/li>\n<\/ul>\n<h3>1.2 \u5f62\u8c61\u7406\u89e3<\/h3>\n<p>\u60f3\u8c61\u4f60\u5728\u6d4f\u89c8\u4e00\u5f20\u9ad8\u6e05\u7167\u7247\uff0c\u6c60\u5316\u64cd\u4f5c\u5c31\u50cf\u662f\uff1a<\/p>\n<ul>\n<li><strong>\u6700\u5927\u6c60\u5316<\/strong>\uff1a\u53ea\u4fdd\u7559\u6bcf\u5f20\u5c40\u90e8\u533a\u57df\u4e2d\u6700\u4eae\u7684\u50cf\u7d20<\/li>\n<li><strong>\u5e73\u5747\u6c60\u5316<\/strong>\uff1a\u8ba1\u7b97\u6bcf\u5f20\u5c40\u90e8\u533a\u57df\u7684\u5e73\u5747\u4eae\u5ea6<\/li>\n<\/ul>\n<p>\u8fd9\u6837\uff0c\u4f60\u65e2\u80fd\u628a\u63e1\u6574\u4f53\u8f6e\u5ed3\uff0c\u53c8\u4e0d\u9700\u8981\u8bb0\u4f4f\u6bcf\u4e00\u4e2a\u7ec6\u8282\u3002<\/p>\n<h2>\u4e8c\u3001\u6c60\u5316\u6280\u672f\u7684\u5de5\u4f5c\u539f\u7406<\/h2>\n<h3>2.1 \u6838\u5fc3\u64cd\u4f5c<\/h3>\n<p>\u6c60\u5316\u64cd\u4f5c\u901a\u8fc7\u4e00\u4e2a\u56fa\u5b9a\u7684\u7a97\u53e3\uff08Kernel\uff09\u5728\u7279\u5f81\u56fe\u4e0a\u6ed1\u52a8\uff0c\u5bf9\u6bcf\u4e2a\u7a97\u53e3\u5185\u7684\u503c\u8fdb\u884c\u805a\u5408\uff1a<\/p>\n<pre><code>\u8f93\u5165\u7279\u5f81\u56fe\uff1a\n[[1, 3, 2, 4],\n [5, 1, 6, 2],\n [3, 7, 1, 8],\n [2, 4, 5, 1]]\n\n\u6c60\u5316\u7a97\u53e3\u5927\u5c0f\uff1a2\u00d72\uff0c\u6b65\u957f\uff1a2\n\n\u8f93\u51fa\u7279\u5f81\u56fe\uff08\u6700\u5927\u6c60\u5316\uff09\uff1a\n[[5, 4],\n [7, 8]]\n<\/code><\/pre>\n<h3>2.2 \u5e38\u89c1\u6c60\u5316\u7c7b\u578b<\/h3>\n<h4>\u6700\u5927\u6c60\u5316\uff08Max Pooling\uff09<\/h4>\n<p>\u53d6\u7a97\u53e3\u5185\u7684\u6700\u5927\u503c\uff0c\u80fd\u591f\u4fdd\u7559\u6700\u663e\u8457\u7684\u7279\u5f81\u3002<\/p>\n<p>&#8220;`python<br \/>\nimport numpy as np<\/p>\n<p>def max_pooling(input_matrix, pool_size=2, stride=2):<br \/>\n    &#8220;&#8221;&#8221;<br \/>\n    \u6700\u5927\u6c60\u5316\u64cd\u4f5c<\/p>\n<p>    \u53c2\u6570\uff1a<br \/>\n        input_matrix: \u8f93\u5165\u7279\u5f81\u56fe (numpy \u6570\u7ec4)<br \/>\n        pool_size: \u6c60\u5316\u7a97\u53e3\u5927\u5c0f<br \/>\n        stride: \u6b65\u957f<\/p>\n<p>    \u8fd4\u56de\uff1a<br \/>\n        \u6c60\u5316\u540e\u7684\u7279\u5f81\u56fe<br \/>\n    &#8220;&#8221;&#8221;<br \/>\n    batch_size, height, width, channels = input_matrix.shape<\/p>\n<p>    # \u8ba1\u7b97\u8f93\u51fa\u5c3a\u5bf8<br \/>\n    out_height = (height &#8211; pool_size) \/\/ stride + 1<br \/>\n    out_width = (width &#8211; pool_size) \/\/ stride + 1<\/p>\n<p>    # \u521d\u59cb\u5316\u8f93\u51fa<br \/>\n    output = np.zeros((batch_size, out_height, out_width, channels))<\/p>\n<p>    for i in range(out_height):<br \/>\n        for j in range(out_width):<br \/>\n            h_start, h_end = i * stride, i * stride + pool_size<br \/>\n            w_start, w_end = j * stride, j * stride + pool_size<\/p>\n<p>            # \u53d6\u7a97\u53e3\u5185\u7684\u6700\u5927\u503c<br \/>\n            pool_region = input_matrix[:, h_start:h_end, w_start:w_end, :]<br \/>\n            output[:, i, j, :] = np.max(pool_region, axis=(1, 2))<\/p>\n<p>    return output<\/p>\n<h1>\u4f7f\u7528\u793a\u4f8b<\/h1>\n<p>input_data = np.random.rand(1, 4, 4, 1) * 10<br \/>\npooled_data = max_pooling(input_data, pool_size=2, stride=2)<br \/>\nprint(f&#8221;\u8f93\u5165\u5f62\u72b6\uff1a{input_data.shape}&#8221;)<br \/>\nprint(f&#8221;\u8f93\u51fa\u5f62\u72b6\uff1a{pooled_data.shape}&#8221;)<\/p>\n<pre><code>\n<h4>\u5e73\u5747\u6c60\u5316\uff08Average Pooling\uff09<\/h4>\n\n\u53d6\u7a97\u53e3\u5185\u7684\u5e73\u5747\u503c\uff0c\u80fd\u591f\u4fdd\u7559\u6574\u4f53\u4fe1\u606f\u3002\n\n<\/code><\/pre>\n<p>python<br \/>\ndef average_pooling(input_matrix, pool_size=2, stride=2):<br \/>\n    &#8220;&#8221;&#8221;\u5e73\u5747\u6c60\u5316\u64cd\u4f5c&#8221;&#8221;&#8221;<br \/>\n    batch_size, height, width, channels = input_matrix.shape<\/p>\n<p>    out_height = (height &#8211; pool_size) \/\/ stride + 1<br \/>\n    out_width = (width &#8211; pool_size) \/\/ stride + 1<\/p>\n<p>    output = np.zeros((batch_size, out_height, out_width, channels))<\/p>\n<p>    for i in range(out_height):<br \/>\n        for j in range(out_width):<br \/>\n            h_start, h_end = i * stride, i * stride + pool_size<br \/>\n            w_start, w_end = j * stride, j * stride + pool_size<\/p>\n<p>            pool_region = input_matrix[:, h_start:h_end, w_start:w_end, :]<br \/>\n            output[:, i, j, :] = np.mean(pool_region, axis=(1, 2))<\/p>\n<p>    return output<\/p>\n<pre><code>\n<h4>\u5176\u4ed6\u6c60\u5316\u7c7b\u578b<\/h4>\n\n<ul>\n<li><strong>\u5168\u5c40\u5e73\u5747\u6c60\u5316\uff08Global Average Pooling\uff09<\/strong>\uff1a\u5bf9\u6574\u5f20\u7279\u5f81\u56fe\u53d6\u5e73\u5747<\/li>\n<li><strong>\u968f\u673a\u6c60\u5316\uff08Stochastic Pooling\uff09<\/strong>\uff1a\u6309\u6982\u7387\u9009\u62e9\u503c\uff0c\u589e\u52a0\u968f\u673a\u6027<\/li>\n<li><strong>Lp \u6c60\u5316<\/strong>\uff1a\u53d6 p \u6b21\u65b9\u540e\u5e73\u5747\u518d\u5f00 p \u6b21\u65b9<\/li>\n<\/ul>\n\n<h3>2.3 \u6c60\u5316\u53c2\u6570<\/h3>\n\n<table border=\"1\" cellpadding=\"5\">\n  <tr>\n    <th>\u53c2\u6570<\/th>\n    <th>\u8bf4\u660e<\/th>\n    <th>\u5e38\u7528\u503c<\/th>\n  <\/tr>\n  <tr>\n    <td>pool_size<\/td>\n    <td>\u6c60\u5316\u7a97\u53e3\u5927\u5c0f<\/td>\n    <td>2\u00d72, 3\u00d73<\/td>\n  <\/tr>\n  <tr>\n    <td>stride<\/td>\n    <td>\u6b65\u957f<\/td>\n    <td>\u7b49\u4e8e\u6216\u5927\u4e8e pool_size<\/td>\n  <\/tr>\n  <tr>\n    <td>padding<\/td>\n    <td>\u586b\u5145\u65b9\u5f0f<\/td>\n    <td>'valid', 'same'<\/td>\n  <\/tr>\n  <tr>\n    <td>data_format<\/td>\n    <td>\u6570\u636e\u683c\u5f0f<\/td>\n    <td>'NHWC' \u6216 'NCHW'<\/td>\n  <\/tr>\n<\/table>\n\n<h2>\u4e09\u3001\u4f7f\u7528\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6\u5b9e\u73b0<\/h2>\n\n<h3>3.1 PyTorch \u5b9e\u73b0<\/h3>\n\n<\/code><\/pre>\n<p>python<br \/>\nimport torch<br \/>\nimport torch.nn as nn<\/p>\n<p>class PoolingNetwork(nn.Module):<br \/>\n    &#8220;&#8221;&#8221;\u4f7f\u7528 PyTorch \u5b9e\u73b0\u6c60\u5316\u7f51\u7edc&#8221;&#8221;&#8221;<\/p>\n<p>    def __init__(self):<br \/>\n        super(PoolingNetwork, self).__init__()<\/p>\n<p>        # \u5b9a\u4e49\u5377\u79ef\u5c42<br \/>\n        self.conv1 = nn.Conv2d(1, 32, kernel_size=3, padding=1)<br \/>\n        self.conv2 = nn.Conv2d(32, 64, kernel_size=3, padding=1)<\/p>\n<p>        # \u5b9a\u4e49\u6c60\u5316\u5c42<br \/>\n        self.max_pool = nn.MaxPool2d(kernel_size=2, stride=2)<br \/>\n        self.avg_pool = nn.AvgPool2d(kernel_size=2, stride=2)<\/p>\n<p>        # \u5168\u5c40\u5e73\u5747\u6c60\u5316<br \/>\n        self.global_avg_pool = nn.AdaptiveAvgPool2d((1, 1))<\/p>\n<p>        # \u5168\u8fde\u63a5\u5c42<br \/>\n        self.fc = nn.Linear(64, 10)<\/p>\n<p>    def forward(self, x):<br \/>\n        # \u7b2c\u4e00\u5c42\u5377\u79ef + \u6fc0\u6d3b + \u6700\u5927\u6c60\u5316<br \/>\n        x = self.conv1(x)<br \/>\n        x = torch.relu(x)<br \/>\n        x = self.max_pool(x)  # 4\u00d74 \u2192 2\u00d72<\/p>\n<p>        # \u7b2c\u4e8c\u5c42\u5377\u79ef + \u6fc0\u6d3b + \u5e73\u5747\u6c60\u5316<br \/>\n        x = self.conv2(x)<br \/>\n        x = torch.relu(x)<br \/>\n        x = self.avg_pool(x)  # 2\u00d72 \u2192 1\u00d71<\/p>\n<p>        # \u5168\u5c40\u5e73\u5747\u6c60\u5316 + \u5168\u8fde\u63a5<br \/>\n        x = self.global_avg_pool(x)<br \/>\n        x = x.view(x.size(0), -1)<br \/>\n        x = self.fc(x)<\/p>\n<p>        return x<\/p>\n<h1>\u6d4b\u8bd5\u7f51\u7edc<\/h1>\n<p>model = PoolingNetwork()<br \/>\ninput_tensor = torch.randn(1, 1, 28, 28)<br \/>\noutput = model(input_tensor)<br \/>\nprint(f&#8221;\u8f93\u5165\u5f62\u72b6\uff1a{input_tensor.shape}&#8221;)<br \/>\nprint(f&#8221;\u8f93\u51fa\u5f62\u72b6\uff1a{output.shape}&#8221;)<\/p>\n<pre><code>\n<h3>3.2 TensorFlow\/Keras \u5b9e\u73b0<\/h3>\n\n<\/code><\/pre>\n<p>python<br \/>\nimport tensorflow as tf<br \/>\nfrom tensorflow import keras<br \/>\nfrom tensorflow.keras import layers<\/p>\n<p>def create_pooling_model(input_shape=(28, 28, 1), num_classes=10):<br \/>\n    &#8220;&#8221;&#8221;\u4f7f\u7528 Keras \u521b\u5efa\u5305\u542b\u6c60\u5316\u5c42\u7684\u6a21\u578b&#8221;&#8221;&#8221;<\/p>\n<p>    model = keras.Sequential([<br \/>\n        # \u7b2c\u4e00\u7ec4\u5377\u79ef + \u6c60\u5316<br \/>\n        layers.Conv2D(32, (3, 3), activation=&#8217;relu&#8217;, padding=&#8217;same&#8217;,<br \/>\n                     input_shape=input_shape),<br \/>\n        layers.MaxPooling2D((2, 2)),  # \u4e0b\u91c7\u6837 2 \u500d<\/p>\n<p>        layers.Conv2D(64, (3, 3), activation=&#8217;relu&#8217;, padding=&#8217;same&#8217;),<br \/>\n        layers.MaxPooling2D((2, 2)),  # \u518d\u6b21\u4e0b\u91c7\u6837<\/p>\n<p>        layers.Conv2D(128, (3, 3), activation=&#8217;relu&#8217;, padding=&#8217;same&#8217;),<br \/>\n        layers.GlobalAveragePooling2D(),  # \u5168\u5c40\u5e73\u5747\u6c60\u5316<\/p>\n<p>        # \u5168\u8fde\u63a5\u5c42<br \/>\n        layers.Dense(128, activation=&#8217;relu&#8217;),<br \/>\n        layers.Dropout(0.5),<br \/>\n        layers.Dense(num_classes, activation=&#8217;softmax&#8217;)<br \/>\n    ])<\/p>\n<p>    return model<\/p>\n<h1>\u6784\u5efa\u5e76\u7f16\u8bd1\u6a21\u578b<\/h1>\n<p>model = create_pooling_model()<br \/>\nmodel.compile(<br \/>\n    optimizer=&#8217;adam&#8217;,<br \/>\n    loss=&#8217;sparse_categorical_crossentropy&#8217;,<br \/>\n    metrics=[&#8216;accuracy&#8217;]<br \/>\n)<\/p>\n<p>model.summary()<\/p>\n<pre><code>\n<h2>\u56db\u3001\u5b9e\u9645\u5e94\u7528\u573a\u666f<\/h2>\n\n<h3>4.1 \u56fe\u50cf\u5206\u7c7b<\/h3>\n\n<\/code><\/pre>\n<p>python<\/p>\n<h1>MNIST \u624b\u5199\u6570\u5b57\u8bc6\u522b<\/h1>\n<p>from tensorflow.keras.datasets import mnist<br \/>\nfrom tensorflow.keras.utils import to_categorical<\/p>\n<h1>\u52a0\u8f7d\u6570\u636e<\/h1>\n<p>(x_train, y_train), (x_test, y_test) = mnist.load_data()<\/p>\n<h1>\u9884\u5904\u7406<\/h1>\n<p>x_train = x_train.reshape(-1, 28, 28, 1).astype(&#8216;float32&#8217;) \/ 255.0<br \/>\nx_test = x_test.reshape(-1, 28, 28, 1).astype(&#8216;float32&#8217;) \/ 255.0<br \/>\ny_train = to_categorical(y_train, 10)<br \/>\ny_test = to_categorical(y_test, 10)<\/p>\n<h1>\u521b\u5efa\u6a21\u578b<\/h1>\n<p>model = create_pooling_model()<\/p>\n<h1>\u8bad\u7ec3<\/h1>\n<p>history = model.fit(<br \/>\n    x_train, y_train,<br \/>\n    batch_size=128,<br \/>\n    epochs=10,<br \/>\n    validation_split=0.1,<br \/>\n    verbose=1<br \/>\n)<\/p>\n<h1>\u8bc4\u4f30<\/h1>\n<p>test_loss, test_acc = model.evaluate(x_test, y_test)<br \/>\nprint(f&#8221;\u6d4b\u8bd5\u51c6\u786e\u7387\uff1a{test_acc:.4f}&#8221;)<\/p>\n<pre><code>\n<h3>4.2 \u76ee\u6807\u68c0\u6d4b\u4e2d\u7684\u5e94\u7528<\/h3>\n\n\u5728 Faster R-CNN \u7b49\u76ee\u6807\u68c0\u6d4b\u7b97\u6cd5\u4e2d\uff0c\u6c60\u5316\u5c42\u88ab\u7528\u4e8e\uff1a\n<ul>\n<li><strong>\u7279\u5f81\u63d0\u53d6<\/strong>\uff1a\u4ece\u4e0d\u540c\u5c3a\u5ea6\u7684\u7279\u5f81\u56fe\u4e2d\u63d0\u53d6\u4fe1\u606f<\/li>\n<li><strong>\u533a\u57df\u5efa\u8bae<\/strong>\uff1a\u5bf9\u5019\u9009\u533a\u57df\u8fdb\u884c\u7edf\u4e00\u5c3a\u5bf8\u7684\u7279\u5f81\u63d0\u53d6<\/li>\n<\/ul>\n\n<h3>4.3 \u89c6\u9891\u5904\u7406<\/h3>\n\n\u5728\u89c6\u9891\u5206\u6790\u4efb\u52a1\u4e2d\uff0c3D \u6c60\u5316\u88ab\u5e7f\u6cdb\u5e94\u7528\uff1a\n\n<\/code><\/pre>\n<p>python<\/p>\n<h1>3D \u6c60\u5316\u7528\u4e8e\u89c6\u9891\u5904\u7406<\/h1>\n<p>class VideoClassifier(nn.Module):<br \/>\n    def __init__(self):<br \/>\n        super(VideoClassifier, self).__init__()<\/p>\n<p>        # 3D \u5377\u79ef\u5904\u7406\u89c6\u9891\u5e27\u5e8f\u5217<br \/>\n        self.conv3d = nn.Conv3d(3, 64, kernel_size=(3, 3, 3), padding=1)<\/p>\n<p>        # 3D \u6c60\u5316<br \/>\n        self.pool3d = nn.MaxPool3d(kernel_size=(2, 2, 2), stride=(2, 2, 2))<\/p>\n<p>        self.fc = nn.Linear(64 * 7 * 7, 10)<\/p>\n<p>    def forward(self, x):<br \/>\n        # x: [batch, channels, frames, height, width]<br \/>\n        x = self.conv3d(x)<br \/>\n        x = torch.relu(x)<br \/>\n        x = self.pool3d(x)  # \u5728\u65f6\u95f4\u7ef4\u5ea6\u4e0a\u4e5f\u8fdb\u884c\u4e0b\u91c7\u6837<br \/>\n        x = x.view(x.size(0), -1)<br \/>\n        return self.fc(x)<\/p>\n<pre><code>\n<h2>\u4e94\u3001\u6027\u80fd\u4f18\u5316\u6280\u5de7<\/h2>\n\n<h3>5.1 \u9009\u62e9\u5408\u9002\u7684\u6c60\u5316\u65b9\u5f0f<\/h3>\n\n| \u573a\u666f | \u63a8\u8350\u6c60\u5316\u65b9\u5f0f | \u539f\u56e0 |\n|------|------------|------|\n| \u56fe\u50cf\u5206\u7c7b | MaxPooling | \u4fdd\u7559\u6700\u5f3a\u7279\u5f81 |\n| \u7279\u5f81\u56fe\u538b\u7f29 | AvgPooling | \u4fdd\u7559\u6574\u4f53\u4fe1\u606f |\n| \u5c0f\u6837\u672c\u6570\u636e | GlobalAvgPooling | \u51cf\u5c11\u53c2\u6570\u91cf |\n| \u591a\u5c3a\u5ea6\u68c0\u6d4b | Adaptive Pooling | \u5904\u7406\u4e0d\u540c\u5c3a\u5bf8\u8f93\u5165 |\n\n<h3>5.2 \u6c60\u5316\u4e0e\u5377\u79ef\u7684\u914d\u5408<\/h3>\n\n<\/code><\/pre>\n<p>python<\/p>\n<h1>\u4f18\u5316\u7b56\u7565\uff1a\u4ea4\u66ff\u4f7f\u7528\u4e0d\u540c\u6c60\u5316<\/h1>\n<p>class OptimizedCNN(nn.Module):<br \/>\n    def __init__(self):<br \/>\n        super().__init__()<\/p>\n<p>        # \u4f7f\u7528 1\u00d71 \u5377\u79ef\u8fdb\u884c\u901a\u9053\u964d\u7ef4<br \/>\n        self.channel_reduction = nn.Conv2d(256, 128, kernel_size=1)<\/p>\n<p>        # \u4ea4\u66ff\u4f7f\u7528\u6700\u5927\u6c60\u5316\u548c\u5e73\u5747\u6c60\u5316<br \/>\n        self.pool1 = nn.MaxPool2d(2, 2)<br \/>\n        self.pool2 = nn.AvgPool2d(2, 2)<\/p>\n<p>        self.conv1 = nn.Conv2d(128, 256, 3, padding=1)<\/p>\n<p>    def forward(self, x):<br \/>\n        x = self.pool1(x)      # \u6700\u5927\u6c60\u5316<br \/>\n        x = self.conv1(x)<br \/>\n        x = self.pool2(x)      # \u5e73\u5747\u6c60\u5316<br \/>\n        return x<\/p>\n<pre><code>\n<h3>5.3 \u907f\u514d\u8fc7\u5ea6\u6c60\u5316<\/h3>\n\n<\/code><\/pre>\n<p>python<\/p>\n<h1>\u76d1\u63a7\u7279\u5f81\u56fe\u5c3a\u5bf8\u53d8\u5316<\/h1>\n<p>def analyze_pooling_effect(input_shape=(32, 32, 3)):<br \/>\n    &#8220;&#8221;&#8221;\u5206\u6790\u4e0d\u540c\u6c60\u5316\u7b56\u7565\u5bf9\u7279\u5f81\u56fe\u5c3a\u5bf8\u7684\u5f71\u54cd&#8221;&#8221;&#8221;<\/p>\n<p>    print(f&#8221;\u8f93\u5165\u5c3a\u5bf8\uff1a{input_shape}&#8221;)<\/p>\n<p>    # \u6700\u5927\u6c60\u5316 (2\u00d72, stride=2)<br \/>\n    # \u7b2c 1 \u6b21\uff1a16\u00d716<br \/>\n    # \u7b2c 2 \u6b21\uff1a8\u00d78<br \/>\n    # \u7b2c 3 \u6b21\uff1a4\u00d74<br \/>\n    # \u7b2c 4 \u6b21\uff1a2\u00d72<\/p>\n<p>    # \u5e73\u5747\u6c60\u5316 (3\u00d73, stride=2)<br \/>\n    # \u7b2c 1 \u6b21\uff1a15\u00d715<br \/>\n    # \u7b2c 2 \u6b21\uff1a7\u00d77<br \/>\n    # \u7b2c 3 \u6b21\uff1a3\u00d73<\/p>\n<p>    # \u5168\u5c40\u5e73\u5747\u6c60\u5316<br \/>\n    # \u76f4\u63a5\uff1a1\u00d71<\/p>\n<p>    print(&#8220;\u5efa\u8bae\uff1a\u5728\u6df1\u5c42\u7f51\u7edc\u4e2d\u4f7f\u7528\u5168\u5c40\u5e73\u5747\u6c60\u5316\u4ee3\u66ff\u5168\u8fde\u63a5\u5c42&#8221;)<\/p>\n<p>analyze_pooling_effect()<\/p>\n<pre><code>\n<h2>\u516d\u3001\u5e38\u89c1\u95ee\u9898\u4e0e\u89e3\u51b3\u65b9\u6848<\/h2>\n\n<h3>6.1 \u8fc7\u62df\u5408\u95ee\u9898<\/h3>\n\n<strong>\u95ee\u9898<\/strong>\uff1a\u6c60\u5316\u5c42\u4e0d\u8db3\u5bfc\u81f4\u6a21\u578b\u8fc7\u62df\u5408\n\n<strong>\u89e3\u51b3\u65b9\u6848<\/strong>\uff1a\n<\/code><\/pre>\n<p>python<\/p>\n<h1>\u589e\u52a0\u6c60\u5316\u5c42\u6570\u91cf\u6216\u5f3a\u5ea6<\/h1>\n<p>model = keras.Sequential([<br \/>\n    layers.Conv2D(64, (3, 3), activation=&#8217;relu&#8217;, input_shape=(28, 28, 1)),<br \/>\n    layers.MaxPooling2D((2, 2)),  # \u7b2c\u4e00\u6b21\u4e0b\u91c7\u6837<\/p>\n<p>    layers.Conv2D(128, (3, 3), activation=&#8217;relu&#8217;),<br \/>\n    layers.MaxPooling2D((2, 2)),  # \u7b2c\u4e8c\u6b21\u4e0b\u91c7\u6837<\/p>\n<p>    layers.Flatten(),<br \/>\n    layers.Dense(128, activation=&#8217;relu&#8217;),<br \/>\n    layers.Dropout(0.5),  # \u7ed3\u5408 Dropout<br \/>\n    layers.Dense(10, activation=&#8217;softmax&#8217;)<br \/>\n])<\/p>\n<pre><code>\n<h3>6.2 \u4fe1\u606f\u4e22\u5931<\/h3>\n\n<strong>\u95ee\u9898<\/strong>\uff1a\u8fc7\u5ea6\u6c60\u5316\u5bfc\u81f4\u91cd\u8981\u4fe1\u606f\u4e22\u5931\n\n<strong>\u89e3\u51b3\u65b9\u6848<\/strong>\uff1a\n<ul>\n<li>\u4f7f\u7528\u66f4\u5c0f\u7684\u6c60\u5316\u7a97\u53e3\uff081\u00d71 \u6216 2\u00d72\uff09<\/li>\n<li>\u589e\u52a0\u6b65\u957f\u63a7\u5236\u4e0b\u91c7\u6837\u6bd4\u4f8b<\/li>\n<li>\u7ed3\u5408\u8df3\u8dc3\u8fde\u63a5\u4fdd\u7559\u539f\u59cb\u4fe1\u606f<\/li>\n<\/ul>\n\n<\/code><\/pre>\n<p>python<\/p>\n<h1>\u4f7f\u7528 ResNet \u98ce\u683c\u7684\u8df3\u8dc3\u8fde\u63a5<\/h1>\n<p>class ResNetBlock(nn.Module):<br \/>\n    def __init__(self, in_channels, out_channels):<br \/>\n        super().__init__()<\/p>\n<p>        self.conv1 = nn.Conv2d(in_channels, out_channels, 3, padding=1)<br \/>\n        self.pool1 = nn.MaxPool2d(2, 2)<\/p>\n<p>        self.conv2 = nn.Conv2d(out_channels, out_channels, 3, padding=1)<br \/>\n        self.pool2 = nn.MaxPool2d(2, 2)<\/p>\n<p>        self.shortcut = nn.Sequential(<br \/>\n            nn.Conv2d(in_channels, out_channels, 1),<br \/>\n            nn.MaxPool2d(2, 2)<br \/>\n        )<\/p>\n<p>    def forward(self, x):<br \/>\n        residual = self.shortcut(x)<br \/>\n        out = self.pool1(F.relu(self.conv1(x)))<br \/>\n        out = self.pool2(self.conv2(out))<br \/>\n        return F.relu(out + residual)<br \/>\n&#8220;`<\/p>\n<h2>\u4e03\u3001\u603b\u7ed3<\/h2>\n<p>\u6c60\u5316\u6280\u672f\u662f\u6df1\u5ea6\u5b66\u4e60\u4e2d\u7684\u91cd\u8981\u7ec4\u6210\u90e8\u5206\uff0c\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u63d0\u5347\u6a21\u578b\u6027\u80fd\uff1a<\/p>\n<ol>\n<li><strong>\u964d\u7ef4\u9ad8\u6548<\/strong>\uff1a\u51cf\u5c11\u7279\u5f81\u56fe\u5c3a\u5bf8\uff0c\u964d\u4f4e\u8ba1\u7b97\u6210\u672c<\/li>\n<li><strong>\u7279\u5f81\u63d0\u53d6<\/strong>\uff1a\u4fdd\u7559\u5173\u952e\u7279\u5f81\uff0c\u589e\u5f3a\u6a21\u578b\u9c81\u68d2\u6027<\/li>\n<li><strong>\u9632\u6b62\u8fc7\u62df\u5408<\/strong>\uff1a\u964d\u4f4e\u6a21\u578b\u590d\u6742\u5ea6\uff0c\u63d0\u5347\u6cdb\u5316\u80fd\u529b<\/li>\n<li><strong>\u6269\u5927\u611f\u53d7\u91ce<\/strong>\uff1a\u4f7f\u7f51\u7edc\u80fd\u591f\u6355\u6349\u66f4\u5927\u8303\u56f4\u7684\u4fe1\u606f<\/li>\n<\/ul>\n<p><strong>\u6700\u4f73\u5b9e\u8df5<\/strong>\uff1a<\/p>\n<ul>\n<li>\u6839\u636e\u4efb\u52a1\u9009\u62e9\u5408\u9002\u7684\u6c60\u5316\u65b9\u5f0f<\/li>\n<li>\u6ce8\u610f\u6c60\u5316\u5c42\u4e0e\u5377\u79ef\u5c42\u7684\u914d\u5408<\/li>\n<li>\u76d1\u63a7\u7279\u5f81\u56fe\u5c3a\u5bf8\u53d8\u5316<\/li>\n<li>\u7ed3\u5408 Dropout \u7b49\u6b63\u5219\u5316\u6280\u672f<\/li>\n<\/ul>\n<p>\u901a\u8fc7\u5408\u7406\u8bbe\u8ba1\u548c\u4f18\u5316\u6c60\u5316\u5c42\uff0c\u53ef\u4ee5\u663e\u8457\u63d0\u5347\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u7684\u6027\u80fd\u548c\u6548\u7387\u3002<\/p>\n<p>&#8212;<\/p>\n<p>*\u672c\u6587\u7ea6 2000 \u5b57\uff0c\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u6c60\u5316\u6280\u672f\u7684\u57fa\u672c\u6982\u5ff5\u3001\u5de5\u4f5c\u539f\u7406\u3001\u5b9e\u73b0\u65b9\u6cd5\u53ca\u5e94\u7528\u573a\u666f\uff0c\u4e3a\u521d\u5b66\u8005\u548c\u8fdb\u9636\u8bfb\u8005\u63d0\u4f9b\u4e86\u5168\u9762\u7684\u53c2\u8003\u6307\u5357\u3002*<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6c60\u5316\u6280\u672f\u8be6\u89e3\uff1a\u6df1\u5ea6\u5b66\u4e60\u4e2d\u7684\u964d\u7ef4\u827a\u672f \u5f15\u8a00 \u5728\u6df1\u5ea6\u5b66\u4e60\u7684\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\uff08CNN\uff09\u4e2d\uff0c\u6c60\u5316\u5c42\u662f\u4e00\u4e2a\u4e0d\u53ef\u6216\u7f3a\u7684\u91cd\u8981\u7ec4\u6210&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-15914","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.srclibs.com\/index.php\/wp-json\/wp\/v2\/posts\/15914","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.srclibs.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.srclibs.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.srclibs.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.srclibs.com\/index.php\/wp-json\/wp\/v2\/comments?post=15914"}],"version-history":[{"count":0,"href":"https:\/\/www.srclibs.com\/index.php\/wp-json\/wp\/v2\/posts\/15914\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.srclibs.com\/index.php\/wp-json\/wp\/v2\/media?parent=15914"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.srclibs.com\/index.php\/wp-json\/wp\/v2\/categories?post=15914"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.srclibs.com\/index.php\/wp-json\/wp\/v2\/tags?post=15914"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}