|
22 | 22 | __all__ = ["AttentionUnet"] |
23 | 23 |
|
24 | 24 |
|
| 25 | +# `ConvBlock` 是一個兩層卷積的基本模組,每一層都有激活函數 (ReLU)、標準化層 (BatchNorm)、Dropout 等組成。 |
25 | 26 | class ConvBlock(nn.Module): |
26 | | - |
27 | 27 | def __init__( |
28 | 28 | self, |
29 | | - spatial_dims: int, |
30 | | - in_channels: int, |
31 | | - out_channels: int, |
32 | | - kernel_size: Sequence[int] | int = 3, |
33 | | - strides: int = 1, |
34 | | - dropout=0.0, |
| 29 | + spatial_dims: int, # 定義輸入影像的空間維度 (2D 或 3D) |
| 30 | + in_channels: int, # 定義輸入通道數 |
| 31 | + out_channels: int, # 定義輸出通道數 (即特徵圖數) |
| 32 | + kernel_size: Sequence[int] | int = 3, # 卷積核大小,通常設定為 3 |
| 33 | + strides: int = 1, # 步幅,決定輸出特徵圖的縮放 |
| 34 | + dropout=0.0, # Dropout 機率,默認為 0,意味著不進行隨機失活 |
35 | 35 | ): |
36 | 36 | super().__init__() |
| 37 | + # 構建兩層卷積層,每層有激活函數、標準化和可選的 Dropout |
37 | 38 | layers = [ |
38 | 39 | Convolution( |
39 | 40 | spatial_dims=spatial_dims, |
40 | 41 | in_channels=in_channels, |
41 | 42 | out_channels=out_channels, |
42 | 43 | kernel_size=kernel_size, |
43 | 44 | strides=strides, |
44 | | - padding=None, |
45 | | - adn_ordering="NDA", |
46 | | - act="relu", |
47 | | - norm=Norm.BATCH, |
48 | | - dropout=dropout, |
| 45 | + adn_ordering="NDA", # Ordering: Norm -> Dropout -> Activation |
| 46 | + act="relu", # 激活函數為 ReLU |
| 47 | + norm=Norm.BATCH, # 使用 Batch Normalization |
| 48 | + dropout=dropout, # Dropout 機率 |
49 | 49 | ), |
50 | 50 | Convolution( |
51 | 51 | spatial_dims=spatial_dims, |
52 | 52 | in_channels=out_channels, |
53 | 53 | out_channels=out_channels, |
54 | 54 | kernel_size=kernel_size, |
55 | 55 | strides=1, |
56 | | - padding=None, |
57 | 56 | adn_ordering="NDA", |
58 | 57 | act="relu", |
59 | 58 | norm=Norm.BATCH, |
|
0 commit comments