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 @@
自编码只用训练集就好了, 而且只需要训练 training data 的 image, 不用训练 labels.
```
```py
import torch
import torch.nn as nn
from torch.autograd import Variable
@@ -46,7 +46,7 @@ train_data = torchvision.datasets.MNIST(
AutoEncoder 形式很简单, 分别是 encoder  和 decoder , 压缩和解压, 压缩后得到压缩的特征值, 再从压缩的特征值解压成原图片.
```
```py
class AutoEncoder(nn.Module):
def __init__(self):
super(AutoEncoder, self).__init__()
@@ -87,7 +87,7 @@ autoencoder = AutoEncoder()
![](img/c429fb827df769a542339e200e2ea20c.png)
```
```py
optimizer = torch.optim.Adam(autoencoder.parameters(), lr=LR)
loss_func = nn.MSELoss()
@@ -113,7 +113,7 @@ for epoch in range(EPOCH):
3D 的可视化图挺有趣的, 还能挪动观看, 更加直观, 好理解.
```
```py
# 要观看的数据
view_data = Variable(train_data.train_data[:200].view(-1, 28*28).type(torch.FloatTensor)/255.)
encoded_data, _ = autoencoder(view_data) # 提取压缩的特征值