如何免费在兰州百姓网发布信息并吸引肥西建设局网站的注意?

摘要:兰州百姓网免费发布信息网站,肥西建设局网站,哪个网站可以做危险化学品供求,免费设计图网站前言: 结合手写数字识别的例子,实现以下AutoEncoder ae.py:实现auto
兰州百姓网免费发布信息网站,肥西建设局网站,哪个网站可以做危险化学品供求,免费设计图网站前言#xff1a; 结合手写数字识别的例子#xff0c;实现以下AutoEncoder ae.py: 实现autoEncoder 网络 main.py: 加载手写数字数据集#xff0c;以及训练#xff0c;验证#xff0c;测试网络。 左图#xff1a;原图像 右图#xff1a;重构图像 ----main----- 每轮训…前言 结合手写数字识别的例子实现以下AutoEncoder ae.py:  实现autoEncoder 网络 main.py: 加载手写数字数据集以及训练验证测试网络。 左图原图像 右图重构图像 ----main-----  每轮训练时间 : 91 0 loss: 0.02758789248764515  每轮训练时间 : 95 1 loss: 0.024654878303408623  每轮训练时间 : 149 2 loss: 0.018874473869800568 目录 1 AE 实现 2 main 实现 一  ae(AutoEncoder) 实现 文件名: ae.py 模型的搭建 注意点 手写数字数据集 提供了 标签y但是AutoEncoder 网络不需要 它的标签就是输入的x, 需要重构本身 自编码器autoencoder, AE是一类在半监督学习和非监督学习中使用的人工神经网络Artificial Neural Networks, ANNs其功能是通过将输入信息作为学习目标对输入信息进行表征学习representation learning [1-2]  。 自编码器包含编码器encoder和解码器decoder两部分 [2]  。按学习范式自编码器可以被分为收缩自编码器contractive autoencoder、正则自编码器regularized autoencoder和变分自编码器Variational AutoEncoder, VAE其中前两者是判别模型、后者是生成模型 [2]  。按构筑类型自编码器可以是前馈结构或递归结构的神经网络。 自编码器具有一般意义上表征学习算法的功能被应用于降维dimensionality reduction和异常值检测anomaly detection [2]  。包含卷积层构筑的自编码器可被应用于计算机视觉问题包括图像降噪image denoising [3]  、神经风格迁移neural style transfer等 [4]  。 # -*- coding: utf-8 -*-Created on Wed Aug 30 14:19:19 2023author: chengxf2 import torch from torch import nn#ae: AutoEncoderclass AE(nn.Module):def __init__(self,hidden_size10):super(AE, self).__init__()self.encoder nn.Sequential(nn.Linear(in_features784, out_features256),nn.ReLU(),nn.Linear(in_features256, out_features128),nn.ReLU(),nn.Linear(in_features128, out_features64),nn.ReLU(),nn.Linear(in_features64, out_featureshidden_size),nn.ReLU())# hidden [batch_size, 10]self.decoder nn.Sequential(nn.Linear(in_featureshidden_size, out_features64),nn.ReLU(),nn.Linear(in_features64, out_features128),nn.ReLU(),nn.Linear(in_features128, out_features256),nn.ReLU(),nn.Linear(in_features256, out_features784),nn.Sigmoid())def forward(self, x):param x:[batch, 1,28,28]return m x.size(0)x x.view(m, 784)hidden self.encoder(x)x self.decoder(hidden)#reshapex x.view(m,1,28,28)return x 二 main 实现 文件名 main.py 作用 加载数据集 训练模型 测试模型泛化能力 # -*- coding: utf-8 -*-Created on Wed Aug 30 14:24:10 2023author: chengxf2 import torch from torch.utils.data import DataLoader from torchvision import transforms, datasets import time from torch import optim,nn from ae import AE import visdomdef main():batchNum 32lr 1e-3epochs 20device torch.device(cuda:0 if torch.cuda.is_available() else cpu)torch.manual_seed(1234)viz visdom.Visdom()viz.line([0],[-1],wintrain_loss,opts dict(titletrain acc))tf transforms.Compose([ transforms.ToTensor()])mnist_train datasets.MNIST(mnist,True,transform tf,downloadTrue)train_data DataLoader(mnist_train, batch_sizebatchNum, shuffleTrue)mnist_test datasets.MNIST(mnist,False,transform tf,downloadTrue)test_data DataLoader(mnist_test, batch_sizebatchNum, shuffleTrue)global_step 0model AE().to(device)criteon nn.MSELoss().to(device) #损失函数optimizer optim.Adam(model.parameters(),lrlr) #梯度更新规则print(\n ----main-----)for epoch in range(epochs):start time.perf_counter()for step ,(x,y) in enumerate(train_data):#[b,1,28,28]x x.to(device)x_hat model(x)loss criteon(x_hat, x)#backpropoptimizer.zero_grad()loss.backward()optimizer.step()viz.line(Y[loss.item()],X[global_step],wintrain_loss,updateappend)global_step 1end time.perf_counter() interval end - startprint(\n 每轮训练时间 :,int(interval))print(epoch, loss:,loss.item())x,target iter(test_data).next()x x.to(device)with torch.no_grad():x_hat model(x)tip hatstr(epoch)viz.images(x,nrow8, winx,optsdict(titlex))viz.images(x_hat,nrow8, winx_hat,optsdict(titletip))if __name__ __main__:main()