mirror of
https://github.com/wjlin0/wjlin0.github.io.git
synced 2026-10-27 19:10:50 +00:00
1 line
17 KiB
JavaScript
1 line
17 KiB
JavaScript
"use strict";(globalThis.webpackChunkblog=globalThis.webpackChunkblog||[]).push([[2447],{20429:(n,e,l)=>{l.r(e),l.d(e,{assets:()=>r,contentTitle:()=>o,default:()=>h,frontMatter:()=>c,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"\u4e2a\u4eba\u77e5\u8bc6\u5e93/AI/PyTorch/\u7b2c\u4e94\u7ae0/5.2 \u5229\u7528\u6a21\u578b\u5757\u5feb\u901f\u642d\u5efa\u590d\u6742\u7f51\u7edc","title":"5.2 \u5229\u7528\u6a21\u578b\u5757\u5feb\u901f\u642d\u5efa\u590d\u6742\u7f51\u7edc.md","description":"|\u4f5c\u8005|\u4fee\u8ba2\u65f6\u95f4|","source":"@site/docs/\u4e2a\u4eba\u77e5\u8bc6\u5e93/10.AI/01.PyTorch/05.\u7b2c\u4e94\u7ae0/5.2 \u5229\u7528\u6a21\u578b\u5757\u5feb\u901f\u642d\u5efa\u590d\u6742\u7f51\u7edc.md","sourceDirName":"\u4e2a\u4eba\u77e5\u8bc6\u5e93/10.AI/01.PyTorch/05.\u7b2c\u4e94\u7ae0","slug":"/\u4e2a\u4eba\u77e5\u8bc6\u5e93/AI/PyTorch/\u7b2c\u4e94\u7ae0/5.2 \u5229\u7528\u6a21\u578b\u5757\u5feb\u901f\u642d\u5efa\u590d\u6742\u7f51\u7edc","permalink":"/docs/\u4e2a\u4eba\u77e5\u8bc6\u5e93/AI/PyTorch/\u7b2c\u4e94\u7ae0/5.2 \u5229\u7528\u6a21\u578b\u5757\u5feb\u901f\u642d\u5efa\u590d\u6742\u7f51\u7edc","draft":false,"unlisted":false,"editUrl":"https://github.com/facebook/docusaurus/tree/main/packages/create-docusaurus/templates/shared/docs/\u4e2a\u4eba\u77e5\u8bc6\u5e93/10.AI/01.PyTorch/05.\u7b2c\u4e94\u7ae0/5.2 \u5229\u7528\u6a21\u578b\u5757\u5feb\u901f\u642d\u5efa\u590d\u6742\u7f51\u7edc.md","tags":[],"version":"current","frontMatter":{},"sidebar":"tutorialSidebar","previous":{"title":"5.1 PyTorch\u6a21\u578b\u5b9a\u4e49\u7684\u65b9\u5f0f.md","permalink":"/docs/\u4e2a\u4eba\u77e5\u8bc6\u5e93/AI/PyTorch/\u7b2c\u4e94\u7ae0/5.1 PyTorch\u6a21\u578b\u5b9a\u4e49\u7684\u65b9\u5f0f"},"next":{"title":"5.3 PyTorch\u4fee\u6539\u6a21\u578b.md","permalink":"/docs/\u4e2a\u4eba\u77e5\u8bc6\u5e93/AI/PyTorch/\u7b2c\u4e94\u7ae0/5.3 PyTorch\u4fee\u6539\u6a21\u578b"}}');var i=l(74848),t=l(28453);const c={},o="5.2 \u5229\u7528\u6a21\u578b\u5757\u5feb\u901f\u642d\u5efa\u590d\u6742\u7f51\u7edc.md",r={},d=[{value:"5.2.1 U-Net\u7b80\u4ecb",id:"521-u-net\u7b80\u4ecb",level:2},{value:"5.2.2 U-Net\u6a21\u578b\u5757\u5206\u6790",id:"522-u-net\u6a21\u578b\u5757\u5206\u6790",level:2},{value:"5.2.3 U-Net\u6a21\u578b\u5757\u5b9e\u73b0",id:"523-u-net\u6a21\u578b\u5757\u5b9e\u73b0",level:2},{value:"5.2.4 \u5229\u7528\u6a21\u578b\u5757\u7ec4\u88c5U-Net",id:"524-\u5229\u7528\u6a21\u578b\u5757\u7ec4\u88c5u-net",level:2},{value:"\u53c2\u8003\u8d44\u6599",id:"\u53c2\u8003\u8d44\u6599",level:2}];function a(n){const e={a:"a",code:"code",h1:"h1",h2:"h2",header:"header",img:"img",li:"li",ol:"ol",p:"p",pre:"pre",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,t.R)(),...n.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(e.header,{children:(0,i.jsx)(e.h1,{id:"52-\u5229\u7528\u6a21\u578b\u5757\u5feb\u901f\u642d\u5efa\u590d\u6742\u7f51\u7edcmd",children:"5.2 \u5229\u7528\u6a21\u578b\u5757\u5feb\u901f\u642d\u5efa\u590d\u6742\u7f51\u7edc.md"})}),"\n\n\n\n\n\n\n\n\n\n\n\n\n\n",(0,i.jsxs)(e.table,{children:[(0,i.jsx)(e.thead,{children:(0,i.jsxs)(e.tr,{children:[(0,i.jsx)(e.th,{style:{textAlign:"left"},children:"\u4f5c\u8005"}),(0,i.jsx)(e.th,{style:{textAlign:"left"},children:"\u4fee\u8ba2\u65f6\u95f4"})]})}),(0,i.jsx)(e.tbody,{children:(0,i.jsxs)(e.tr,{children:[(0,i.jsx)(e.td,{style:{textAlign:"left"},children:(0,i.jsx)(e.img,{src:"https://img.shields.io/badge/wjlin0-%E4%B8%AA%E4%BA%BA%E7%9F%A5%E8%AF%86%E5%BA%93-green",alt:"wjlin0"})}),(0,i.jsx)(e.td,{style:{textAlign:"left"},children:"2026-06-07 20:53:18"})]})})]}),"\n\n\n\n\n\n\n\n\n\n\n\n\n\n",(0,i.jsxs)(e.table,{children:[(0,i.jsx)(e.thead,{children:(0,i.jsxs)(e.tr,{children:[(0,i.jsx)(e.th,{style:{textAlign:"left"},children:"\u4f5c\u8005"}),(0,i.jsx)(e.th,{style:{textAlign:"left"},children:"\u4fee\u8ba2\u65f6\u95f4"})]})}),(0,i.jsx)(e.tbody,{children:(0,i.jsxs)(e.tr,{children:[(0,i.jsx)(e.td,{style:{textAlign:"left"},children:(0,i.jsx)(e.img,{src:"https://img.shields.io/badge/wjlin0-%E4%B8%AA%E4%BA%BA%E7%9F%A5%E8%AF%86%E5%BA%93-green",alt:"wjlin0"})}),(0,i.jsx)(e.td,{style:{textAlign:"left"},children:"2025-10-31 15:44:29"})]})})]}),"\n",(0,i.jsx)(e.h1,{id:"52-\u5229\u7528\u6a21\u578b\u5757\u5feb\u901f\u642d\u5efa\u590d\u6742\u7f51\u7edc",children:"5.2 \u5229\u7528\u6a21\u578b\u5757\u5feb\u901f\u642d\u5efa\u590d\u6742\u7f51\u7edc"}),"\n",(0,i.jsxs)(e.p,{children:["\u4e0a\u4e00\u8282\u4e2d\u6211\u4eec\u4ecb\u7ecd\u4e86\u600e\u6837\u5b9a\u4e49PyTorch\u7684\u6a21\u578b\uff0c\u5176\u4e2d\u7ed9\u51fa\u7684\u793a\u4f8b\u90fd\u662f\u7528",(0,i.jsx)(e.code,{children:"torch.nn"}),"\u4e2d\u7684\u5c42\u6765\u5b8c\u6210\u7684\u3002\u8fd9\u79cd\u5b9a\u4e49\u65b9\u5f0f\u6613\u4e8e\u7406\u89e3\uff0c\u5728\u5b9e\u9645\u573a\u666f\u4e0b\u4e0d\u4e00\u5b9a\u5229\u4e8e\u4f7f\u7528\u3002\u5f53\u6a21\u578b\u7684\u6df1\u5ea6\u975e\u5e38\u5927\u65f6\u5019\uff0c\u4f7f\u7528",(0,i.jsx)(e.code,{children:"Sequential"}),"\u5b9a\u4e49\u6a21\u578b\u7ed3\u6784\u9700\u8981\u5411\u5176\u4e2d\u6dfb\u52a0\u51e0\u767e\u884c\u4ee3\u7801\uff0c\u4f7f\u7528\u8d77\u6765\u4e0d\u751a\u65b9\u4fbf\u3002"]}),"\n",(0,i.jsx)(e.p,{children:"\u5bf9\u4e8e\u5927\u90e8\u5206\u6a21\u578b\u7ed3\u6784\uff08\u6bd4\u5982ResNet\u3001DenseNet\u7b49\uff09\uff0c\u6211\u4eec\u4ed4\u7ec6\u89c2\u5bdf\u5c31\u4f1a\u53d1\u73b0\uff0c\u867d\u7136\u6a21\u578b\u6709\u5f88\u591a\u5c42\uff0c \u4f46\u662f\u5176\u4e2d\u6709\u5f88\u591a\u91cd\u590d\u51fa\u73b0\u7684\u7ed3\u6784\u3002\u8003\u8651\u5230\u6bcf\u4e00\u5c42\u6709\u5176\u8f93\u5165\u548c\u8f93\u51fa\uff0c\u82e5\u5e72\u5c42\u4e32\u8054\u6210\u7684\u201d\u6a21\u5757\u201c\u4e5f\u6709\u5176\u8f93\u5165\u548c\u8f93\u51fa\uff0c\u5982\u679c\u6211\u4eec\u80fd\u5c06\u8fd9\u4e9b\u91cd\u590d\u51fa\u73b0\u7684\u5c42\u5b9a\u4e49\u4e3a\u4e00\u4e2a\u201d\u6a21\u5757\u201c\uff0c\u6bcf\u6b21\u53ea\u9700\u8981\u5411\u7f51\u7edc\u4e2d\u6dfb\u52a0\u5bf9\u5e94\u7684\u6a21\u5757\u6765\u6784\u5efa\u6a21\u578b\uff0c\u8fd9\u6837\u5c06\u4f1a\u6781\u5927\u4fbf\u5229\u6a21\u578b\u6784\u5efa\u7684\u8fc7\u7a0b\u3002"}),"\n",(0,i.jsx)(e.p,{children:"\u672c\u8282\u6211\u4eec\u5c06\u4ee5U-Net\u4e3a\u4f8b\uff0c\u4ecb\u7ecd\u5982\u4f55\u6784\u5efa\u6a21\u578b\u5757\uff0c\u4ee5\u53ca\u5982\u4f55\u5229\u7528\u6a21\u578b\u5757\u5feb\u901f\u642d\u5efa\u590d\u6742\u6a21\u578b\u3002"}),"\n",(0,i.jsx)(e.p,{children:"\u7ecf\u8fc7\u672c\u8282\u7684\u5b66\u4e60\uff0c\u4f60\u5c06\u6536\u83b7\uff1a"}),"\n",(0,i.jsxs)(e.ul,{children:["\n",(0,i.jsx)(e.li,{children:"\u5229\u7528\u4e0a\u4e00\u8282\u5b66\u5230\u7684\u77e5\u8bc6\uff0c\u5c06\u7b80\u5355\u5c42\u6784\u5efa\u6210\u5177\u6709\u7279\u5b9a\u529f\u80fd\u7684\u6a21\u578b\u5757"}),"\n",(0,i.jsx)(e.li,{children:"\u5229\u7528\u6a21\u578b\u5757\u6784\u5efa\u590d\u6742\u7f51\u7edc"}),"\n"]}),"\n",(0,i.jsx)(e.h2,{id:"521-u-net\u7b80\u4ecb",children:"5.2.1 U-Net\u7b80\u4ecb"}),"\n",(0,i.jsx)(e.p,{children:"U-Net\u662f\u5206\u5272 (Segmentation) \u6a21\u578b\u7684\u6770\u4f5c\uff0c\u5728\u4ee5\u533b\u5b66\u5f71\u50cf\u4e3a\u4ee3\u8868\u7684\u8bf8\u591a\u9886\u57df\u6709\u7740\u5e7f\u6cdb\u7684\u5e94\u7528\u3002U-Net\u6a21\u578b\u7ed3\u6784\u5982\u4e0b\u56fe\u6240\u793a\uff0c\u901a\u8fc7\u6b8b\u5dee\u8fde\u63a5\u7ed3\u6784\u89e3\u51b3\u4e86\u6a21\u578b\u5b66\u4e60\u4e2d\u7684\u9000\u5316\u95ee\u9898\uff0c\u4f7f\u5f97\u795e\u7ecf\u7f51\u7edc\u7684\u6df1\u5ea6\u80fd\u591f\u4e0d\u65ad\u6269\u5c55\u3002"}),"\n",(0,i.jsx)(e.p,{children:(0,i.jsx)(e.img,{alt:"unet",src:l(54612).A+"",width:"1555",height:"1036"})}),"\n",(0,i.jsx)(e.h2,{id:"522-u-net\u6a21\u578b\u5757\u5206\u6790",children:"5.2.2 U-Net\u6a21\u578b\u5757\u5206\u6790"}),"\n",(0,i.jsx)(e.p,{children:"\u7ed3\u5408\u4e0a\u56fe\uff0c\u4e0d\u96be\u53d1\u73b0U-Net\u6a21\u578b\u5177\u6709\u975e\u5e38\u597d\u7684\u5bf9\u79f0\u6027\u3002\u6a21\u578b\u4ece\u4e0a\u5230\u4e0b\u5206\u4e3a\u82e5\u5e72\u5c42\uff0c\u6bcf\u5c42\u7531\u5de6\u4fa7\u548c\u53f3\u4fa7\u4e24\u4e2a\u6a21\u578b\u5757\u7ec4\u6210\uff0c\u6bcf\u4fa7\u7684\u6a21\u578b\u5757\u4e0e\u5176\u4e0a\u4e0b\u6a21\u578b\u5757\u4e4b\u95f4\u6709\u8fde\u63a5\uff1b\u540c\u65f6\u4f4d\u4e8e\u540c\u4e00\u5c42\u5de6\u53f3\u4e24\u4fa7\u7684\u6a21\u578b\u5757\u4e4b\u95f4\u4e5f\u6709\u8fde\u63a5\uff0c\u79f0\u4e3a\u201cSkip-connection\u201d\u3002\u6b64\u5916\u8fd8\u6709\u8f93\u5165\u548c\u8f93\u51fa\u5904\u7406\u7b49\u5176\u4ed6\u7ec4\u6210\u90e8\u5206\u3002\u7531\u4e8e\u6a21\u578b\u7684\u5f62\u72b6\u975e\u5e38\u50cf\u82f1\u6587\u5b57\u6bcd\u7684\u201cU\u201d\uff0c\u56e0\u6b64\u88ab\u547d\u540d\u4e3a\u201cU-Net\u201d\u3002"}),"\n",(0,i.jsx)(e.p,{children:"\u7ec4\u6210U-Net\u7684\u6a21\u578b\u5757\u4e3b\u8981\u6709\u5982\u4e0b\u51e0\u4e2a\u90e8\u5206\uff1a"}),"\n",(0,i.jsxs)(e.ul,{children:["\n",(0,i.jsxs)(e.li,{children:["\n",(0,i.jsx)(e.p,{children:"\u6bcf\u4e2a\u5b50\u5757\u5185\u90e8\u7684\u4e24\u6b21\u5377\u79ef\uff08Double Convolution\uff09"}),"\n"]}),"\n",(0,i.jsxs)(e.li,{children:["\n",(0,i.jsx)(e.p,{children:"\u5de6\u4fa7\u6a21\u578b\u5757\u4e4b\u95f4\u7684\u4e0b\u91c7\u6837\u8fde\u63a5\uff0c\u5373\u6700\u5927\u6c60\u5316\uff08Max pooling\uff09"}),"\n"]}),"\n",(0,i.jsxs)(e.li,{children:["\n",(0,i.jsx)(e.p,{children:"\u53f3\u4fa7\u6a21\u578b\u5757\u4e4b\u95f4\u7684\u4e0a\u91c7\u6837\u8fde\u63a5\uff08Up sampling\uff09"}),"\n"]}),"\n",(0,i.jsxs)(e.li,{children:["\n",(0,i.jsx)(e.p,{children:"\u8f93\u51fa\u5c42\u7684\u5904\u7406"}),"\n"]}),"\n"]}),"\n",(0,i.jsx)(e.p,{children:"\u9664\u6a21\u578b\u5757\u5916\uff0c\u8fd8\u6709\u6a21\u578b\u5757\u4e4b\u95f4\u7684\u6a2a\u5411\u8fde\u63a5\uff0c\u8f93\u5165\u548cU-Net\u5e95\u90e8\u7684\u8fde\u63a5\u7b49\u8ba1\u7b97\uff0c\u8fd9\u4e9b\u5355\u72ec\u7684\u64cd\u4f5c\u53ef\u4ee5\u901a\u8fc7forward\u51fd\u6570\u6765\u5b9e\u73b0\u3002"}),"\n",(0,i.jsx)(e.p,{children:"\u4e0b\u9762\u6211\u4eec\u7528PyTorch\u5148\u5b9e\u73b0\u4e0a\u8ff0\u7684\u6a21\u578b\u5757\uff0c\u7136\u540e\u518d\u5229\u7528\u5b9a\u4e49\u597d\u7684\u6a21\u578b\u5757\u6784\u5efaU-Net\u6a21\u578b\u3002"}),"\n",(0,i.jsx)(e.h2,{id:"523-u-net\u6a21\u578b\u5757\u5b9e\u73b0",children:"5.2.3 U-Net\u6a21\u578b\u5757\u5b9e\u73b0"}),"\n",(0,i.jsx)(e.p,{children:"\u5728\u4f7f\u7528PyTorch\u5b9e\u73b0U-Net\u6a21\u578b\u65f6\uff0c\u6211\u4eec\u4e0d\u5fc5\u628a\u6bcf\u4e00\u5c42\u6309\u5e8f\u6392\u5217\u663e\u5f0f\u5199\u51fa\uff0c\u8fd9\u6837\u592a\u9ebb\u70e6\u4e14\u4e0d\u5b9c\u8bfb\uff0c\u4e00\u79cd\u6bd4\u8f83\u597d\u7684\u65b9\u6cd5\u662f\u5148\u5b9a\u4e49\u597d\u6a21\u578b\u5757\uff0c\u518d\u5b9a\u4e49\u6a21\u578b\u5757\u4e4b\u95f4\u7684\u8fde\u63a5\u987a\u5e8f\u548c\u8ba1\u7b97\u65b9\u5f0f\u3002\u5c31\u597d\u6bd4\u88c5\u914d\u96f6\u4ef6\u4e00\u6837\uff0c\u6211\u4eec\u5148\u88c5\u914d\u597d\u4e00\u4e9b\u57fa\u7840\u7684\u90e8\u4ef6\uff0c\u4e4b\u540e\u518d\u7528\u8fd9\u4e9b\u53ef\u4ee5\u590d\u7528\u7684\u90e8\u4ef6\u5f97\u5230\u6574\u4e2a\u88c5\u914d\u4f53\u3002"}),"\n",(0,i.jsxs)(e.p,{children:["\u8fd9\u91cc\u7684\u57fa\u7840\u90e8\u4ef6\u5bf9\u5e94\u4e0a\u4e00\u8282\u5206\u6790\u7684\u56db\u4e2a\u6a21\u578b\u5757\uff0c\u6839\u636e\u529f\u80fd\u6211\u4eec\u5c06\u5176\u547d\u540d\u4e3a\uff1a",(0,i.jsx)(e.code,{children:"DoubleConv"}),", ",(0,i.jsx)(e.code,{children:"Down"}),", ",(0,i.jsx)(e.code,{children:"Up"}),", ",(0,i.jsx)(e.code,{children:"OutConv"}),"\u3002\u4e0b\u9762\u7ed9\u51faU-Net\u4e2d\u6a21\u578b\u5757\u7684PyTorch \u5b9e\u73b0\uff1a"]}),"\n",(0,i.jsx)(e.pre,{children:(0,i.jsx)(e.code,{className:"language-python",children:"import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\n"})}),"\n",(0,i.jsx)(e.pre,{children:(0,i.jsx)(e.code,{className:"language-python",children:'class DoubleConv(nn.Module):\n """(convolution => [BN] => ReLU) * 2"""\n\n def __init__(self, in_channels, out_channels, mid_channels=None):\n super().__init__()\n if not mid_channels:\n mid_channels = out_channels\n self.double_conv = nn.Sequential(\n nn.Conv2d(in_channels, mid_channels, kernel_size=3, padding=1, bias=False),\n nn.BatchNorm2d(mid_channels),\n nn.ReLU(inplace=True),\n nn.Conv2d(mid_channels, out_channels, kernel_size=3, padding=1, bias=False),\n nn.BatchNorm2d(out_channels),\n nn.ReLU(inplace=True)\n )\n\n def forward(self, x):\n return self.double_conv(x)\n\n'})}),"\n",(0,i.jsx)(e.pre,{children:(0,i.jsx)(e.code,{className:"language-python",children:'class Down(nn.Module):\n """Downscaling with maxpool then double conv"""\n\n def __init__(self, in_channels, out_channels):\n super().__init__()\n self.maxpool_conv = nn.Sequential(\n nn.MaxPool2d(2),\n DoubleConv(in_channels, out_channels)\n )\n\n def forward(self, x):\n return self.maxpool_conv(x)\n\n'})}),"\n",(0,i.jsx)(e.pre,{children:(0,i.jsx)(e.code,{className:"language-python",children:'class Up(nn.Module):\n """Upscaling then double conv"""\n\n def __init__(self, in_channels, out_channels, bilinear=False):\n super().__init__()\n\n # if bilinear, use the normal convolutions to reduce the number of channels\n if bilinear:\n self.up = nn.Upsample(scale_factor=2, mode=\'bilinear\', align_corners=True)\n self.conv = DoubleConv(in_channels, out_channels, in_channels // 2)\n else:\n self.up = nn.ConvTranspose2d(in_channels, in_channels // 2, kernel_size=2, stride=2)\n self.conv = DoubleConv(in_channels, out_channels)\n\n def forward(self, x1, x2):\n x1 = self.up(x1)\n # input is CHW\n diffY = x2.size()[2] - x1.size()[2]\n diffX = x2.size()[3] - x1.size()[3]\n\n x1 = F.pad(x1, [diffX // 2, diffX - diffX // 2,\n diffY // 2, diffY - diffY // 2])\n # if you have padding issues, see\n # https://github.com/HaiyongJiang/U-Net-Pytorch-Unstructured-Buggy/commit/0e854509c2cea854e247a9c615f175f76fbb2e3a\n # https://github.com/xiaopeng-liao/Pytorch-UNet/commit/8ebac70e633bac59fc22bb5195e513d5832fb3bd\n x = torch.cat([x2, x1], dim=1)\n return self.conv(x)\n\n'})}),"\n",(0,i.jsx)(e.pre,{children:(0,i.jsx)(e.code,{className:"language-python",children:"class OutConv(nn.Module):\n def __init__(self, in_channels, out_channels):\n super(OutConv, self).__init__()\n self.conv = nn.Conv2d(in_channels, out_channels, kernel_size=1)\n\n def forward(self, x):\n return self.conv(x)\n"})}),"\n",(0,i.jsx)(e.h2,{id:"524-\u5229\u7528\u6a21\u578b\u5757\u7ec4\u88c5u-net",children:"5.2.4 \u5229\u7528\u6a21\u578b\u5757\u7ec4\u88c5U-Net"}),"\n",(0,i.jsx)(e.p,{children:"\u4f7f\u7528\u4e0a\u9762\u6211\u4eec\u5b9a\u4e49\u597d\u7684\u6a21\u578b\u5757\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u975e\u5e38\u65b9\u4fbf\u5730\u7ec4\u88c5U-Net\u6a21\u578b\u3002\u53ef\u4ee5\u770b\u5230\uff0c\u901a\u8fc7\u6a21\u578b\u5757\u7684\u65b9\u5f0f\u5b9e\u73b0\u4e86\u4ee3\u7801\u590d\u7528\uff0c\u6574\u4e2a\u6a21\u578b\u7ed3\u6784\u5b9a\u4e49\u6240\u9700\u7684\u4ee3\u7801\u603b\u884c\u6570\u660e\u663e\u51cf\u5c11\uff0c\u4ee3\u7801\u53ef\u8bfb\u6027\u4e5f\u5f97\u5230\u4e86\u63d0\u5347\u3002"}),"\n",(0,i.jsx)(e.pre,{children:(0,i.jsx)(e.code,{className:"language-python",children:"class UNet(nn.Module):\n def __init__(self, n_channels, n_classes, bilinear=False):\n super(UNet, self).__init__()\n self.n_channels = n_channels\n self.n_classes = n_classes\n self.bilinear = bilinear\n\n self.inc = DoubleConv(n_channels, 64)\n self.down1 = Down(64, 128)\n self.down2 = Down(128, 256)\n self.down3 = Down(256, 512)\n factor = 2 if bilinear else 1\n self.down4 = Down(512, 1024 // factor)\n self.up1 = Up(1024, 512 // factor, bilinear)\n self.up2 = Up(512, 256 // factor, bilinear)\n self.up3 = Up(256, 128 // factor, bilinear)\n self.up4 = Up(128, 64, bilinear)\n self.outc = OutConv(64, n_classes)\n\n def forward(self, x):\n x1 = self.inc(x)\n x2 = self.down1(x1)\n x3 = self.down2(x2)\n x4 = self.down3(x3)\n x5 = self.down4(x4)\n x = self.up1(x5, x4)\n x = self.up2(x, x3)\n x = self.up3(x, x2)\n x = self.up4(x, x1)\n logits = self.outc(x)\n return logits\n"})}),"\n",(0,i.jsx)(e.h2,{id:"\u53c2\u8003\u8d44\u6599",children:"\u53c2\u8003\u8d44\u6599"}),"\n",(0,i.jsxs)(e.ol,{children:["\n",(0,i.jsx)(e.li,{children:(0,i.jsx)(e.a,{href:"https://github.com/milesial/Pytorch-UNet",children:"https://github.com/milesial/Pytorch-UNet"})}),"\n"]})]})}function h(n={}){const{wrapper:e}={...(0,t.R)(),...n.components};return e?(0,i.jsx)(e,{...n,children:(0,i.jsx)(a,{...n})}):a(n)}},28453:(n,e,l)=>{l.d(e,{R:()=>c,x:()=>o});var s=l(96540);const i={},t=s.createContext(i);function c(n){const e=s.useContext(t);return s.useMemo(function(){return"function"==typeof n?n(e):{...e,...n}},[e,n])}function o(n){let e;return e=n.disableParentContext?"function"==typeof n.components?n.components(i):n.components||i:c(n.components),s.createElement(t.Provider,{value:e},n.children)}},54612:(n,e,l)=>{l.d(e,{A:()=>s});const s=l.p+"assets/images/5.2.1unet-f0e9aa890b967da85a7bd9a1fd73c55a.png"}}]); |