2020-10-19 21:48:57

This commit is contained in:
wizardforcel
2020-10-19 21:48:57 +08:00
parent 74f7d35aeb
commit 045dee5888
20 changed files with 73 additions and 73 deletions

View File

@@ -14,7 +14,7 @@
![](img/fedaa24e2fcad876c77a2038c2d8d14d.png)
```
```py
import torch
from torch.autograd import Variable
from torch import nn
@@ -60,7 +60,7 @@ plt.show()
这里就教你如何构建带有 BN 的神经网络的. BN 其实可以看做是一个 layer ( BN layer ). 我们就像平时加层一样加 BN layer  就好了. 注意, 我还对输入数据进行了一个 BN 处理, 因为如果你把输入数据看出是 从前面一层来的输出数据, 我们同样也能对她进行 BN.
```
```py
class Net(nn.Module):
def __init__(self, batch_normalization=False):
super(Net, self).__init__()
@@ -108,7 +108,7 @@ nets = [Net(batch_normalization=False), Net(batch_normalization=True)]
训练的时候, 这两个神经网络分开训练. 训练的环境都一样.
```
```py
opts = [torch.optim.Adam(net.parameters(), lr=LR) for net in nets]
loss_func = torch.nn.MSELoss()
@@ -132,7 +132,7 @@ for epoch in range(EPOCH):
![](img/cb2138c3f800c7ca4b5ae38076d09429.png)
```
```py
f, axs = plt.subplots(4, N_HIDDEN 1, figsize=(10, 5))
def plot_histogram(l_in, l_in_bn, pre_ac, pre_ac_bn):