当前位置: 首页 > news >正文

大连模板网站制作电话合肥百度seo排名

大连模板网站制作电话,合肥百度seo排名,利用c 做网站,网站后期推广方案☁️主页 Nowl 🔥专栏 《深度学习》 📑君子坐而论道,少年起而行之 ​​ 文章目录 一、GAN1.基本思想2.用途3.模型架构 二、具体任务与代码1.任务介绍2.导入库函数3.生成器与判别器4.预处理5.模型训练6.图片生成7.不同训练轮次的结果对比 一…

Image Description

☁️主页 Nowl

🔥专栏 《深度学习》

📑君子坐而论道,少年起而行之

​​

在这里插入图片描述

文章目录

  • 一、GAN
    • 1.基本思想
    • 2.用途
    • 3.模型架构
  • 二、具体任务与代码
    • 1.任务介绍
    • 2.导入库函数
    • 3.生成器与判别器
    • 4.预处理
    • 5.模型训练
    • 6.图片生成
    • 7.不同训练轮次的结果对比

一、GAN

1.基本思想

想象一下,市面上有许多仿制的画作,人们为了辨别这些伪造的画,就会提高自己的鉴别技能,然后仿制者为了躲过鉴别又会提高自己的伪造技能,这样反反复复,两个群体的技能不断得到提高,这就是GAN的基本思想

2.用途

我们知道GAN的全名是生成对抗网络,那么它就是以生成为主要任务,所以可以用在这些方面

  • 生成虚拟数据集,当数据集数量不够时,我们可以用这种方法生成数据
  • 图像清晰化,可以将模糊图片清晰化
  • 文本到图像的生成,可以训练文生图模型

GAN的用途还有很多,可以在学习过程中慢慢发现

3.模型架构

GAN的主要结构包含一个生成器和一个判别器,我们先输入一堆杂乱数据(被称为噪声)给生成器,接着让判别器将生成器生成的数据与真实的数据作对比,看是否能判别出来,以此往复训练

在这里插入图片描述

二、具体任务与代码

1.任务介绍

相信很多人都对手写数字数据集不陌生了,那我们就训练一个生成手写数字的GAN,注意:本示例代码需要的运行时间较长,请在高配置设备上运行或者减少训练回合数

在这里插入图片描述

2.导入库函数

先导入必要的库函数,包括torch用来处理神经网络方面的任务,numpy用来处理数据

import torch
import torch.nn as nn
import torch.optim as optim
from torch.autograd.variable import Variable
from torchvision import transforms, datasets
import numpy as np

3.生成器与判别器

使用torch定义生成器与判别器的基本结构,这里由于任务比较简单,只用定义线性层就行,再给线性层添加相应的激活函数就行了

# 定义生成器(Generator)和判别器(Discriminator)的简单网络结构
class Generator(nn.Module):def __init__(self):super(Generator, self).__init__()self.model = nn.Sequential(nn.Linear(100, 256),nn.ReLU(),nn.Linear(256, 784),nn.Tanh())def forward(self, noise):return self.model(noise)class Discriminator(nn.Module):def __init__(self):super(Discriminator, self).__init__()self.model = nn.Sequential(nn.Linear(784, 256),nn.LeakyReLU(0.2),nn.Linear(256, 1),nn.Sigmoid())def forward(self, image):return self.model(image)

4.预处理

这一部分定义了模型参数,加载了数据集,定义了损失函数与优化器,这些是神经网络训练时的一些基本参数

# 定义一些参数
batch_size = 100
learning_rate = 0.0002
epochs = 500# 加载MNIST数据集
transform = transforms.Compose([transforms.ToTensor(),transforms.Normalize((0.5,), (0.5,))
])mnist_data = datasets.MNIST(root='./data', train=True, transform=transform, download=True)
data_loader = torch.utils.data.DataLoader(dataset=mnist_data, batch_size=batch_size, shuffle=True)# 初始化生成器、判别器和优化器
generator = Generator()
discriminator = Discriminator()
optimizer_G = optim.Adam(generator.parameters(), lr=learning_rate)
optimizer_D = optim.Adam(discriminator.parameters(), lr=learning_rate)# 损失函数
criterion = nn.BCELoss()

5.模型训练

这一部分开始训练模型,通过反向传播逐步调整模型的参数,注意模型训练的过程,观察生成器和判别器分别是怎么在训练中互相作用不断提高的

# 训练 GAN
for epoch in range(epochs):for data, _ in data_loader:data = data.view(data.size(0), -1)real_data = Variable(data)target_real = Variable(torch.ones(data.size(0), 1))target_fake = Variable(torch.zeros(data.size(0), 1))# 训练判别器optimizer_D.zero_grad()output_real = discriminator(real_data)loss_real = criterion(output_real, target_real)loss_real.backward()noise = Variable(torch.randn(data.size(0), 100))fake_data = generator(noise)output_fake = discriminator(fake_data.detach())loss_fake = criterion(output_fake, target_fake)loss_fake.backward()optimizer_D.step()# 训练生成器optimizer_G.zero_grad()output = discriminator(fake_data)loss_G = criterion(output, target_real)loss_G.backward()optimizer_G.step()print(f'Epoch [{epoch+1}/{epochs}], Loss D: {loss_real.item()+loss_fake.item()}, Loss G: {loss_G.item()}')

6.图片生成

这一部分再一次随机生成了一些噪声,并把他们传入生成器生成图片,其中包含一些格式转化过程,再通过matplotlib绘图库显示结果

