{"id":209,"date":"2025-06-14T13:45:54","date_gmt":"2025-06-14T05:45:54","guid":{"rendered":"http:\/\/jieyekang.com\/?p=209"},"modified":"2025-06-15T19:13:11","modified_gmt":"2025-06-15T11:13:11","slug":"%e7%a7%91%e7%a0%94%e4%b8%ad%e7%9a%84%e5%b0%8f%e7%81%b5%e6%84%9f%e4%b9%8b%e7%ba%a7%e8%81%94%e7%a5%9e%e7%bb%8f%e7%bd%91%e7%bb%9c","status":"publish","type":"post","link":"http:\/\/jieyekang.com\/index.php\/2025\/06\/14\/%e7%a7%91%e7%a0%94%e4%b8%ad%e7%9a%84%e5%b0%8f%e7%81%b5%e6%84%9f%e4%b9%8b%e7%ba%a7%e8%81%94%e7%a5%9e%e7%bb%8f%e7%bd%91%e7%bb%9c\/","title":{"rendered":"\u79d1\u7814\u4e2d\u7684\u5c0f\u7075\u611f\u4e4b\u7ea7\u8054\u795e\u7ecf\u7f51\u7edc"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">\u524d\u8a00<\/h1>\n\n\n\n<p>\u5728\u6700\u8fd1\u7684\u79d1\u7814\u751f\u6d3b\u4e2d\uff0c\u6211\u65f6\u5e38\u9047\u4e0a\u5f88\u6709\u610f\u601d\u7684\u5c0f\u95ee\u9898\uff0c\u5728\u6b64\u6211\u5f00\u4e00\u4e2a\u4e13\u680f\u4e13\u95e8\u8bb0\u5f55\u4e0b\u6211\u5df2\u7ecf\u89e3\u51b3\u7684\u548c\u672a\u66fe\u89e3\u51b3\u7684\u5c0f\u7075\u611f\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u95ee\u9898\u8bf4\u660e<\/h1>\n\n\n\n<p>\u5c0f\u7075\u611f\uff1a\u5728\u4e00\u5757\u5e73\u9762\u4e0a\uff0c\u6709$n$\u4e2a\u632f\u52a8\u6e90\u5728\u4ea7\u751f\u632f\u52a8\uff0c\u6839\u636e\u7269\u7406\u5b9a\u5f8b\u8fd9\u4e9b\u632f\u52a8\u70b9\u4f1a\u5728\u5e73\u9762\u4e0a\u4ea7\u751f\u632f\u52a8\u5206\u5e03\uff08\u6fc0\u52b1\u5206\u5e03\uff09\uff0c\u6211\u5c06\u632f\u5e45\u6570\u636e\u91c7\u96c6\uff0c\u7ed8\u5236\u51fa\u7c7b\u4f3c\u4e8e\u56fe1\u4e2d\u7684\u5206\u5e03\u56fe\u3002\u6b64\u65f6\uff0c\u6211\u60f3\u5c06\u632f\u52a8\u5206\u5e03\u56fe\u4f5c\u4e3a\u8f93\u5165\u6570\u636e\uff0c\u632f\u52a8\u70b9\u6e90\u7684\u4f4d\u7f6e\u5750\u6807\u4f5c\u4e3a\u8f93\u51fa\u6570\u636e\uff0c\u5c24\u5176\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u6211\u4e0d\u5728\u6a21\u578b\u4e2d\u8bbe\u7f6e\u6700\u540e\u8f93\u51fa\u7684\u70b9\u6e90\u7684\u6570\u91cf\uff0c\u4e5f\u5c31\u662f\u8bf4\u6a21\u578b\u6700\u540e\u8f93\u51fa\u7684\u5750\u6807\u7684\u6570\u91cf\u4e0d\u662f\u4e00\u6210\u4e0d\u53d8\u7684\u3002<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"400\" height=\"400\" src=\"http:\/\/jieyekang.com\/wp-content\/uploads\/2025\/06\/1749186391-3_frame_004.jpg\" alt=\"\" class=\"wp-image-211\" style=\"width:281px;height:auto\" srcset=\"http:\/\/jieyekang.com\/wp-content\/uploads\/2025\/06\/1749186391-3_frame_004.jpg 400w, http:\/\/jieyekang.com\/wp-content\/uploads\/2025\/06\/1749186391-3_frame_004-300x300.jpg 300w, http:\/\/jieyekang.com\/wp-content\/uploads\/2025\/06\/1749186391-3_frame_004-150x150.jpg 150w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><figcaption class=\"wp-element-caption\">\u56fe1 \u632f\u52a8\u5206\u5e03\u793a\u610f\u56fe<\/figcaption><\/figure>\n<\/div>\n\n\n<p>\u6211\u8ba4\u4e3a\u6709\u610f\u601d\u7684\u5730\u65b9\u662f\u2014\u2014\u6a21\u578b\u5728\u4e00\u65b9\u9762\u5728\u505a\u7c7b\u4f3c\u5bf9\u70b9\u6e90\u6570\u91cf\u7684\u56de\u5f52\u4efb\u52a1\uff0c\u8f93\u51fa\u9884\u6d4b\u7684\u70b9\u6e90\u6570\u91cf\uff0c\u4e00\u65b9\u9762\u5728\u5206\u7c7b\u7684\u57fa\u7840\u4e0a\u8fdb\u884c\u56de\u5f52\u4efb\u52a1\uff0c\u8f93\u51fa\u6fc0\u52b1\u70b9\u6e90\u7684\u4f4d\u7f6e\u5750\u6807\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u7075\u611f\u5047\u8bbe<\/h1>\n\n\n\n<p>\u8981\u5728\u4e00\u4e2a\u6a21\u578b\u4e2d\u505a\u5230\u8fd9\u4e9b\u662f\u8f83\u4e3a\u56f0\u96be\u7684\uff0c\u56e0\u6b64\uff0c\u6211\u8bbe\u60f3\u662f\u5426\u80fd\u7ec4\u5408\u4e24\u4e2a\u6a21\u578b\u6784\u5efa\u4e3a\u4e00\u4e2a\u7f51\u7edc\u8fdb\u884c\u8bad\u7ec3\u5462\uff1f\u5047\u8bbe$Model A$\u4f5c\u4e3a\u5b9e\u73b0\u8f93\u51fa\u70b9\u6e90\u6570\u91cf\u7684\u90e8\u5206\uff0c\u90a3\u4e48\u5728$Model B$\u7684\u8f93\u51fa\u5c42\u4e2d\uff0c\u6700\u540e\u7684\u8f93\u51fa\u5c42\uff08\u7ebf\u6027\u5c42\uff09\u7684\u7ef4\u5ea6\u5219\u7531$Model A$\uff08\u8f93\u51fa\u7684\u70b9\u6e90\u6570\u91cf\uff09\u63a7\u5236\u3002\u8fd9\u6837\u5c31\u7b80\u5355\u6784\u5efa\u51fa\u4e86\u4e00\u4e2a\u7ec4\u5408\u6a21\u578b\u7f51\u7edc\u67b6\u6784\u3002<\/p>\n\n\n\n<p>PS\uff1a\u7ecf\u8fc7\u540e\u7eed\u7684\u67e5\u9605\u8d44\u6599\uff0c\u539f\u6765\u672c\u6587\u7684\u8fd9\u79cd\u7ec4\u5408\u6a21\u578b\u7f51\u7edc\u67b6\u6784\u5df2\u7ecf\u6709\u8f83\u591a\u7684\u76f8\u5173\u5de5\u4f5c\u4e86\uff0c\u5e38\u5728\u591a\u4efb\u52a1\u5b66\u4e60\u4e2d\u8fd0\u7528\uff0c\u88ab\u79f0\u4e3a<strong><em>\u7ea7\u8054\u795e\u7ecf\u7f51\u7edc<\/em><\/strong>\u3002<\/p>\n\n\n\n<p>\u5982\u56fe2\u6240\u793a\uff0c\u80fd\u591f\u66f4\u52a0\u6e05\u6670\u7684\u770b\u6e05\u695a\u6a21\u578b\u7684\u8fd0\u4f5c\u673a\u5236\u3002<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"711\" src=\"http:\/\/jieyekang.com\/wp-content\/uploads\/2025\/06\/1749189837-image-1024x711.png\" alt=\"\" class=\"wp-image-216\" style=\"width:431px;height:auto\" srcset=\"http:\/\/jieyekang.com\/wp-content\/uploads\/2025\/06\/1749189837-image-1024x711.png 1024w, http:\/\/jieyekang.com\/wp-content\/uploads\/2025\/06\/1749189837-image-300x208.png 300w, http:\/\/jieyekang.com\/wp-content\/uploads\/2025\/06\/1749189837-image-768x533.png 768w, http:\/\/jieyekang.com\/wp-content\/uploads\/2025\/06\/1749189837-image-1536x1066.png 1536w, http:\/\/jieyekang.com\/wp-content\/uploads\/2025\/06\/1749189837-image-2048x1421.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">\u56fe2 \u7ea7\u8054MLP\u7ed3\u6784\u793a\u610f\u56fe<\/figcaption><\/figure>\n<\/div>\n\n\n<h1 class=\"wp-block-heading\">\u7075\u611f\u5c0f\u9a8c\u8bc1<\/h1>\n\n\n\n<p>\u4e0b\u9762\u662f\u4ee3\u7801\u90e8\u5206\uff0c\u6211\u5148\u91c7\u7528\u4e86\u7b80\u5355\u7684\u7ebf\u6027\u5c42\u8fdb\u884c\u5b9e\u9a8c\uff0c\u6d4b\u8bd5\u6211\u7684\u5c0f\u7075\u611f\u662f\u5426\u80fd\u591f\u5b9e\u73b0\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\n\nclass MLP4Number(nn.Module):\n    def __init__(self, channel=3, hidden_dim=64, output_dim=1):\n        super().__init__()\n        self.fc1 = nn.Linear(channel, hidden_dim)\n        self.fc2 = nn.Linear(hidden_dim, output_dim)\n\n    def forward(self, x):\n        x = F.relu(self.fc1(x))\n        x = self.fc2(x)\n        x = torch.round(x).clamp(min=1)\n        return x\n\nclass MLP4Coordinate(nn.Module):\n    def __init__(self, channel=10, hidden_dim=64, output_dim=1):\n        super().__init__()\n        self.fc1 = nn.Linear(channel, hidden_dim)\n        self.fc2 = nn.Linear(hidden_dim, output_dim)\n        self.number = output_dim\n\n    def forward(self, x):\n        x = F.relu(self.fc1(x))\n        x = self.fc2(x)\n        x = x.view(self.number, 3)\n        return x\n\nclass MLP4TwoTask(nn.Module):\n    def __init__(self, input_channels=256, hidden_dim=64, output_dim=1):\n        super().__init__()\n        self.input = input_channels ** 2\n        self.hidden = hidden_dim\n        self.number = MLP4Number(self.input, hidden_dim, output_dim)\n\n    def forward(self, x):\n        c = torch.tensor(&#91;])\n        x = x.view(x.size(0), -1)\n        n = self.number(x)\n        for i in n:\n            self.coordinate = MLP4Coordinate(self.input, self.hidden, output_dim=int(i))\n            a = self.coordinate(x)\n            c = torch.cat((c, a), dim=0)\n        return n, c\n\nif __name__ == '__main__':\n    model = MLP4TwoTask()\n    imgs = torch.randn(3, 256, 256)\n    output = model(imgs)\n    print(output)<\/code><\/pre>\n\n\n\n<p>\u4e0b\u9762\u662f\u7ecf\u8fc7ChatGPT\u6da6\u8272\u540e\u7684\u4ee3\u7801\u5b9e\u73b0\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\n\nclass MLP4Number(nn.Module):\n    def __init__(self, in_dim: int, hidden_dim: int = 64, output_dim: int = 1):\n        super().__init__()\n        self.fc1 = nn.Linear(in_dim, hidden_dim)\n        self.fc2 = nn.Linear(hidden_dim, output_dim)\n\n    def forward(self, x: torch.Tensor) -&gt; torch.Tensor:\n        \"\"\"\n        \u8f93\u5165\uff1a\n            x: Tensor\uff0cshape = (batch_size, in_dim)\n        \u8f93\u51fa\uff1a\n            Tensor\uff0cshape = (batch_size, 1)\uff0c\u7ecf\u8fc7 round \u5e76 clamp(min=1)\n        \"\"\"\n        x = F.relu(self.fc1(x))\n        x = self.fc2(x)\n        x = torch.round(x).clamp(min=1)\n        return x.squeeze(-1)  # \u8fd4\u56de shape = (batch_size,)\n\n\nclass MLP4Coordinate(nn.Module):\n    def __init__(self, in_dim: int, hidden_dim: int = 64, output_dim: int = 1):\n        super().__init__()\n        self.fc1 = nn.Linear(in_dim, hidden_dim)\n        self.fc2 = nn.Linear(hidden_dim, output_dim * 3)\n        # output_dim \u8868\u793a\u201c\u8981\u9884\u6d4b\u51e0\u4e2a\u4e09\u7ef4\u70b9\u201d\uff0c\u6700\u7ec8\u8f93\u51fa\u4f1a reshape \u6210 (output_dim, 3)\n\n    def forward(self, x: torch.Tensor, num_points: int) -&gt; torch.Tensor:\n        \"\"\"\n        \u8f93\u5165\uff1a\n            x: Tensor\uff0cshape = (1, in_dim) \u6216 (batch=1, in_dim)  \u2014\u2014 \u5355\u4e2a\u6837\u672c\n            num_points: int\uff0c\u8868\u793a\u8981\u9884\u6d4b\u591a\u5c11\u4e2a (x,y,z) \u5750\u6807\u70b9\n        \u8f93\u51fa\uff1a\n            Tensor\uff0cshape = (num_points, 3)\n        \"\"\"\n        x = F.relu(self.fc1(x))\n        x = self.fc2(x)  # shape = (1, num_points*3)\n        x = x.view(num_points, 3)  # reshape \u6210 (num_points, 3)\n        return x\n\n\nclass MLP4TwoTask(nn.Module):\n    def __init__(self, input_size: int = 256, hidden_dim: int = 64):\n        \"\"\"\n        input_size: \u56fe\u50cf\u8fb9\u957f\uff08\u5982 256\uff09\uff0c\u7f51\u7edc\u7684\u8f93\u5165\u662f (batch, input_size, input_size)\n        hidden_dim: MLP \u9690\u85cf\u5c42\u7ef4\u5ea6\n        \"\"\"\n        super().__init__()\n        self.input_dim = input_size * input_size  # 256*256\n        self.hidden_dim = hidden_dim\n\n        # \u9636\u6bb5\u4e00\uff1a\u9884\u6d4b\u8981\u8f93\u51fa\u591a\u5c11\u4e2a\u70b9\n        self.number_net = MLP4Number(in_dim=self.input_dim,\n                                    hidden_dim=hidden_dim,\n                                    output_dim=1)  # \u5355\u4e2a\u6570\u503c\n\n        # \u6ce8\u610f\uff1a\u8fd9\u91cc\u5e76\u4e0d\u9884\u5148\u521b\u5efa MLP4Coordinate\uff0c\u56e0\u4e3a output_dim\uff08\u5750\u6807\u70b9\u6570\uff09\u662f\u52a8\u6001\u7684\u3002\n        # \u6211\u4eec\u4f1a\u5728 forward \u91cc\u6309\u9700\u5b9e\u4f8b\u5316\u4e00\u4e2a\u5c40\u90e8\u7684 MLP4Coordinate\n\n    def forward(self, x: torch.Tensor) -&gt; (torch.Tensor, torch.Tensor):\n        \"\"\"\n        \u8f93\u5165\uff1a\n            x: Tensor\uff0cshape = (batch_size, input_size, input_size)\n        \u8f93\u51fa\uff1a\n            num_list: Tensor\uff0cshape = (batch_size,) \u2014\u2014 \u6bcf\u4e2a\u6837\u672c\u9884\u6d4b\u7684\u70b9\u7684\u6570\u91cf (&gt;=1)\n            coords_all: Tensor\uff0cshape = (sum(num_list), 3) \u2014\u2014 \u628a\u6240\u6709\u6837\u672c\u7684\u5750\u6807\u62fc\u5728\u4e00\u8d77\n        \"\"\"\n        batch_size = x.size(0)\n        device = x.device\n\n        # \u5148\u628a (batch, H, W) -&gt; (batch, H*W)\n        x_flat = x.view(batch_size, -1)  # shape = (batch_size, input_dim)\n\n        # \u9636\u6bb5\u4e00\uff1a\u9884\u6d4b\u6bcf\u4e2a\u6837\u672c\u8981\u591a\u5c11\u4e2a\u70b9 (&gt;=1)\n        num_list = self.number_net(x_flat)  # shape = (batch_size,)\n        # num_list \u5185\u7684\u503c\u662f\u6d6e\u70b9\u53d6\u6574\u540e\u4fdd\u8bc1 \u22651\uff0c\u6bd4\u5982 &#91;3., 1., 5., ...]\n\n        coords_list = &#91;]\n        for idx in range(batch_size):\n            num_i = int(num_list&#91;idx].item())  # \u53d6\u51fa\u7b2c idx \u4e2a\u6837\u672c\u9700\u8981\u7684\u70b9\u6570 (Python int)\n\n            # \u6ce8\u610f\uff1a\u8fd9\u91cc\u7528\u4e34\u65f6\u53d8\u91cf\uff0c\u4e0d\u8981\u5199\u6210 self.coord_net\uff0c\u5426\u5219\u4f1a\u88ab\u6ce8\u518c\u5230 Module \u91cc\n            coord_net = MLP4Coordinate(in_dim=self.input_dim,\n                                       hidden_dim=self.hidden_dim,\n                                       output_dim=num_i).to(device)\n\n            # \u53d6\u51fa\u7b2c idx \u4e2a\u6837\u672c\u7684\u6241\u5e73\u5316\u5411\u91cf\uff0c\u5f62\u72b6\u8981\u662f (1, input_dim)\uff0c\u65b9\u4fbf MLP4Coordinate \u63a5\u53d7\n            single_x = x_flat&#91;idx].unsqueeze(0)  # shape = (1, input_dim)\n\n            # \u5f97\u5230\u5750\u6807\uff1ashape = (num_i, 3)\n            coords_i = coord_net(single_x, num_points=num_i)\n            coords_list.append(coords_i)\n\n        # \u628a\u6240\u6709\u6837\u672c\u9884\u6d4b\u51fa\u6765\u7684\u5750\u6807\u4e00\u8d77 cat\uff0c\u6700\u7ec8\u5f62\u72b6 = (sum(num_list), 3)\n        coords_all = torch.cat(coords_list, dim=0)\n\n        return num_list, coords_all\n\n\nif __name__ == \"__main__\":\n    # \u793a\u4f8b\u8fd0\u884c\n    model = MLP4TwoTask(input_size=256, hidden_dim=64)  # \u5982\u679c\u6709 GPU\uff0c\u5c31 .cuda()\n    imgs = torch.randn(3, 256, 256)\n    num_out, coords_out = model(imgs)\n    print(\"Num per sample:\", num_out)            # e.g. tensor(&#91;2., 5., 1.], device='cuda:0')\n    print(\"All coords shape:\", coords_out.shape) # (2+5+1, 3) = (8,3) \u8fd9\u79cd\u5f62\u5f0f<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u9a8c\u8bc1\u5b9e\u9a8c<\/h1>\n\n\n\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u5c06\u7ea7\u8054MLP\u6539\u53d8\u4e3a\u7ea7\u8054CNN\uff0c\u4e0b\u9762\u5f00\u59cb\u5b9e\u9a8c\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u6784\u5efa\u6570\u636e\u96c6<\/h2>\n\n\n\n<p>\u5728\u672c\u6587\u4e2d\u7684\u6240\u6709\u6570\u636e\u90fd\u662f\u91c7\u7528\u4e86\u6570\u503c\u6a21\u62df\u7684\u529e\u6cd5\uff0c\u4e0b\u9762\u662f\u6211\u4eec\u7b80\u8981\u6784\u5efa\u6570\u636e\u96c6\u7684\u4ee3\u7801\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import numpy as np\nimport matplotlib.pyplot as plt\nimport os\nimport random\nfrom matplotlib import cm  # \u5bfc\u5165\u989c\u8272\u6620\u5c04\u6a21\u5757\n\n# \u521b\u5efa\u8f93\u51fa\u76ee\u5f55\noutput_dir = \"data\"\nif not os.path.exists(output_dir):\n    os.makedirs(output_dir)\n\n# \u6ce2\u7684\u53c2\u6570\nk = 0.2  # \u6ce2\u7684\u9891\u7387\nspeed = 0.2  # \u6ce2\u7684\u4f20\u64ad\u901f\u5ea6\nnums = 100  # \u751f\u6210\u6570\u636e\u6570\u91cf\nresolution = 400  # \u56fe\u50cf\u5206\u8fa8\u7387\n\n# \u7f51\u683c\u70b9\nx = np.linspace(-10, 10, resolution)\ny = np.linspace(-10, 10, resolution)\nX, Y = np.meshgrid(x, y)\n\n# \u968f\u673a\u751f\u6210\u6fc0\u52b1\u70b9\u4f4d\u7f6e\ndef generate_random_sources(num_sources):\n    sources = &#91;]\n    for _ in range(num_sources):\n        x_pos = random.uniform(0, 1)  # \u968f\u673a x \u5750\u6807\n        y_pos = random.uniform(0, 1)  # \u968f\u673a y \u5750\u6807\n        sources.append(np.array(&#91;x_pos, y_pos]))\n    return sources\n\n# \u751f\u6210\u6ce2\u7684\u5e45\u5ea6\ndef generate_wave(sources, frame):\n    Z = np.zeros_like(X)  # \u521d\u59cb\u5316\u6ce2\u7684\u5e45\u5ea6\n    for center in sources:\n        R = np.sqrt((X - center&#91;0]) ** 2 + (Y - center&#91;1]) ** 2)\n        Z += np.sin(k * R - speed * frame)  # \u53e0\u52a0\u6bcf\u4e2a\u6fc0\u52b1\u70b9\u7684\u6ce2\n    return Z\n\n# \u751f\u6210\u5e76\u4fdd\u5b58\u6570\u636e\uff08\u6dfb\u52a0\u9ad8\u65af\u566a\u58f0\uff09\ndef generate_and_save_data(num_sources, output_dir=\"route_data\"):\n    # \u521b\u5efa\u5b50\u76ee\u5f55\n    npy_dir = os.path.join(output_dir, \"npy\")\n    pic_dir = os.path.join(output_dir, \"pic\")\n    os.makedirs(npy_dir, exist_ok=True)\n    os.makedirs(pic_dir, exist_ok=True)\n\n    for frame in range(nums):\n        # \u968f\u673a\u751f\u6210\u6fc0\u52b1\u70b9\u4f4d\u7f6e\n        sources = generate_random_sources(num_sources)\n\n        # \u751f\u6210\u6ce2\u7684\u5e45\u5ea6\n        Z = generate_wave(sources, frame)\n\n        # \u5c06\u6ce2\u5f62\u6570\u636e\u6620\u5c04\u4e3a RGB \u56fe\u50cf\u6570\u636e\n        norm_z = (Z - Z.min()) \/ (Z.max() - Z.min())\n        rgba_data = cm.jet(norm_z)\n        rgb_data = rgba_data&#91;..., :3]\n\n        # \u6dfb\u52a0\u9ad8\u65af\u566a\u58f0\n        noise_std = 0.1  # \u566a\u58f0\u5f3a\u5ea6\uff0c\u6839\u636e\u9700\u8981\u8c03\u6574\n        noise = np.random.normal(0, noise_std, rgb_data.shape)\n        noisy_rgb = np.clip(rgb_data + noise, 0, 1)  # \u9650\u5236\u5728\u6709\u6548\u8303\u56f4\n\n        # \u4fdd\u5b58\u5e26\u566a\u58f0\u7684npy\u6587\u4ef6\n        npy_filename = os.path.join(npy_dir, f\"{num_sources}_frame_{frame:03d}.npy\")\n        np.save(npy_filename, noisy_rgb)\n\n        # \u53ef\u89c6\u5316\u5e76\u4fdd\u5b58\u56fe\u7247\n        img_filename = os.path.join(pic_dir, f\"{num_sources}_frame_{frame:03d}.png\")\n        plt.imshow(noisy_rgb)\n        # \u6807\u8bb0\u6fc0\u52b1\u70b9\n        for source in sources:\n            x_idx = np.argmin(np.abs(x - source&#91;0]))\n            y_idx = np.argmin(np.abs(y - source&#91;1]))\n            plt.scatter(x&#91;x_idx], y&#91;y_idx], color='white', s=100, marker='x', alpha=0.6)  # \u8c03\u6574\u900f\u660e\u5ea6\n        plt.axis('off')\n        plt.savefig(img_filename, bbox_inches='tight', pad_inches=0)\n        plt.clf()\n\n    print(f\"Generated route_data for {num_sources} sources with Gaussian noise.\")\n    print(f\"Saved route_data to {output_dir}\")\n\n# \u751f\u6210\u5e26\u566a\u58f0\u7684\u6570\u636e\ngenerate_and_save_data(1)\ngenerate_and_save_data(2)\ngenerate_and_save_data(3)<\/code><\/pre>\n\n\n\n<p>\u5728\u4e0a\u8ff0\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u8bbe\u7f6e\u6ce2\u7684\u9891\u7387\u4e3a$k=0.2$\uff0c\u4f20\u64ad\u901f\u5ea6\u4e3a0.2\uff0c\u6bcf\u7ec4\u6570\u91cf\u4e3a100\uff0c\u9ad8\u65af\u566a\u58f0\u4e3a0.1\uff0c\u6bcf\u7ec4\u7684\u56fe\u50cf\u5206\u8fa8\u7387\u4e3a$400 \\times 400$\uff0c\u968f\u673a\u70b9\u7684x\u548cy\u7684\u5750\u6807\u8303\u56f4\u5747\u5728$[0,1]$\u3002\u5176\u4e2d\uff0c\u7531\u4e8e\u795e\u7ecf\u7f51\u7edc\u7684\u672c\u8d28\u5176\u5b9e\u5c31\u662f\u4e00\u79cd\u51fd\u6570\u6620\u5c04$f(\\cdot)$\uff0c\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u968f\u610f\u6784\u5efa\u5177\u4f53\u5750\u6807\uff08\u56e0\u4e3a\u53ea\u662f\u8981\u9a8c\u8bc1idea\u7684\u53ef\u884c\u6027\uff0c\u65e0\u9700\u592a\u8fc7\u4e25\u8c28\uff09\uff0c\u901a\u8fc7\u6784\u5efa\u5728x\u548cy\u7684\u5750\u6807\u8303\u56f4\u5185\u7684\u5750\u6807\u6570\u636e\u5e76\u5c06\u5176\u4f5c\u4e3a\u6587\u4ef6\u540d\u5bf9Data\u8fdb\u884c\u91cd\u547d\u540d\uff0c\u5f97\u5230\u6700\u540e\u7684\u6570\u636e\u96c6\u3002<\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">PS\uff08\u5fae\u64cd\uff09\uff1a\u65e0\u8bba\u5750\u6807\u6570\u636e\u7684\u8303\u56f4\uff0c\u5176\u5b9e\u90fd\u53ef\u4ee5\u5c06\u5176\u5f52\u4e00\u5316\u540e\u8f93\u5165\u7f51\u7edc\u4e2d\u8fdb\u884c\u5b66\u4e60\uff0c\u524d\u63d0\u662f\u9700\u8981\u63d0\u53d6\u7eaa\u5f55\u4e0b\u6570\u636e\u4e2d\u7684\u6700\u5927\u503c\u4e0e\u6700\u5c0f\u503c\u7528\u6765\u8fd8\u539f\u56de\u539f\u5750\u6807\u3002<\/mark><\/p>\n\n\n\n<p>\u6211\u4eec\u5728\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\u6784\u5efa\u51faData\u5185\u5bb9\u4e3a\uff08Images\uff0cCoords\uff09\u7684\u6570\u636e\u96c6\uff0c\u5176\u4e2dImages\u4e3a\uff08batch\uff0c3\uff0cH\uff0cW\uff09\uff0cCoords\u4e3a\uff08batch\uff0ccoords\uff09\uff0cImages Size\u4e3a$400 \\times 400$\u3002<\/p>\n\n\n\n<p>\u4e0b\u9762\u662f\u6784\u5efa\u6570\u636e\u96c6\u90e8\u5206\u7684\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class NpyDataset(Dataset):\n    def __init__(self, data_dir: str):\n        super().__init__()\n        self.file_paths = glob.glob(os.path.join(data_dir, \"*.npy\"))\n        self.file_paths.sort()\n\n    def __len__(self):\n        return len(self.file_paths)\n\n    def __getitem__(self, idx: int):\n        file_path = self.file_paths&#91;idx]\n        filename = os.path.basename(file_path)\n\n        # \u52a0\u8f7d .npy \u6587\u4ef6\u5185\u5bb9\n        np_array = np.load(file_path)  # e.g. shape = (400, 400, 3)\n\n        # \u5982\u679c\u662f\u4e09\u901a\u9053(H, W, 3)\uff0c\u8f6c\u6210 (3, H, W)\n        if np_array.ndim == 3:\n            # \u5047\u8bbe\u6700\u540e\u4e00\u7ef4\u662f channel\n            data_tensor = torch.from_numpy(np_array).permute(2, 0, 1).float()\n        elif np_array.ndim == 2:\n            # \u5982\u679c\u662f\u5355\u901a\u9053(H, W)\uff0c\u52a0\u4e00\u4e2a\u901a\u9053\u7ef4 (1, H, W)\n            data_tensor = torch.from_numpy(np_array).unsqueeze(0).float()\n        else:\n            # \u5982\u679c\u6570\u636e\u6709\u5176\u4ed6\u7ef4\u5ea6\uff0c\u5c31\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u5904\u7406\n            raise ValueError(f\"Unsupported npy shape: {np_array.shape}\")\n\n        # \u4ece\u6587\u4ef6\u540d\u89e3\u6790\u5750\u6807\uff08\u4e0d\u53d8\uff09\n        name_without_ext = os.path.splitext(filename)&#91;0]\n        parts = name_without_ext.split(\"_\")\n        coords = &#91;]\n        for i in range(0, len(parts), 2):\n            x = float(parts&#91;i]);\n            y = float(parts&#91;i + 1])\n            coords.append(&#91;x, y])\n        coord_tensor = torch.tensor(coords, dtype=torch.float32)\n\n        return data_tensor, coord_tensor\n\ndef variable_collate_fn(batch):\n    \"\"\"\n    \u81ea\u5b9a\u4e49 collate_fn\uff0c\u7528\u4e8e\u5904\u7406\u6bcf\u4e2a\u6837\u672c label (coord) \u957f\u5ea6\u4e0d\u540c\u7684\u60c5\u51b5\u3002\n    batch \u662f list of (data_tensor, coord_tensor)\u3002\n\n    \u8fd4\u56de:\n      data_batch: Tensor, \u5c06 data_tensor \u5806\u53e0\uff0c\u5f62\u72b6 = (batch_size, ...)\n      coords_list: List of Tensors, \u6bcf\u4e2a coord_tensor \u5f62\u72b6 = (Ni, 2)\n    \"\"\"\n    data_list, coords_list = zip(*batch)\n    data_batch = torch.stack(data_list, dim=0)\n    return data_batch, list(coords_list)<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u6784\u5efa\u7ea7\u8054CNN<\/h2>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"414\" src=\"http:\/\/jieyekang.com\/wp-content\/uploads\/2025\/06\/1749281289-image-1024x414.png\" alt=\"\" class=\"wp-image-228\" srcset=\"http:\/\/jieyekang.com\/wp-content\/uploads\/2025\/06\/1749281289-image-1024x414.png 1024w, http:\/\/jieyekang.com\/wp-content\/uploads\/2025\/06\/1749281289-image-300x121.png 300w, http:\/\/jieyekang.com\/wp-content\/uploads\/2025\/06\/1749281289-image-768x310.png 768w, http:\/\/jieyekang.com\/wp-content\/uploads\/2025\/06\/1749281289-image-1536x621.png 1536w, http:\/\/jieyekang.com\/wp-content\/uploads\/2025\/06\/1749281289-image-2048x828.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">\u56fe3 \u7ea7\u8054CNN\u7ed3\u6784\u793a\u610f\u56fe<\/figcaption><\/figure>\n<\/div>\n\n\n<p>\u5982\u56fe3\u6240\u793a\uff0c\u6211\u4eec\u5148\u91c7\u7528\u5377\u79ef\u64cd\u4f5c\u63d0\u53d6\u56fe\u7247\u7684\u7279\u5f81\u4fe1\u606f\uff0c\u7136\u540e\u5c06\u7279\u5f81\u4fe1\u606f\u8f93\u5165\u7ebf\u6027\u5c42\u8fdb\u884c\u8fdb\u4e00\u6b65\u7684\u5b66\u4e60\u548c\u53d8\u5316\uff0c\u6700\u540e\u8f93\u51fa\u6211\u4eec\u60f3\u8981\u5f97\u5230\u7684\u6570\u636e\u3002\u5176\u4e2d\uff0c\u5728Feature Extraction\u4e2d\uff0c\u4e3a\u4e86\u4f7f\u5f97\u7f51\u7edc\u5c42\u6570\u80fd\u591f\u66f4\u591a\uff0c\u6211\u4eec\u91c7\u7528\u4e86\u7531\u6b8b\u5dee\u8fde\u63a5\u6784\u6210\u7684\u6b8b\u5dee\u5757\uff0c\u7ecf\u8fc7\u5806\u53e0\u6784\u6210\u603b\u4f53\u7684\u5377\u79ef\u63d0\u53d6\u90e8\u5206\u3002<\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">PS\uff1a\u7531\u4e8e\u56fe3\u4e2d\u6a21\u578b\u7684\u8868\u8fbe\u80fd\u529b\u6709\u9650\uff0c\u4e0b\u65b9\u7684\u4ee3\u7801\u4ec5\u4ec5\u53ea\u8868\u793a\u6a21\u578b\u642d\u5efa\u7684\u57fa\u672c\u601d\u8def\uff0c\u5728\u590d\u73b0\u8fc7\u7a0b\u4e2d\u8bf7\u6839\u636e\u81ea\u5df1\u7684\u9700\u6c42\u5bf9\u6a21\u578b\u8fdb\u884c\u6a21\u5757\u7684\u6dfb\u52a0\uff0c\u672c\u6587\u4e2d\u7684\u6240\u6709\u4ee3\u7801\u5747\u653e\u7f6e\u4e8eGithub\u4e2d\uff0c\u6709\u9700\u8981\u6d6e\u73b0\u8005\u53ef\u4ee5\u524d\u5f80\u6211\u7684Github\u4e0a\u67e5\u770b\u5b8c\u6574\u7684\u4ee3\u7801\u3002<\/mark>\uff08<a href=\"https:\/\/github.com\/MAOJIUTT\/Cascade-Neural-Networks\" target=\"_blank\"  rel=\"nofollow\" >https:\/\/github.com\/MAOJIUTT\/Cascade-Neural-Networks<\/a>\uff09<\/p>\n\n\n\n<p>\u4e0b\u9762\u662f\u6a21\u578b\u7684\u4ee3\u7801<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class ResBlock(nn.Module):\n    def __init__(self, channels: int):\n        super().__init__()\n        self.conv1 = nn.Conv2d(channels, channels, kernel_size=3, padding=1, bias=False)\n        self.bn1 = nn.BatchNorm2d(channels)\n        self.conv2 = nn.Conv2d(channels, channels, kernel_size=3, padding=1, bias=False)\n        self.bn2 = nn.BatchNorm2d(channels)\n\n    def forward(self, x: torch.Tensor) -&gt; torch.Tensor:\n        identity = x\n        out = self.conv1(x)\n        out = self.bn1(out)\n        out = F.relu(out, inplace=True)\n        out = self.conv2(out)\n        out = self.bn2(out)\n        out += identity\n        out = F.relu(out, inplace=True)\n        return out\n\n\nclass CNN4TwoStage(nn.Module):\n    def __init__(\n        self,\n        in_channels: int = 1,\n        base_channels: int = 32,\n        num_resblocks: int = 2,\n        max_points: int = 10,\n        hidden_dim: int = 128\n    ):\n        super().__init__()\n        self.in_channels = in_channels\n        self.base_channels = base_channels\n        self.max_points = max_points\n        self.hidden_dim = hidden_dim\n\n        # backbone\n        self.conv_start = nn.Sequential(\n            nn.Conv2d(in_channels, base_channels, kernel_size=3, padding=1, bias=False),\n            nn.BatchNorm2d(base_channels),\n            nn.ReLU(inplace=True)\n        )\n        res_blocks = &#91;]\n        for _ in range(num_resblocks):\n            res_blocks.append(ResBlock(base_channels))\n        self.residual_layers = nn.Sequential(*res_blocks)\n        self.global_pool = nn.AdaptiveAvgPool2d((1,1))\n        self.fc_feature = nn.Linear(base_channels, hidden_dim)\n\n        # Number Head\n        self.number_fc = nn.Linear(hidden_dim, 1)\n\n        # Coordinate Head (\u6539\u4e3a max_points * 2)\n        self.coord_fc = nn.Linear(hidden_dim, max_points * 2)\n\n    def forward(self, x: torch.Tensor) -&gt; (torch.Tensor, torch.Tensor):\n        \"\"\"\n        \u8f93\u5165\uff1a\n            x: (batch, in_channels, H, W)\n        \u8f93\u51fa\uff1a\n            num_list: (batch,) \u6574\u6570\u578b\uff0c\u9884\u6d4b\u7684\u6bcf\u5f20\u56fe\u8981\u8f93\u51fa\u51e0\u4e2a\u70b9\n            coords_all: (sum_i Ni, 2) \u6240\u6709\u6837\u672c\u62fc\u63a5\u540e\u7684 (x,y) \u5750\u6807\n        \"\"\"\n        batch_size = x.size(0)\n        device = x.device\n\n        # backbone \u63d0\u53d6\u7279\u5f81\n        out = self.conv_start(x)           # (batch, base, H, W)\n        out = self.residual_layers(out)    # (batch, base, H, W)\n        out = self.global_pool(out)        # (batch, base, 1, 1)\n        out = out.view(batch_size, -1)     # (batch, base)\n        feat = F.relu(self.fc_feature(out))# (batch, hidden_dim)\n\n        # Number Head\n        num_pred = self.number_fc(feat)    # (batch,1)\n        num_pred = torch.round(num_pred).clamp(min=1)  # \u4fdd\u8bc1 \u22651\n        num_list = num_pred.squeeze(-1).long()         # (batch,)\n\n        # Coordinate Head \u2192 (batch, max_points*2)\n        coord_pred = self.coord_fc(feat)   # (batch, max_points*2)\n\n        coords_list = &#91;]\n        for i in range(batch_size):\n            n_i = int(num_list&#91;i].item())\n            if n_i &gt; self.max_points:\n                n_i = self.max_points\n            # \u53d6\u524d n_i*2 \u4e2a\u6570\uff0creshape \u4e3a (n_i,2)\n            coords_i = coord_pred&#91;i, : n_i * 2].view(n_i, 2)\n            coords_list.append(coords_i)\n\n        # \u628a\u6240\u6709\u6837\u672c\u7684 coords_i \u5728\u7b2c 0 \u7ef4\u62fc\u8d77\u6765 -&gt; (sum_i n_i, 2)\n        coords_all = torch.cat(coords_list, dim=0)\n        return num_list, coords_all<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u9636\u6bb5\u6027\u8bad\u7ec3\uff08\u51bb\u7ed3-\u5fae\u8c03\u7b56\u7565\uff09<\/h2>\n\n\n\n<p>\u7531\u4e8e\u7ea7\u8054CNN\u662f\u591a\u4efb\u52a1\u7ed3\u6784\uff0c\u662f\u4e00\u4e2a\u5178\u578b\u7684\u591a\u4efb\u52a1\u5b66\u4e60\u6a21\u578b\uff08Multi-Task Learning\uff0cMTL\uff09\uff0c\u62e5\u6709\u4e24\u4e2a\u90e8\u5206\u2014\u2014\u4e3b\u5e72\u7f51\u7edc\uff08Backbone\uff09\u548c\u4efb\u52a1\u5206\u652f\uff08Head\uff09\u3002\u4e3b\u5e72\u7f51\u7edc\u7528\u4e8e\u63d0\u53d6\u5171\u4eab\u7279\u5f81\uff0c\u4efb\u52a1\u5206\u652f\u5219\u662f\u5b8c\u6210\u5bf9\u5e94\u9700\u8981\u5b8c\u6210\u7684\u4efb\u52a1\u3002\u5176\u4e2d\uff0c\u5728\u672c\u6587\u7684\u591a\u4efb\u52a1\u7ed3\u6784\u4e2d\u6709\u4e24\u4e2a\u5173\u8054\u7684\u5b66\u4e60\u9636\u6bb5\uff0c\u9636\u6bb51 \u4e3a <strong>Number Head<\/strong> \u9884\u6d4b\u7684\u662f\u6bcf\u5f20\u56fe\u4e2d\u76ee\u6807\u7684\u4e2a\u6570\uff1b\u9636\u6bb52 \u4e3a <strong>Coordinate Head<\/strong> \u9884\u6d4b\u7684\u662f\u76ee\u6807\u7684\u5750\u6807\uff0c\u800c\u5b83\u4f9d\u8d56\u4e8e\u9636\u6bb51 <strong>Number Head<\/strong>\u7684\u9884\u6d4b\u7ed3\u679c\u3002\u56e0\u6b64\uff0c\u53ef\u4ee5\u8ba4\u4e3a\u5982\u679c <strong>Number Head<\/strong> \u9884\u6d4b\u4e0d\u51c6\uff0c\u90a3\u4e48 <strong>Coordinate Head<\/strong> \u7684\u8bad\u7ec3\u4f1a\u53d7\u5f71\u54cd\uff08\u5982\u70b9\u6570\u4e0d\u5bf9\u5bfc\u81f4\u914d\u5bf9\u9519\u8bef\uff09\u3002\u6240\u4ee5\uff0c\u6211\u4eec\u53ef\u4ee5\u91c7\u7528\u5982\u4e0b<strong>\u4e24\u6bb5\u5f0f\u8bad\u7ec3\u7b56\u7565<\/strong>\u3002<\/p>\n\n\n\n<p>\u7b2c\u4e00\u9636\u6bb5\uff1a\u51bb\u7ed3 <strong>Coordinate Head<\/strong> \uff0c\u53ea\u4f18\u5316\u6570\u91cf\u9884\u6d4b\uff0c\u4ee3\u7801\u5982\u4e0b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def train_number_head(model, loader, optimizer, epochs=10):\n    model.train()\n\n    # \u51bb\u7ed3\u5750\u6807\u9884\u6d4b\u5934\n    for param in model.coord_fc.parameters():\n        param.requires_grad = False\n\n    mse_num = nn.MSELoss()\n\n    for epoch in range(epochs):\n        epoch_loss = 0.0\n        for x_batch, coords_list in loader:\n            x_batch = x_batch.to(device)\n            num_target = torch.tensor(\n                &#91;coords.shape&#91;0] for coords in coords_list],\n                dtype=torch.float32, device=device\n            )\n\n            num_pred, _ = model(x_batch)\n\n            loss = mse_num(num_pred.float(), num_target)\n\n            optimizer.zero_grad()\n            loss.backward()\n            optimizer.step()\n\n            epoch_loss += loss.item()\n\n        print(f\"&#91;Number Head] Epoch &#91;{epoch+1}\/{epochs}]  Loss: {epoch_loss:.6f}\")<\/code><\/pre>\n\n\n\n<p>\u7b2c\u4e8c\u9636\u6bb5\uff1a\u89e3\u51bb <strong>Coordinate Head<\/strong> \uff0c\u53ef\u9009\u51bb <strong>Number Head<\/strong> \uff0c\u4ee3\u7801\u5982\u4e0b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def train_coord_head(model, loader, optimizer, epochs=10, lambda_coord=1.0, freeze_number_head=False):\n    model.train()\n\n    # \u89e3\u51bb\u5750\u6807\u5934\n    for param in model.coord_fc.parameters():\n        param.requires_grad = True\n\n    # \u53ef\u9009\uff1a\u51bb\u7ed3\u6570\u91cf\u9884\u6d4b\u5934\n    if freeze_number_head:\n        for param in model.number_fc.parameters():\n            param.requires_grad = False\n\n    mse_num = nn.MSELoss()\n    mse_coord = nn.MSELoss()\n\n    for epoch in range(epochs):\n        total_loss_num, total_loss_coord = 0.0, 0.0\n\n        for x_batch, coords_list in loader:\n            x_batch = x_batch.to(device)\n\n            num_target = torch.tensor(\n                &#91;coords.shape&#91;0] for coords in coords_list],\n                dtype=torch.float32, device=device\n            )\n\n            coords_target_all = torch.cat(\n                &#91;coords.to(device) for coords in coords_list], dim=0\n            )\n\n            num_pred, coords_pred_all = model(x_batch)\n\n            loss_num = mse_num(num_pred.float(), num_target)\n            loss_coord = mse_coord(coords_pred_all, coords_target_all)\n\n            total_loss = loss_num + lambda_coord * loss_coord\n\n            optimizer.zero_grad()\n            total_loss.backward()\n            optimizer.step()\n\n            total_loss_num += loss_num.item()\n            total_loss_coord += loss_coord.item()\n\n        print(f\"&#91;Coord Head] Epoch &#91;{epoch+1}\/{epochs}]  NumLoss: {total_loss_num:.6f}  CoordLoss: {total_loss_coord:.6f}\")<\/code><\/pre>\n\n\n\n<p>\u4f46\u662f\u5728\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\u8ba1\u7b97Loss\u503c\u65f6\uff0c\u4ecd\u7136\u4f1a\u9047\u4e0a\u70b9\u6570\u4e0d\u5bf9\u5bfc\u81f4\u914d\u5bf9\u9519\u8bef\u7684\u95ee\u9898\uff0c\u672c\u7bc7Blog\u76ee\u524d\u672a\u80fd\u89e3\u51b3\u8be5\u95ee\u9898\uff0c\u6240\u4ee5\u5728\u672c\u6587\u4e2d\u6211\u6240\u91c7\u7528\u7684\u89e3\u51b3\u65b9\u6cd5\u662f\u5206\u6bb5\u5f0f\u8bad\u7ec3\u6a21\u578b\uff0c\u5148\u5c06\u6a21\u578b\u4e2d\u9884\u6d4b\u6fc0\u52b1\u70b9\u6570\u91cf\u7684\u6a21\u5757\u90e8\u5206\u8bad\u7ec3\u523090%\u4ee5\u4e0a\u7684\u51c6\u786e\u7387\uff0c\u7136\u540e\u518d\u5728\u8fd9\u4e2a\u57fa\u7840\u4e0a\u8bad\u7ec3\u9884\u6d4b\u5750\u6807\u90e8\u5206\u7684\u6a21\u578b\uff0c\u8fd9\u6837\u5c31\u80fd\u591f\u4fdd\u8bc1\u4e00\u5b9a\u7684\u6a21\u578b\u9884\u6d4b\u51c6\u786e\u7387\u3002<\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-amber-color\">PS\uff1a\u672cBlog\u4e2d\u672a\u89e3\u51b3\u7684\u95ee\u9898\u90e8\u5206\u6211\u4f1a\u5728\u6691\u671f\u4e2d\u5c1d\u8bd5\u89e3\u51b3\u3002<\/mark><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u635f\u5931\u51fd\u6570<\/h2>\n\n\n\n<p>\u5728\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\uff0c\u635f\u5931\u51fd\u6570\u662f\u5c24\u4e3a\u91cd\u8981\u7684\uff0c\u4f46\u662f\u5728\u8fd9\u4e2a\u7f51\u7edc\u67b6\u6784\u4e2d\uff0c\u6a21\u578b\u7684\u8f93\u51fa\u7ef4\u5ea6\u662f\u52a8\u6001\u7684\uff0c\u5728\u7ef4\u5ea6\u4e0a\u65e0\u6cd5\u5f88\u597d\u7684\u4e0e\u6570\u636e\u7684\u6807\u7b7e\u7ef4\u5ea6\u5bf9\u5e94\uff0c\u56e0\u6b64\u65e0\u6cd5\u76f4\u63a5\u5bf9\u5176\u8fdb\u884c\u6c42\u635f\u5931\u3002\u7ed3\u5408\u672c\u6587\u7684\u8bad\u7ec3\u601d\u8def\uff0c\u6211\u91c7\u7528\u9010\u6570\u91cf\u4e00\u4e00\u5bf9\u5e94\u6c42Loss\u635f\u5931\u503c\u3002<\/p>\n\n\n\n<p>\u5177\u4f53\u610f\u601d\u5c31\u662f\uff0c\u5f53\u6a21\u578b\u8f93\u51fa\u7ef4\u5ea6\u4e0e\u6570\u636e\u6807\u7b7e\u7684\u7ef4\u5ea6\u4e0d\u5339\u914d\u65f6\uff0c\u6211\u53ea\u9700\u8981\u6839\u636e<strong><em>\u8f83\u5c0f<\/em><\/strong>\u90a3\u4e00\u90e8\u5206\u7684\u8f93\u51fa\u7ef4\u5ea6\u4f5c\u4e3a\u8ba1\u7b97Loss\u635f\u5931\u503c\u65f6\u7684\u7ef4\u5ea6\u3002\u56e0\u4e3a\u6a21\u578b\u7684\u8f93\u51fa\u7ef4\u5ea6\u4e0e\u6570\u636e\u6807\u7b7e\u7ef4\u5ea6\u4e0d\u540c\u65f6\u4f1a\u5b58\u5728\u4e24\u79cd\u60c5\u51b5\uff0c\u4e00\u662f\u6a21\u578b\u7684\u8f93\u51fa\u7ef4\u5ea6<strong><em>\u5c0f\u4e8e<\/em><\/strong>\u6570\u636e\u6807\u7b7e\u7ef4\u5ea6\uff08\u9884\u6d4b\u70b9\u7684\u6570\u91cf<strong><em>\u5c0f\u4e8e<\/em><\/strong>\u76ee\u6807\u6570\u91cf\uff09\uff0c\u4e8c\u662f\u6a21\u578b\u7684\u8f93\u51fa\u7ef4\u5ea6<em><strong>\u5927\u4e8e<\/strong><\/em>\u6570\u636e\u6807\u7b7e\u7ef4\u5ea6\uff08\u9884\u6d4b\u70b9\u7684\u6570\u91cf<strong><em>\u5927\u4e8e<\/em><\/strong>\u76ee\u6807\u6570\u91cf\uff09\u3002\u6240\u4ee5\u4e3a\u4e86\u4fdd\u6301\u7ef4\u5ea6\u4e0a\u7684\u7edf\u4e00\u4ee5\u65b9\u4fbf\u8ba1\u7b97Loss\u635f\u5931\u503c\uff0c\u6211\u51b3\u5b9a\u6839\u636e<strong><em>\u8f83\u5c0f<\/em><\/strong>\u90a3\u4e00\u90e8\u5206\u7684\u8f93\u51fa\u7ef4\u5ea6\u4f5c\u4e3a\u8ba1\u7b97Loss\u635f\u5931\u503c\u65f6\u7684\u7ef4\u5ea6\u3002<\/p>\n\n\n\n<p>\u6240\u4ee5\u6211\u4eec\u5c06<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">\u7b2c\u4e8c\u9636\u6bb5<\/mark>\u7684\u4ee3\u7801\u4fee\u6539\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def train_coord_head(model, loader, optimizer, epochs=10, lambda_coord=1.0, freeze_number_head=False, coord_eps=0.5):\n    model.train()\n\n    for param in model.coord_fc.parameters():\n        param.requires_grad = True\n\n    if freeze_number_head:\n        for param in model.number_fc.parameters():\n            param.requires_grad = False\n\n    mse_num = nn.MSELoss()\n    mse_coord = nn.MSELoss()\n\n    for epoch in range(epochs):\n        total_loss_num, total_loss_coord = 0.0, 0.0\n        correct_count_num = 0\n        total_count_num = 0\n\n        correct_count_coord = 0\n        total_count_coord = 0\n\n        for x_batch, coords_list in loader:\n            x_batch = x_batch.to(device)\n\n            num_target = torch.tensor(\n                &#91;coords.shape&#91;0] for coords in coords_list],\n                dtype=torch.float32, device=device\n            )\n\n            coords_target_all = torch.cat(\n                &#91;coords.to(device) for coords in coords_list], dim=0\n            )\n\n            num_pred, coords_pred_all = model(x_batch)\n\n            # ===== \u70b9\u6570\u9884\u6d4b =====\n            loss_num = mse_num(num_pred.float(), num_target)\n\n            pred_rounded = torch.round(num_pred).clamp(min=1, max=model.max_points)\n            correct_count_num += (pred_rounded == num_target).sum().item()\n            total_count_num += len(num_target)\n\n            # ===== \u5750\u6807\u9884\u6d4b =====\n            pred_coords_split = &#91;]\n            target_coords_split = &#91;]\n            idx_pred = 0\n            idx_target = 0\n            for i in range(len(coords_list)):\n                coords_target_i = coords_list&#91;i].to(device)\n                n_target = coords_target_i.shape&#91;0]\n                n_pred = int(pred_rounded&#91;i].item())\n\n                coords_pred_i = coords_pred_all&#91;idx_pred: idx_pred + n_pred]\n                idx_pred += n_pred\n                idx_target += n_target\n\n                # \u53d6\u6700\u5c0f\u957f\u5ea6\n                n_common = min(n_pred, n_target)\n                if n_common &gt; 0:\n                    coords_pred_i = coords_pred_i&#91;:n_common]\n                    coords_target_i = coords_target_i&#91;:n_common]\n\n                    pred_coords_split.append(coords_pred_i)\n                    target_coords_split.append(coords_target_i)\n\n                    # ==== \u51c6\u786e\u7387\u7edf\u8ba1 ====\n                    dist = torch.norm(coords_pred_i - coords_target_i, dim=1)\n                    correct_count_coord += (dist &lt; coord_eps).sum().item()\n                    total_count_coord += n_common\n\n            if pred_coords_split:\n                coords_pred_used = torch.cat(pred_coords_split, dim=0)\n                coords_target_used = torch.cat(target_coords_split, dim=0)\n                loss_coord = mse_coord(coords_pred_used, coords_target_used)\n            else:\n                loss_coord = torch.tensor(0.0, device=device)\n\n            total_loss = loss_num + lambda_coord * loss_coord\n\n            optimizer.zero_grad()\n            total_loss.backward()\n            optimizer.step()\n\n            total_loss_num += loss_num.item()\n            total_loss_coord += loss_coord.item()\n\n        acc_num = correct_count_num \/ total_count_num if total_count_num &gt; 0 else 0.0\n        acc_coord = correct_count_coord \/ total_count_coord if total_count_coord &gt; 0 else 0.0\n\n        print(f\"&#91;Coord Head] Epoch &#91;{epoch+1}\/{epochs}]  NumLoss: {total_loss_num:.6f}  CoordLoss: {total_loss_coord:.6f}  \"\n              f\"NumAcc: {acc_num:.4f}  CoordAcc(@{coord_eps}): {acc_coord:.4f}\")<\/code><\/pre>\n\n\n\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u5728\u6539\u8fdb\u540e\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5728\u5224\u65ad\u5750\u6807\u9884\u6d4b\u7684\u51c6\u786e\u7387\u7684\u65f6\u5019\uff0c\u8bbe\u7f6e\u4e86coord_eps\u53c2\u6570\u4e3a0.5\uff0c\u4f5c\u4e3a\u8ddd\u79bb\u5bb9\u5dee\uff08\u8ddd\u79bb\u5bb9\u5fcd\u5ea6\u7684\u5dee\u503c\uff09\uff0c\u7528\u5176\u4f5c\u4e3a\u8ddd\u79bb\u5bb9\u5dee\u8ba1\u7b97\u5f97\u5230\u7684Coord Acc\u503c\u5219\u8868\u793a\u4e3a\u9884\u6d4b\u70b9\u8ddd\u79bb\u771f\u5b9e\u70b9\u7684\u6b27\u51e0\u91cc\u5f97\u8ddd\u79bb\u5c0f\u4e8e0.5\u7684\u9884\u6d4b\u70b9\u7684\u6bd4\u4f8b\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u6a21\u578b\u7684\u6027\u80fd<\/h1>\n\n\n\n<p>\u7531\u4e8e\u5728\u6a21\u578b\u7684\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\uff0c\u91c7\u7528\u56fe3\u7684\u7f51\u7edc\u67b6\u6784\u8bad\u7ec3\u7684\u6548\u679c\u4e0d\u662f\u5f88\u597d\uff0c\u6211\u4eec\u91cd\u65b0\u6839\u636e\u56fe3\u7684\u57fa\u672c\u601d\u8def\u5728\u7279\u5f81\u63d0\u53d6\u9636\u6bb5\u6dfb\u52a0\u4e86\u4e0b\u91c7\u6837\u7684\u8fc7\u7a0b\uff0c\u4ee5\u53ca\u5728\u5750\u6807\u9884\u6d4b\u5206\u652f\u4e2d\u5c06\u7ebf\u6027\u5c42\u66ff\u6362\u4e3a\u6b8b\u5deeMLP\u7ed3\u6784\uff0c\u5177\u4f53\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class ResBlock(nn.Module):\n    def __init__(self, channels: int):\n        super().__init__()\n        self.conv1 = nn.Conv2d(channels, channels, kernel_size=3, padding=1, bias=False)\n        self.bn1 = nn.BatchNorm2d(channels)\n        self.conv2 = nn.Conv2d(channels, channels, kernel_size=3, padding=1, bias=False)\n        self.bn2 = nn.BatchNorm2d(channels)\n\n    def forward(self, x):\n        identity = x\n        out = F.relu(self.bn1(self.conv1(x)), inplace=True)\n        out = self.bn2(self.conv2(out))\n        return F.relu(out + identity, inplace=True)\n\nclass DownBlock(nn.Module):\n    def __init__(self, in_channels, out_channels, dropout_rate=0.0, use_resblock=True):\n        super().__init__()\n        self.down = nn.Sequential(\n            nn.Conv2d(in_channels, out_channels, kernel_size=4, stride=2, padding=1, bias=False),\n            nn.BatchNorm2d(out_channels),\n            nn.ReLU(inplace=True),\n        )\n        self.res = ResBlock(out_channels) if use_resblock else nn.Identity()\n        self.dropout = nn.Dropout2d(dropout_rate) if dropout_rate &gt; 0 else nn.Identity()\n\n    def forward(self, x):\n        x = self.down(x)\n        x = self.res(x)\n        x = self.dropout(x)\n        return x\n\nclass ResidualCoordHead(nn.Module):\n    def __init__(self, hidden_dim, max_points):\n        super().__init__()\n        self.max_points = max_points\n\n        self.fc1 = nn.Linear(hidden_dim, hidden_dim)\n        self.norm1 = nn.LayerNorm(hidden_dim)\n        self.dropout1 = nn.Dropout(0.2)\n\n        self.fc2 = nn.Linear(hidden_dim, hidden_dim \/\/ 2)\n        self.norm2 = nn.LayerNorm(hidden_dim \/\/ 2)\n        self.dropout2 = nn.Dropout(0.2)\n\n        self.output_layer = nn.Linear(hidden_dim \/\/ 2, max_points * 2)\n        self.shortcut = nn.Linear(hidden_dim, hidden_dim \/\/ 2)\n\n    def forward(self, x):\n        residual = self.shortcut(x)\n        x = F.relu(self.norm1(self.fc1(x)))\n        x = self.dropout1(x)\n        x = F.relu(self.norm2(self.fc2(x)))\n        x = self.dropout2(x)\n        return self.output_layer(x + residual)\n\nclass CNN4TwoStage(nn.Module):\n    def __init__(\n        self,\n        in_channels=1,\n        base_channels=32,\n        max_points=10,\n        hidden_dim=128,\n        num_down_blocks=6,\n        dropout_rate=0.3,\n        use_resblock=True,\n    ):\n        super().__init__()\n        self.max_points = max_points\n\n        # \u6784\u5efa DownBlock \u5217\u8868\n        self.down_blocks = nn.ModuleList()\n        channels = &#91;in_channels] + &#91;base_channels * (2 ** i) for i in range(num_down_blocks)]\n        for i in range(num_down_blocks):\n            self.down_blocks.append(DownBlock(\n                in_channels=channels&#91;i],\n                out_channels=channels&#91;i + 1],\n                dropout_rate=dropout_rate,\n                use_resblock=use_resblock\n            ))\n\n        self.global_pool = nn.AdaptiveAvgPool2d((1, 1))\n        final_channel = channels&#91;-1]\n\n        self.fc_feature = nn.Sequential(\n            nn.Flatten(),\n            nn.Linear(final_channel, hidden_dim),\n            nn.ReLU(inplace=True),\n            nn.Dropout(dropout_rate),\n        )\n\n        self.number_fc = nn.Linear(hidden_dim, 1)\n        self.coord_fc = ResidualCoordHead(hidden_dim, max_points)\n\n    def forward(self, x):\n        batch_size = x.size(0)\n        device = x.device\n\n        for block in self.down_blocks:\n            x = block(x)\n\n        x = self.global_pool(x)\n        feat = self.fc_feature(x)\n\n        num_pred = self.number_fc(feat).squeeze(-1)  # (B,)\n        coord_pred = self.coord_fc(feat)  # (B, max_points * 2)\n\n        coords_list = &#91;]\n        for i in range(batch_size):\n            n_i = int(torch.round(num_pred&#91;i]).clamp(1, self.max_points).item())\n            coords_i = coord_pred&#91;i, :n_i * 2].view(n_i, 2)\n            coords_list.append(coords_i)\n\n        coords_all = torch.cat(coords_list, dim=0) if coords_list else torch.empty(0, 2, device=device)\n        return num_pred, coords_all<\/code><\/pre>\n\n\n\n<p>\u6211\u5927\u6982\u505a\u4e86\u4e00\u4e9b\u7b80\u5355\u7684\u5bf9\u6bd4\u5b9e\u9a8c\u6765\u6d4b\u91cf\u6a21\u578b\u7684\u57fa\u672c\u6027\u80fd\uff0c\u518d\u8fdb\u884c\u8bad\u7ec3\u524d\uff0c\u4e3a\u4e86\u5b9e\u9a8c\u7684\u53ef\u590d\u73b0\u6027\uff0c\u6211\u8bbe\u7f6e\u4e86\u968f\u673a\u79cd\u5b50\u8fdb\u884c\u521d\u59cb\u5316\u6a21\u578b\u53c2\u6570\uff0c\u4ee3\u7801\u5982\u4e0b\uff0c\u8bb0\u4f4f\u8fd9\u4e2a\u51fd\u6570\u9700\u8981\u653e\u5728\u5bfc\u5e93\u540e\u4ee5\u53ca\u6240\u6709\u51fd\u6570\u524d\uff0c\u5e76\u4e14\u9700\u8981\u5728\u6240\u6709\u51fd\u6570\u524d\u8c03\u7528\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def set_seed(seed: int = 42):\n    random.seed(seed)\n    np.random.seed(seed)\n    torch.manual_seed(seed)\n    torch.cuda.manual_seed(seed)\n    torch.cuda.manual_seed_all(seed)  # if using multi-GPU\n    torch.backends.cudnn.deterministic = True\n    torch.backends.cudnn.benchmark = False\n\nset_seed()<\/code><\/pre>\n\n\n\n<p style=\"font-size:25px\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">\u7279\u522b\u6ce8\u610f\u672c\u6587\u4e2d\u53ea\u63a2\u7a76Idea\u7684\u53ef\u5b9e\u73b0\u6027\uff0c\u800c\u4e0d\u505a\u4e25\u8c28\u7684\u63a2\u8ba8\uff08\u6bd4\u5982\u8bf4\u8fd8\u9700\u8981\u5728\u9a8c\u8bc1\u96c6\u4e0a\u8fdb\u884c\u6d4b\u8bd5\u7b49\uff09<\/mark><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u6548\u679c\u9a8c\u8bc1<\/h2>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"394\" src=\"http:\/\/jieyekang.com\/wp-content\/uploads\/2025\/06\/1749819904-\u56fe\u7247-1-1024x394.png\" alt=\"\" class=\"wp-image-267\" style=\"width:578px;height:auto\" srcset=\"http:\/\/jieyekang.com\/wp-content\/uploads\/2025\/06\/1749819904-\u56fe\u7247-1-1024x394.png 1024w, http:\/\/jieyekang.com\/wp-content\/uploads\/2025\/06\/1749819904-\u56fe\u7247-1-300x115.png 300w, http:\/\/jieyekang.com\/wp-content\/uploads\/2025\/06\/1749819904-\u56fe\u7247-1-768x295.png 768w, http:\/\/jieyekang.com\/wp-content\/uploads\/2025\/06\/1749819904-\u56fe\u7247-1-1536x590.png 1536w, http:\/\/jieyekang.com\/wp-content\/uploads\/2025\/06\/1749819904-\u56fe\u7247-1-2048x787.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">\u56fe4 \u5728\u4e0d\u540c\u6a21\u578b\u53c2\u6570\u91cf\u4e0b\u9636\u6bb51\u7684MSE\u635f\u5931\u51fd\u6570\u4ee5\u53ca\u9884\u6d4b\u51c6\u786e\u7387\u66f2\u7ebf<\/figcaption><\/figure>\n<\/div>\n\n\n<p>\u5982\u56fe4\uff0c\u6211\u4eec\u80fd\u591f\u770b\u5230\u9636\u6bb51\u4e2d\u7684MSE\u635f\u5931\u66f2\u7ebf\u548c\u9884\u6d4b\u51c6\u786e\u7387\u66f2\u7ebf\uff0c\u5747\u80fd\u770b\u5230loss\u90fd\u5728\u4e0b\u964d\uff0c\u6211\u4eec\u5148\u8fdb\u884c\u6a2a\u5411\u5bf9\u6bd4\uff0c\u4e5f\u5c31\u662f\u56fa\u5b9a\u9690\u85cf\u5c42\u4e3a128\uff0c\u7136\u540e\u5bf9\u6bd4\u5728\u4e0d\u540cBlock\u6570\u91cf\u4e0b\u7684\u6536\u655b\u60c5\u51b5\uff1b\u518d\u56fa\u5b9aBlock\u6570\u91cf\u4e3a7\uff0c\u7136\u540e\u518d\u5bf9\u6bd4\u4e0d\u540c\u9690\u85cf\u5c42\u6570\u91cf\u4e0b\u7684\u6536\u655b\u60c5\u51b5\u3002\u6839\u636eMSE\u635f\u5931\u56fe\u50cf\uff0c\u5f97\u5230\u7ed3\u8bba\u2014\u2014\u5728\u76f8\u540c\u9690\u85cf\u5c42\u4e0b\u589e\u52a0Block\u7684\u6570\u91cf\u4f1a\u52a0\u5feb\u6536\u655b\u901f\u5ea6\u548c\u6536\u655b\u6548\u679c\uff1b\u5728\u76f8\u540cBlock\u6570\u91cf\u4e0b\u589e\u52a0\u9690\u85cf\u5c42\u7ef4\u5ea6\u540c\u6837\u4e5f\u4f1a\u52a0\u5feb\u6536\u655b\u901f\u5ea6\u548c\u6536\u655b\u6548\u679c\u3002 \u5f53\u7136\uff0c\u4e5f\u53ef\u4ee5\u770b\u5230\u51c6\u786e\u7387\u7684\u66f2\u7ebf\u4e5f\u7b26\u5408MSE\u635f\u5931\u56fe\u50cf\u5f97\u5230\u7684\u7ed3\u8bba\u3002<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"502\" height=\"384\" src=\"http:\/\/jieyekang.com\/wp-content\/uploads\/2025\/06\/1749820347-image.png\" alt=\"\" class=\"wp-image-271\" style=\"width:374px;height:auto\" srcset=\"http:\/\/jieyekang.com\/wp-content\/uploads\/2025\/06\/1749820347-image.png 502w, http:\/\/jieyekang.com\/wp-content\/uploads\/2025\/06\/1749820347-image-300x229.png 300w\" sizes=\"auto, (max-width: 502px) 100vw, 502px\" \/><figcaption class=\"wp-element-caption\">\u56fe5 \u5728\u4e0d\u540c\u6a21\u578b\u53c2\u6570\u91cf\u4e0b\u9636\u6bb52\u7684MSE\u635f\u5931\u66f2\u7ebf<\/figcaption><\/figure>\n<\/div>\n\n\n<p>\u5982\u56fe5\uff0c\u7531\u9636\u6bb52\u4e2d\u7684MSE\u635f\u5931\u56fe\u50cf\u4f9d\u65e7\u53ef\u4ee5\u5f97\u5230\u9636\u6bb51\u4e2d\u7684\u7ed3\u8bba\uff0c\u540c\u6837\u8bc1\u660e\u4e86\u201c\u5728\u76f8\u540c\u9690\u85cf\u5c42\u4e0b\u589e\u52a0Block\u7684\u6570\u91cf\u4f1a\u52a0\u5feb\u6536\u655b\u901f\u5ea6\u548c\u6536\u655b\u6548\u679c\uff1b\u5728\u76f8\u540cBlock\u6570\u91cf\u4e0b\u589e\u52a0\u9690\u85cf\u5c42\u7ef4\u5ea6\u540c\u6837\u4e5f\u4f1a\u52a0\u5feb\u6536\u655b\u901f\u5ea6\u548c\u6536\u655b\u6548\u679c\u201d\u3002<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"522\" src=\"http:\/\/jieyekang.com\/wp-content\/uploads\/2025\/06\/1749819676-\u56fe\u7247-1-1024x522.png\" alt=\"\" class=\"wp-image-265\" srcset=\"http:\/\/jieyekang.com\/wp-content\/uploads\/2025\/06\/1749819676-\u56fe\u7247-1-1024x522.png 1024w, http:\/\/jieyekang.com\/wp-content\/uploads\/2025\/06\/1749819676-\u56fe\u7247-1-300x153.png 300w, http:\/\/jieyekang.com\/wp-content\/uploads\/2025\/06\/1749819676-\u56fe\u7247-1-768x391.png 768w, http:\/\/jieyekang.com\/wp-content\/uploads\/2025\/06\/1749819676-\u56fe\u7247-1-1536x783.png 1536w, http:\/\/jieyekang.com\/wp-content\/uploads\/2025\/06\/1749819676-\u56fe\u7247-1-2048x1044.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">\u56fe6 \u5728\u4e0d\u540c\u8ddd\u79bb\u5bb9\u5dee\u4e0b\u7684\u4e0d\u540c\u6a21\u578b\u53c2\u6570\u91cf\u7684\u9636\u6bb52\u7684\u51c6\u786e\u7387\u66f2\u7ebf<\/figcaption><\/figure>\n<\/div>\n\n\n<p>\u5982\u56fe6\uff0c\u6211\u8fd8\u63a2\u7a76\u4e86\u5728\u8bbe\u7f6e\u7684\u4e0d\u540c\u8ddd\u79bb\u5bb9\u5dee\u4e0b\uff0c\u9636\u6bb52\u7684\u51c6\u786e\u7387\u60c5\u51b5\u3002\u6211\u53d1\u73b0\u6a21\u578b\u9884\u6d4b\u7684\u7cbe\u5ea6\u5927\u6982\u662f\u57280.1\uff5e0.2\u5de6\u53f3\uff0c\u56e0\u4e3a\u6a21\u578b\u5728\u8ddd\u79bb\u5bb9\u5dee\u4e3a0.5\uff0c0.4\uff0c0.3\u7684\u60c5\u51b5\u4e0b\u90fd\u80fd\u591f\u4fdd\u630190%\u4ee5\u4e0a\u9ad8\u51c6\u786e\u7387\u7684\u6548\u679c\uff0c\u5728\u8ddd\u79bb\u5bb9\u5dee\u4e3a0.2\u65f6\uff0c\u6a21\u578b\u7684\u51c6\u786e\u7387\u4e0b\u964d\u660e\u663e\uff0c\u5c3d\u7ba1\u540c\u6837\u6709\u63a5\u8fd180%\u7684\u51c6\u786e\u7387\uff0c\u4f46\u662f\u5f53\u5bb9\u5dee\u4e3a0.1\u65f6\uff0c\u6a21\u578b\u7684\u51c6\u786e\u7387\u65ad\u5d16\u5f0f\u4e0b\u964d\uff0c\u867d\u7136\u4f7f\u75287-256\uff08Block\u6570\u91cf\u4e3a7\uff0c\u9690\u85cf\u5c42\u7ef4\u5ea6\u4e3a256\uff09\u7684\u6a21\u578b\u7684\u51c6\u786e\u7387\u6bd4\u5176\u4ed6\u6a21\u578b\u51c6\u786e\u7387\u8981\u9ad8\u5f97\u591a\uff0c\u4f46\u662f\u51c6\u786e\u7387\u4ecd\u7136\u5f88\u4f4e\uff08\u4f4e\u4e8e35%\uff09\u3002\u6240\u4ee5\u80fd\u591f\u77e5\u9053\u6a21\u578b\u7684\u5750\u6807\u9884\u6d4b\u7cbe\u5ea6\u4e3a0.1\uff5e0.2\u5de6\u53f3\uff0c\u603b\u4f53\u4e0a\u9884\u6d4b\u6548\u679c\u4e0d\u9519\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u6027\u80fd\u6307\u6807<\/h2>\n\n\n\n<p>\u63a5\u4e0b\u6765\u6211\u4f1a\u4ee5\u6570\u503c\u7684\u5f62\u5f0f\u6765\u7814\u7a76\u6a21\u578b\u7684\u6548\u679c\uff0c\u4f46\u662f\u5177\u4f53\u6570\u503c\u8868\u793a\u7684\u610f\u4e49\u5c31\u4e0d\u518d\u8d58\u8ff0\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td class=\"has-text-align-center\" data-align=\"center\">Blocks<\/td><td class=\"has-text-align-center\" data-align=\"center\">Hidden Dim<\/td><td class=\"has-text-align-center\" data-align=\"center\">Num MSE<\/td><td class=\"has-text-align-center\" data-align=\"center\">Coord MSE<\/td><td class=\"has-text-align-center\" data-align=\"center\">Num Acc<\/td><td class=\"has-text-align-center\" data-align=\"center\">Num Time<\/td><td class=\"has-text-align-center\" data-align=\"center\">Coord Time<\/td><td class=\"has-text-align-center\" data-align=\"center\">Param<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">4<\/td><td class=\"has-text-align-center\" data-align=\"center\">128<\/td><td class=\"has-text-align-center\" data-align=\"center\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-cyan-blue-color\">0.714229<\/mark><\/td><td class=\"has-text-align-center\" data-align=\"center\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-cyan-blue-color\">0.418045<\/mark><\/td><td class=\"has-text-align-center\" data-align=\"center\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-cyan-blue-color\">84.00%<\/mark><\/td><td class=\"has-text-align-center\" data-align=\"center\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-cyan-blue-color\">499<\/mark><\/td><td class=\"has-text-align-center\" data-align=\"center\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-cyan-blue-color\">807<\/mark><\/td><td class=\"has-text-align-center\" data-align=\"center\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-cyan-blue-color\">2.2M<\/mark><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">5<\/td><td class=\"has-text-align-center\" data-align=\"center\">128<\/td><td class=\"has-text-align-center\" data-align=\"center\">0.316047<\/td><td class=\"has-text-align-center\" data-align=\"center\">0.296123<\/td><td class=\"has-text-align-center\" data-align=\"center\">94.67%<\/td><td class=\"has-text-align-center\" data-align=\"center\">513<\/td><td class=\"has-text-align-center\" data-align=\"center\">814<\/td><td class=\"has-text-align-center\" data-align=\"center\">8.8M<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">6<\/td><td class=\"has-text-align-center\" data-align=\"center\">128<\/td><td class=\"has-text-align-center\" data-align=\"center\">0.243847<\/td><td class=\"has-text-align-center\" data-align=\"center\">0.113514<\/td><td class=\"has-text-align-center\" data-align=\"center\">97.67%<\/td><td class=\"has-text-align-center\" data-align=\"center\">537<\/td><td class=\"has-text-align-center\" data-align=\"center\">822<\/td><td class=\"has-text-align-center\" data-align=\"center\">34.8M<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">7<\/td><td class=\"has-text-align-center\" data-align=\"center\">128<\/td><td class=\"has-text-align-center\" data-align=\"center\">0.250646<\/td><td class=\"has-text-align-center\" data-align=\"center\">0.103853<\/td><td class=\"has-text-align-center\" data-align=\"center\">97.00%<\/td><td class=\"has-text-align-center\" data-align=\"center\">542<\/td><td class=\"has-text-align-center\" data-align=\"center\">889<\/td><td class=\"has-text-align-center\" data-align=\"center\">138.9M<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">7<\/td><td class=\"has-text-align-center\" data-align=\"center\">256<\/td><td class=\"has-text-align-center\" data-align=\"center\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">0.159434<\/mark><\/td><td class=\"has-text-align-center\" data-align=\"center\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">0.070690<\/mark><\/td><td class=\"has-text-align-center\" data-align=\"center\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">99.33%<\/mark><\/td><td class=\"has-text-align-center\" data-align=\"center\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">579<\/mark><\/td><td class=\"has-text-align-center\" data-align=\"center\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">904<\/mark><\/td><td class=\"has-text-align-center\" data-align=\"center\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">139.3M<\/mark><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u6a21\u578b7-256\u5728\u5404\u65b9\u9762\u5747\u8fdc\u4f18\u4e8e\u6a21\u578b4-128\uff0c\u5176\u4e2dNum MSE\u4e0b\u964d\u4e86\u7ea6<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\">78.87%<\/mark>\uff0cCoord MSE\u4e0b\u964d\u4e86\u7ea6<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\">83.25%<\/mark>\uff0cNum Acc\u63d0\u9ad8\u4e86\u7ea6<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\">15.33%<\/mark>\uff0c\u4f46\u662f\u65f6\u95f4\u5f00\u9500\u6210\u672c\u5206\u522b\u53ea\u589e\u52a0\u4e86<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\">16%<\/mark>\u548c<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\">12%<\/mark>\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td class=\"has-text-align-center\" data-align=\"center\">Blocks<\/td><td class=\"has-text-align-center\" data-align=\"center\">Hidden Dim<\/td><td class=\"has-text-align-center\" data-align=\"center\">Coord(0.5)<\/td><td class=\"has-text-align-center\" data-align=\"center\">Coord(0.4)<\/td><td class=\"has-text-align-center\" data-align=\"center\">Coord(0.3)<\/td><td class=\"has-text-align-center\" data-align=\"center\">Coord(0.2)<\/td><td class=\"has-text-align-center\" data-align=\"center\">Coord(0.1)<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">4<\/td><td class=\"has-text-align-center\" data-align=\"center\">128<\/td><td class=\"has-text-align-center\" data-align=\"center\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-cyan-blue-color\">81.65%<\/mark><\/td><td class=\"has-text-align-center\" data-align=\"center\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-cyan-blue-color\">53.01%<\/mark><\/td><td class=\"has-text-align-center\" data-align=\"center\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-cyan-blue-color\">29.52%<\/mark><\/td><td class=\"has-text-align-center\" data-align=\"center\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-cyan-blue-color\">14.09%<\/mark><\/td><td class=\"has-text-align-center\" data-align=\"center\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-cyan-blue-color\">4.24%<\/mark><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">5<\/td><td class=\"has-text-align-center\" data-align=\"center\">128<\/td><td class=\"has-text-align-center\" data-align=\"center\">90.39%<\/td><td class=\"has-text-align-center\" data-align=\"center\">73.82%<\/td><td class=\"has-text-align-center\" data-align=\"center\">49.58%<\/td><td class=\"has-text-align-center\" data-align=\"center\">25.25%<\/td><td class=\"has-text-align-center\" data-align=\"center\">7.59%<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">6<\/td><td class=\"has-text-align-center\" data-align=\"center\">128<\/td><td class=\"has-text-align-center\" data-align=\"center\">99.83%<\/td><td class=\"has-text-align-center\" data-align=\"center\">96.95%<\/td><td class=\"has-text-align-center\" data-align=\"center\">86.80%<\/td><td class=\"has-text-align-center\" data-align=\"center\">62.75%<\/td><td class=\"has-text-align-center\" data-align=\"center\">23.74%<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">7<\/td><td class=\"has-text-align-center\" data-align=\"center\">128<\/td><td class=\"has-text-align-center\" data-align=\"center\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">100%<\/mark><\/td><td class=\"has-text-align-center\" data-align=\"center\">97.97%<\/td><td class=\"has-text-align-center\" data-align=\"center\">88.18%<\/td><td class=\"has-text-align-center\" data-align=\"center\">66.78%<\/td><td class=\"has-text-align-center\" data-align=\"center\">25.50%<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">7<\/td><td class=\"has-text-align-center\" data-align=\"center\">256<\/td><td class=\"has-text-align-center\" data-align=\"center\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">100%<\/mark><\/td><td class=\"has-text-align-center\" data-align=\"center\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">99.66%<\/mark><\/td><td class=\"has-text-align-center\" data-align=\"center\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">95.81%<\/mark><\/td><td class=\"has-text-align-center\" data-align=\"center\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">77.76%<\/mark><\/td><td class=\"has-text-align-center\" data-align=\"center\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">36.29%<\/mark><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u5982\u4e0a\u8868\u793a\uff0c\u5728\u786e\u5b9a\u7cbe\u5ea6\u7684\u65f6\uff0c\u6a21\u578b7-256\u4f9d\u65e7\u8981\u5728\u5404\u65b9\u9762\u8fdc\u4f18\u4e8e\u6a21\u578b4-128\uff0c\u5f53\u8ddd\u79bb\u5bb9\u5dee\u5206\u522b\u4e3a0.5\uff0c0.4\uff0c0.3\uff0c0.2\uff0c0.1\u65f6\uff0c\u9884\u6d4b\u7684\u51c6\u786e\u7387\uff08\u7cbe\u51c6\u5ea6\uff09\u5206\u522b\u63d0\u9ad8\u4e86<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\">18%<\/mark>\uff0c<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\">46%<\/mark>\uff0c<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\">66%<\/mark>\uff0c<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\">63%<\/mark>\uff0c<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\">32%<\/mark>\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u5c0f\u7ed3<\/h1>\n\n\n\n<p>\u603b\u4f53\u4e0a\u6765\u770b\uff0c\u672c\u6587\u7684\u7ea7\u8054\u795e\u7ecf\u7f51\u7edc\u7684Idea\u662f\u53ef\u884c\u7684\uff0c\u4f46\u662f\u5728\u5177\u4f53\u7684\u5b9e\u9a8c\u8fc7\u7a0b\u4e2d\u8fd8\u662f\u4f1a\u6709\u4e00\u4e9b\u4e0d\u4e25\u8c28\u7684\u5730\u65b9\u5b58\u5728\uff0c\u4f8b\u5982\u751f\u6210\u6570\u636e\u96c6\u7684\u65f6\u5019\u91c7\u7528\u7684\u968f\u673a\u5750\u6807\u8bbe\u7f6e\uff0c\u8fd9\u4e2a\u4e5f\u7b97\u4e0a\u53e6\u5916\u4e00\u79cd\u6570\u636e\u6c61\u67d3\u5427\uff0c\u8fd8\u6709\u5728\u5b9e\u9a8c\u4e2d\u6ca1\u6709\u8bbe\u7f6e\u9a8c\u8bc1\u96c6\u548c\u6d4b\u8bd5\u96c6\uff0c\u5f53\u7136\u8fd8\u6709\u5f88\u591a\u5176\u4ed6\u7684\u95ee\u9898\uff0c\u5728\u6b64\u5c31\u4e0d\u518d\u8d58\u8ff0\uff0c\u6700\u540e\u518d\u6b21\u5f3a\u8c03\u672c\u6587\u53ea\u662f\u7528\u4e8e\u9a8c\u8bc1Idea\u7684\u53ef\u5b9e\u73b0\u6027\uff0c\u5e76\u975e\u662f\u4e00\u7bc7\u4e25\u8c28\u7684\u8bba\u6587\u6216\u8005\u6280\u672f\u5206\u4eab\u5e16\uff0c\u611f\u8c22\u7406\u89e3\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00 \u5728\u6700\u8fd1\u7684\u79d1\u7814\u751f\u6d3b\u4e2d\uff0c\u6211\u65f6\u5e38\u9047\u4e0a\u5f88\u6709\u610f\u601d\u7684\u5c0f\u95ee\u9898\uff0c\u5728\u6b64\u6211\u5f00\u4e00\u4e2a\u4e13\u680f\u4e13\u95e8\u8bb0\u5f55\u4e0b\u6211\u5df2\u7ecf\u89e3\u51b3\u7684\u548c\u672a\u66fe\u89e3\u51b3\u7684\u5c0f\u7075\u611f\u3002 \u95ee\u9898\u8bf4\u660e \u5c0f\u7075\u611f &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[1],"tags":[9],"class_list":["post-209","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-9"],"_links":{"self":[{"href":"http:\/\/jieyekang.com\/index.php\/wp-json\/wp\/v2\/posts\/209","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/jieyekang.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/jieyekang.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/jieyekang.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/jieyekang.com\/index.php\/wp-json\/wp\/v2\/comments?post=209"}],"version-history":[{"count":68,"href":"http:\/\/jieyekang.com\/index.php\/wp-json\/wp\/v2\/posts\/209\/revisions"}],"predecessor-version":[{"id":287,"href":"http:\/\/jieyekang.com\/index.php\/wp-json\/wp\/v2\/posts\/209\/revisions\/287"}],"wp:attachment":[{"href":"http:\/\/jieyekang.com\/index.php\/wp-json\/wp\/v2\/media?parent=209"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/jieyekang.com\/index.php\/wp-json\/wp\/v2\/categories?post=209"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/jieyekang.com\/index.php\/wp-json\/wp\/v2\/tags?post=209"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}