diff --git a/totrans/gen-dl_11.yaml b/totrans/gen-dl_11.yaml index fd0b17a..19394b4 100644 --- a/totrans/gen-dl_11.yaml +++ b/totrans/gen-dl_11.yaml @@ -1391,6 +1391,7 @@ id: totrans-163 prefs: [] type: TYPE_NORMAL + zh: 这个解决方案最初在2015年He等人的ResNet论文中首次提出。通过在主要加权层周围包含一个跳跃连接*高速公路*,块可以选择绕过复杂的权重更新,简单地通过恒等映射传递。这使得网络可以在不牺牲梯度大小或网络准确性的情况下进行深度训练。 - en: A diagram of a `ResidualBlock` is shown in [Figure 8-10](#diffusion_residual). Note that in some residual blocks, we also include an extra `Conv2D` layer with kernel size 1 on the skip connection, to bring the number of channels in line @@ -1398,24 +1399,29 @@ id: totrans-164 prefs: [] type: TYPE_NORMAL + zh: '`ResidualBlock`的图示如[图8-10](#diffusion_residual)所示。请注意,在一些残差块中,我们还在跳跃连接上包含一个额外的具有核大小1的`Conv2D`层,以使通道数与块的其余部分保持一致。' - en: '![](Images/gdl2_0810.png)' id: totrans-165 prefs: [] type: TYPE_IMG + zh: '![](Images/gdl2_0810.png)' - en: Figure 8-10\. The `ResidualBlock` in the U-Net id: totrans-166 prefs: - PREF_H6 type: TYPE_NORMAL + zh: 图8-10。U-Net中的`ResidualBlock` - en: We can code a `ResidualBlock` in Keras as shown in [Example 8-8](#diffusion_residual_code). id: totrans-167 prefs: [] type: TYPE_NORMAL + zh: 我们可以像[示例8-8](#diffusion_residual_code)中所示的那样在Keras中编写`ResidualBlock`。 - en: Example 8-8\. Code for the `ResidualBlock` in the U-Net id: totrans-168 prefs: - PREF_H5 type: TYPE_NORMAL + zh: 示例8-8。U-Net中的`ResidualBlock`代码 - en: '[PRE7]' id: totrans-169 prefs: [] @@ -1425,6 +1431,7 @@ id: totrans-170 prefs: [] type: TYPE_NORMAL + zh: '[![1](Images/1.png)](#co_diffusion_models_CO6-1)' - en: Check if the number of channels in the input matches the number of channels that we would like the block to output. If not, include an extra `Conv2D` layer on the skip connection to bring the number of channels in line with the rest of @@ -1432,36 +1439,44 @@ id: totrans-171 prefs: [] type: TYPE_NORMAL + zh: 检查输入中的通道数是否与我们希望该块输出的通道数匹配。如果不匹配,可以在跳跃连接上包含额外的`Conv2D`层,以使通道数与块的其余部分保持一致。 - en: '[![2](Images/2.png)](#co_diffusion_models_CO6-2)' id: totrans-172 prefs: [] type: TYPE_NORMAL + zh: '[![2](Images/2.png)](#co_diffusion_models_CO6-2)' - en: Apply a `BatchNormalization` layer. id: totrans-173 prefs: [] type: TYPE_NORMAL + zh: 应用`BatchNormalization`层。 - en: '[![3](Images/3.png)](#co_diffusion_models_CO6-3)' id: totrans-174 prefs: [] type: TYPE_NORMAL + zh: '[![3](Images/3.png)](#co_diffusion_models_CO6-3)' - en: Apply two `Conv2D` layers. id: totrans-175 prefs: [] type: TYPE_NORMAL + zh: 应用两个`Conv2D`层。 - en: '[![4](Images/4.png)](#co_diffusion_models_CO6-4)' id: totrans-176 prefs: [] type: TYPE_NORMAL + zh: '[![4](Images/4.png)](#co_diffusion_models_CO6-4)' - en: Add the original block input to the output to provide the final output from the block. id: totrans-177 prefs: [] type: TYPE_NORMAL + zh: 将原始块输入添加到输出中,以提供块的最终输出。 - en: DownBlocks and UpBlocks id: totrans-178 prefs: - PREF_H3 type: TYPE_NORMAL + zh: DownBlocks和UpBlocks - en: Each successive `DownBlock` increases the number of channels via `block_depth` (=2 in our example) `ResidualBlock`s, while also applying a final `AveragePooling2D` layer in order to halve the size of the image. Each `ResidualBlock` is added to @@ -1469,6 +1484,7 @@ id: totrans-179 prefs: [] type: TYPE_NORMAL + zh: 每个连续的`DownBlock`通过`block_depth`(在我们的示例中为2)`ResidualBlock`增加通道数,同时还应用最终的`AveragePooling2D`层以将图像尺寸减半。每个`ResidualBlock`都添加到一个列表中,以便稍后由`UpBlock`层作为U-Net中的跳跃连接使用。 - en: An `UpBlock` first applies an `UpSampling2D` layer that doubles the size of the image, through bilinear interpolation. Each successive `UpBlock` decreases the number of channels via `block_depth` (=2) `ResidualBlock`s, while also concatenating @@ -1477,24 +1493,29 @@ id: totrans-180 prefs: [] type: TYPE_NORMAL + zh: '`UpBlock`首先应用一个`UpSampling2D`层,通过双线性插值将图像大小加倍。每个连续的`UpBlock`通过`block_depth`(=2)`ResidualBlock`减少通道数,同时还通过U-Net中的跳跃连接将`DownBlock`的输出连接起来。这个过程的图示如[图8-11](#diffusion_down_up_block)所示。' - en: '![](Images/gdl2_0811.png)' id: totrans-181 prefs: [] type: TYPE_IMG + zh: '![](Images/gdl2_0811.png)' - en: Figure 8-11\. The `DownBlock` and corresponding `UpBlock` in the U-Net id: totrans-182 prefs: - PREF_H6 type: TYPE_NORMAL + zh: 图8-11。U-Net中的`DownBlock`和相应的`UpBlock` - en: We can code the `DownBlock` and `UpBlock` using Keras as illustrated in [Example 8-9](#diffusion_down_up_code). id: totrans-183 prefs: [] type: TYPE_NORMAL + zh: 我们可以使用Keras编写`DownBlock`和`UpBlock`,如[示例8-9](#diffusion_down_up_code)所示。 - en: Example 8-9\. Code for the `DownBlock` and `UpBlock` in the U-Net model id: totrans-184 prefs: - PREF_H5 type: TYPE_NORMAL + zh: 示例8-9。U-Net模型中的`DownBlock`和`UpBlock`代码 - en: '[PRE8]' id: totrans-185 prefs: [] @@ -1504,71 +1525,86 @@ id: totrans-186 prefs: [] type: TYPE_NORMAL + zh: '[![1](Images/1.png)](#co_diffusion_models_CO7-1)' - en: The `DownBlock` increases the number of channels in the image using a `ResidualBlock` of a given `width`…​ id: totrans-187 prefs: [] type: TYPE_NORMAL + zh: '`DownBlock`通过给定`width`的`ResidualBlock`增加图像中的通道数…​' - en: '[![2](Images/2.png)](#co_diffusion_models_CO7-2)' id: totrans-188 prefs: [] type: TYPE_NORMAL + zh: '[![2](Images/2.png)](#co_diffusion_models_CO7-2)' - en: …​each of which are saved to a list (`skips`) for use later by the `UpBlock`s. id: totrans-189 prefs: [] type: TYPE_NORMAL + zh: …每个都保存在一个列表(`skips`)中,以便稍后由`UpBlock`使用。 - en: '[![3](Images/3.png)](#co_diffusion_models_CO7-3)' id: totrans-190 prefs: [] type: TYPE_NORMAL + zh: '[![3](Images/3.png)](#co_diffusion_models_CO7-3)' - en: A final `AveragePooling2D` layer reduces the dimensionality of the image by half. id: totrans-191 prefs: [] type: TYPE_NORMAL + zh: 最终的`AveragePooling2D`层将图像的维度减半。 - en: '[![4](Images/4.png)](#co_diffusion_models_CO7-4)' id: totrans-192 prefs: [] type: TYPE_NORMAL + zh: '[![4](Images/4.png)](#co_diffusion_models_CO7-4)' - en: The `UpBlock` begins with an `UpSampling2D` layer that doubles the size of the image. id: totrans-193 prefs: [] type: TYPE_NORMAL + zh: '`UpBlock`从一个`UpSampling2D`层开始,将图像大小加倍。' - en: '[![5](Images/5.png)](#co_diffusion_models_CO7-5)' id: totrans-194 prefs: [] type: TYPE_NORMAL + zh: '[![5](Images/5.png)](#co_diffusion_models_CO7-5)' - en: The output from a `DownBlock` layer is glued to the current output using a `Concatenate` layer. id: totrans-195 prefs: [] type: TYPE_NORMAL + zh: '`DownBlock`层的输出通过`Concatenate`层连接到当前输出。' - en: '[![6](Images/6.png)](#co_diffusion_models_CO7-6)' id: totrans-196 prefs: [] type: TYPE_NORMAL + zh: '[![6](Images/6.png)](#co_diffusion_models_CO7-6)' - en: A `ResidualBlock` is used to reduce the number of channels in the image as it passes through the `UpBlock`. id: totrans-197 prefs: [] type: TYPE_NORMAL + zh: '`ResidualBlock`用于在图像通过`UpBlock`时减少通道数。' - en: Training the Diffusion Model id: totrans-198 prefs: - PREF_H2 type: TYPE_NORMAL + zh: 训练扩散模型 - en: We now have all the components in place to train our denoising diffusion model! [Example 8-10](#diffusion_train_code) creates, compiles, and fits the diffusion model. id: totrans-199 prefs: [] type: TYPE_NORMAL + zh: 现在我们已经准备好训练我们的去噪扩散模型了![示例8-10](#diffusion_train_code)创建、编译和拟合扩散模型。 - en: Example 8-10\. Code for training the `DiffusionModel` id: totrans-200 prefs: - PREF_H5 type: TYPE_NORMAL + zh: 示例8-10。训练`DiffusionModel`的代码 - en: '[PRE9]' id: totrans-201 prefs: [] @@ -1578,24 +1614,29 @@ id: totrans-202 prefs: [] type: TYPE_NORMAL + zh: '[![1](Images/1.png)](#co_diffusion_models_CO8-1)' - en: Instantiate the model. id: totrans-203 prefs: [] type: TYPE_NORMAL + zh: 实例化模型。 - en: '[![2](Images/2.png)](#co_diffusion_models_CO8-2)' id: totrans-204 prefs: [] type: TYPE_NORMAL + zh: '[![2](Images/2.png)](#co_diffusion_models_CO8-2)' - en: Compile the model, using the AdamW optimizer (similar to Adam but with weight decay, which helps stabilize the training process) and mean absolute error loss function. id: totrans-205 prefs: [] type: TYPE_NORMAL + zh: 编译模型,使用AdamW优化器(类似于Adam,但带有权重衰减,有助于稳定训练过程)和平均绝对误差损失函数。 - en: '[![3](Images/3.png)](#co_diffusion_models_CO8-3)' id: totrans-206 prefs: [] type: TYPE_NORMAL + zh: '[![3](Images/3.png)](#co_diffusion_models_CO8-3)' - en: Calculate the normalization statistics using the training set. id: totrans-207 prefs: []