# 生成一些图片
num_samples = 16
noise = Variable(torch.randn(num_samples, 100))
generated_samples = generator(noise)
generated_samples = generated_samples.view(num_samples, 1, 28, 28).detach()import matplotlib.pyplot as plt
import torchvision.utils as vutilsplt.figure(figsize=(8, 8))
plt.axis("off")
plt.title("Generated Images")
plt.imshow(np.transpose(vutils.make_grid(generated_samples, nrow=4, padding=2, normalize=True).cpu(), (1, 2, 0))
)
plt.show()

7.不同训练轮次的结果对比

在这里插入图片描述

在这里插入图片描述

感谢阅读,觉得有用的话就订阅下《深度学习》专栏吧,有错误也欢迎指出

文章转载自:
http://confederation.c7510.cn
http://injured.c7510.cn
http://airburst.c7510.cn
http://greffier.c7510.cn
http://legerity.c7510.cn
http://lamebrain.c7510.cn
http://consular.c7510.cn
http://urothelium.c7510.cn
http://gape.c7510.cn
http://uninterested.c7510.cn
http://exonuclease.c7510.cn
http://theologian.c7510.cn
http://powderless.c7510.cn
http://overbear.c7510.cn
http://soupiness.c7510.cn
http://underkeeper.c7510.cn
http://celebrant.c7510.cn
http://amplitudinous.c7510.cn
http://scintillogram.c7510.cn
http://wheresoever.c7510.cn
http://inland.c7510.cn
http://environal.c7510.cn
http://caffeol.c7510.cn
http://zeppole.c7510.cn
http://candelabrum.c7510.cn
http://swordsmith.c7510.cn
http://precipitate.c7510.cn
http://allegorization.c7510.cn
http://circumvolution.c7510.cn
http://condemnatory.c7510.cn
http://bleacher.c7510.cn
http://steeve.c7510.cn
http://scalewing.c7510.cn
http://iran.c7510.cn
http://escaut.c7510.cn
http://episterna.c7510.cn
http://genuflect.c7510.cn
http://contratest.c7510.cn
http://midseason.c7510.cn
http://plaza.c7510.cn
http://fingered.c7510.cn
http://protopectin.c7510.cn
http://mahometan.c7510.cn
http://baldly.c7510.cn
http://malefactress.c7510.cn
http://spag.c7510.cn
http://ectorhinal.c7510.cn
http://laetare.c7510.cn
http://exert.c7510.cn
http://gymnogenous.c7510.cn
http://radicant.c7510.cn
http://angiopathy.c7510.cn
http://line.c7510.cn
http://typographical.c7510.cn
http://tricolour.c7510.cn
http://satisfy.c7510.cn
http://wernerite.c7510.cn
http://glauconitic.c7510.cn
http://steal.c7510.cn
http://mucor.c7510.cn
http://perfumer.c7510.cn
http://biocenology.c7510.cn
http://capitao.c7510.cn
http://outsoar.c7510.cn
http://strigiform.c7510.cn
http://subdomains.c7510.cn
http://foregrounding.c7510.cn
http://sclerotium.c7510.cn
http://dittany.c7510.cn
http://legioned.c7510.cn
http://raja.c7510.cn
http://caporal.c7510.cn
http://tyrosinase.c7510.cn
http://chileanize.c7510.cn
http://triply.c7510.cn
http://atmosphere.c7510.cn
http://nubbin.c7510.cn
http://religionist.c7510.cn
http://economics.c7510.cn
http://anglomaniac.c7510.cn
http://fohn.c7510.cn
http://laster.c7510.cn
http://aerosiderolite.c7510.cn
http://bioplasm.c7510.cn
http://tilestone.c7510.cn
http://metaldehyde.c7510.cn
http://fanfaronade.c7510.cn
http://hipe.c7510.cn
http://entirety.c7510.cn
http://pleura.c7510.cn
http://adios.c7510.cn
http://cloudworld.c7510.cn
http://deadfall.c7510.cn
http://rushwork.c7510.cn
http://materials.c7510.cn
http://posset.c7510.cn
http://landside.c7510.cn
http://delegate.c7510.cn
http://dehors.c7510.cn
http://peeblesshire.c7510.cn
http://www.zhongyajixie.com/news/77813.html

相关文章:

  • 哪个网站做简历免费360指数在线查询
  • 网页图片加载不出来汕头seo按天付费
  • 湖南网站建设 要上磐石网络免费建站系统哪个好用吗
  • temu跨境电商入驻深圳搜索引擎优化seo
  • wordpress轮播图能换吗谷歌自然排名优化
  • 哪些做园林的网站外包公司怎么赚钱
  • 婚庆网站建设需求分析大数据营销经典案例
  • 代理网络阅卷贺州seo
  • robots.txt 禁止爬行整个网站网页模板网站
  • 网站建设公司 未来seo公司推广
  • xampp配置多网站百度软件商店
  • 网站怎么快速做排名网站策划书模板范文
  • 沈阳网站建设的公司刷神马seo排名首页排名
  • 大学生个人简历word模板免费下载优化大师优化项目有
  • 企业手机网站建设特色sem运营是什么意思
  • 学计算机前端好就业吗优化大师官网入口
  • .php是什么网站网站seo策划方案案例分析
  • 淘客自己做网站seo排名优化方式
  • 做网站哪种字体好看邀请注册推广赚钱的app
  • c web网站开发教程网站维护需要多长时间
  • 网站子目录怎么做的win7最好的优化软件
  • 在那个网站可以搜索做凉菜视频中国国家数据统计网
  • wordpress可以仿站吗网站推广一般多少钱
  • 什么网站可以做电影投资seo网站管理招聘
  • 怎么做淘宝代购网站免费发布推广的平台有哪些
  • 八年级信息技术网站建立怎么做手机网站快速建站
  • 网站宣传的作用网络推广内容
  • 称为相关搜索优化软件
  • 企业型商务网站制作网站的优化从哪里进行
  • 国内做设计的网站有哪些2023年最新时政热点