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

个人网站这么做百度关键词优化推广

个人网站这么做,百度关键词优化推广,举报网站建设情况,建个大型网站要多少钱🍨 本文为🔗365天深度学习训练营 中的学习记录博客🍖 原作者:K同学啊 | 接辅导、项目定制🚀 文章来源:K同学的学习圈子 上一周已经给出代码,需要可以跳转上一周的任务 第G8周:ACGAN任…
  • 🍨 本文为🔗365天深度学习训练营 中的学习记录博客
  • 🍖 原作者:K同学啊 | 接辅导、项目定制
  • 🚀 文章来源:K同学的学习圈子

上一周已经给出代码,需要可以跳转上一周的任务
第G8周:ACGAN任务

import argparse
import os
import numpy as npimport torchvision.transforms as transforms
from torchvision.utils import save_imagefrom torch.utils.data import DataLoader
from torchvision import datasets
from torch.autograd import Variableimport torch.nn as nn
import torch# 创建用于存储生成图像的目录
os.makedirs("images", exist_ok=True)# 解析命令行参数
parser = argparse.ArgumentParser()
parser.add_argument("--n_epochs", type=int, default=50, help="训练的总轮数")
parser.add_argument("--batch_size", type=int, default=64, help="每个批次的大小")
parser.add_argument("--lr", type=float, default=0.0002, help="Adam优化器的学习率")
parser.add_argument("--b1", type=float, default=0.5, help="Adam优化器的一阶动量衰减")
parser.add_argument("--b2", type=float, default=0.999, help="Adam优化器的二阶动量衰减")
parser.add_argument("--n_cpu", type=int, default=4, help="用于批次生成的CPU线程数")
parser.add_argument("--latent_dim", type=int, default=100, help="潜在空间的维度")
parser.add_argument("--n_classes", type=int, default=10, help="数据集的类别数")
parser.add_argument("--img_size", type=int, default=32, help="每个图像的尺寸")
parser.add_argument("--channels", type=int, default=1, help="图像通道数")
parser.add_argument("--sample_interval", type=int, default=400, help="图像采样间隔")
opt = parser.parse_args()
print(opt)# 检查是否支持GPU加速
cuda = True if torch.cuda.is_available() else False# 初始化神经网络权重的函数
def weights_init_normal(m):classname = m.__class__.__name__if classname.find("Conv") != -1:torch.nn.init.normal_(m.weight.data, 0.0, 0.02)elif classname.find("BatchNorm2d") != -1:torch.nn.init.normal_(m.weight.data, 1.0, 0.02)torch.nn.init.constant_(m.bias.data, 0.0)# 生成器网络类
class Generator(nn.Module):def __init__(self):super(Generator, self).__init__()# 为类别标签创建嵌入层self.label_emb = nn.Embedding(opt.n_classes, opt.latent_dim)# 计算上采样前的初始大小self.init_size = opt.img_size // 4  # Initial size before upsampling# 第一层线性层self.l1 = nn.Sequential(nn.Linear(opt.latent_dim, 128 * self.init_size ** 2))# 卷积层块self.conv_blocks = nn.Sequential(nn.BatchNorm2d(128),nn.Upsample(scale_factor=2),nn.Conv2d(128, 128, 3, stride=1, padding=1),nn.BatchNorm2d(128, 0.8),nn.LeakyReLU(0.2, inplace=True),nn.Upsample(scale_factor=2),nn.Conv2d(128, 64, 3, stride=1, padding=1),nn.BatchNorm2d(64, 0.8),nn.LeakyReLU(0.2, inplace=True),nn.Conv2d(64, opt.channels, 3, stride=1, padding=1),nn.Tanh(),)def forward(self, noise, labels):# 将标签嵌入到噪声中gen_input = torch.mul(self.label_emb(labels), noise)# 通过第一层线性层out = self.l1(gen_input)# 重新整形为合适的形状out = out.view(out.shape[0], 128, self.init_size, self.init_size)# 通过卷积层块生成图像img = self.conv_blocks(out)return img# 判别器网络类
class Discriminator(nn.Module):def __init__(self):super(Discriminator, self).__init__()# 定义判别器块的函数def discriminator_block(in_filters, out_filters, bn=True):"""返回每个判别器块的层"""block = [nn.Conv2d(in_filters, out_filters, 3, 2, 1), nn.LeakyReLU(0.2, inplace=True), nn.Dropout2d(0.25)]if bn:block.append(nn.BatchNorm2d(out_filters, 0.8))return block# 判别器的卷积层块self.conv_blocks = nn.Sequential(*discriminator_block(opt.channels, 16, bn=False),*discriminator_block(16, 32),*discriminator_block(32, 64),*discriminator_block(64, 128),)# 下采样后图像的高度和宽度ds_size = opt.img_size // 2 ** 4# 输出层self.adv_layer = nn.Sequential(nn.Linear(128 * ds_size ** 2, 1), nn.Sigmoid())self.aux_layer = nn.Sequential(nn.Linear(128 * ds_size ** 2, opt.n_classes), nn.Softmax())def forward(self, img):out = self.conv_blocks(img)out = out.view(out.shape[0], -1)validity = self.adv_layer(out)label = self.aux_layer(out)return validity, label# 损失函数
adversarial_loss = torch.nn.BCELoss()
auxiliary_loss = torch.nn.CrossEntropyLoss()# 初始化生成器和判别器
generator = Generator()
discriminator = Discriminator()if cuda:generator.cuda()discriminator.cuda()adversarial_loss.cuda()auxiliary_loss.cuda()# 初始化权重
generator.apply(weights_init_normal)
discriminator.apply(weights_init_normal)# 配置数据加载器
os.makedirs("../../data/mnist", exist_ok=True)
dataloader = torch.utils.data.DataLoader(datasets.MNIST("../../data/mnist",train=True,download=True,transform=transforms.Compose([transforms.Resize(opt.img_size), transforms.ToTensor(), transforms.Normalize([0.5], [0.5])]),),batch_size=opt.batch_size,shuffle=True,
)# 优化器
optimizer_G = torch.optim.Adam(generator.parameters(), lr=opt.lr, betas=(opt.b1, opt.b2))
optimizer_D = torch.optim.Adam(discriminator.parameters(), lr=opt.lr, betas=(opt.b1, opt.b2))FloatTensor = torch.cuda.FloatTensor if cuda else torch.FloatTensor
LongTensor = torch.cuda.LongTensor if cuda else torch.LongTensor# 保存生成图像的函数
def sample_image(n_row, batches_done):"""保存从0到n_classes的生成数字的图像网格"""# 采样噪声z = Variable(FloatTensor(np.random.normal(0, 1, (n_row ** 2, opt.latent_dim))))# 为n行生成标签从0到n_classeslabels = np.array([num for _ in range(n_row) for num in range(n_row)])labels = Variable(LongTensor(labels))gen_imgs = generator(z, labels)save_image(gen_imgs.data, "images/%d.png" % batches_done, nrow=n_row, normalize=True)# ----------
# 训练
# ----------for epoch in range(opt.n_epochs):for i, (imgs, labels) in enumerate(dataloader):batch_size = imgs.shape[0]# 真实数据的标签valid = Variable(FloatTensor(batch_size, 1).fill_(1.0), requires_grad=False)# 生成数据的标签fake = Variable(FloatTensor(batch_size, 1).fill_(0.0), requires_grad=False)# 配置输入real_imgs = Variable(imgs.type(FloatTensor))labels = Variable(labels.type(LongTensor))# -----------------# 训练生成器# -----------------optimizer_G.zero_grad()# 采样噪声和标签作为生成器的输入z = Variable(FloatTensor(np.random.normal(0, 1, (batch_size, opt.latent_dim))))gen_labels = Variable(LongTensor(np.random.randint(0, opt.n_classes, batch_size)))# 生成一批图像gen_imgs = generator(z, gen_labels)# 损失度量生成器的欺骗判别器的能力validity, pred_label = discriminator(gen_imgs)g_loss = 0.5 * (adversarial_loss(validity, valid) + auxiliary_loss(pred_label, gen_labels))g_loss.backward()optimizer_G.step()# ---------------------# 训练判别器# ---------------------optimizer_D.zero_grad()# 真实图像的损失real_pred, real_aux = discriminator(real_imgs)d_real_loss = (adversarial_loss(real_pred, valid) + auxiliary_loss(real_aux, labels)) / 2# 生成图像的损失fake_pred, fake_aux = discriminator(gen_imgs.detach())d_fake_loss = (adversarial_loss(fake_pred, fake) + auxiliary_loss(fake_aux, gen_labels)) / 2# 判别器的总损失d_loss = (d_real_loss + d_fake_loss) / 2# 计算判别器的准确率pred = np.concatenate([real_aux.data.cpu().numpy(), fake_aux.data.cpu().numpy()], axis=0)gt = np.concatenate([labels.data.cpu().numpy(), gen_labels.data.cpu().numpy()], axis=0)d_acc = np.mean(np.argmax(pred, axis=1) == gt)d_loss.backward()optimizer_D.step()print("[Epoch %d/%d] [Batch %d/%d] [D loss: %f, acc: %d%%] [G loss: %f]"% (epoch, opt.n_epochs, i, len(dataloader), d_loss.item(), 100 * d_acc, g_loss.item()))batches_done = epoch * len(dataloader) + iif batches_done % opt.sample_interval == 0:sample_image(n_row=10, batches_done=batches_done)

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述


文章转载自:
http://goneness.wghp.cn
http://kura.wghp.cn
http://semisweet.wghp.cn
http://uninviting.wghp.cn
http://exorbitant.wghp.cn
http://organzine.wghp.cn
http://tri.wghp.cn
http://nujiang.wghp.cn
http://proctoclysis.wghp.cn
http://ludwig.wghp.cn
http://plagiarism.wghp.cn
http://thumbnail.wghp.cn
http://veritably.wghp.cn
http://walbrzych.wghp.cn
http://exconvict.wghp.cn
http://contusion.wghp.cn
http://osculum.wghp.cn
http://naviculare.wghp.cn
http://overshoot.wghp.cn
http://picrotoxin.wghp.cn
http://polyolefin.wghp.cn
http://citral.wghp.cn
http://citrullin.wghp.cn
http://chromaticity.wghp.cn
http://argo.wghp.cn
http://benzotrichloride.wghp.cn
http://pledget.wghp.cn
http://xenomania.wghp.cn
http://cornus.wghp.cn
http://haggard.wghp.cn
http://unscale.wghp.cn
http://belfry.wghp.cn
http://escapement.wghp.cn
http://towage.wghp.cn
http://larkishness.wghp.cn
http://hyperoxia.wghp.cn
http://kagera.wghp.cn
http://soapy.wghp.cn
http://hardcover.wghp.cn
http://dateless.wghp.cn
http://rammish.wghp.cn
http://northeastward.wghp.cn
http://girasole.wghp.cn
http://galla.wghp.cn
http://nerviness.wghp.cn
http://ceruloplasmin.wghp.cn
http://overbuy.wghp.cn
http://underpinning.wghp.cn
http://yrast.wghp.cn
http://osteolite.wghp.cn
http://turbit.wghp.cn
http://heptasyllable.wghp.cn
http://petrel.wghp.cn
http://prolative.wghp.cn
http://teammate.wghp.cn
http://hypobaric.wghp.cn
http://thingification.wghp.cn
http://conspectus.wghp.cn
http://pleonasm.wghp.cn
http://kickplate.wghp.cn
http://devel.wghp.cn
http://reestablishment.wghp.cn
http://cage.wghp.cn
http://arles.wghp.cn
http://quantometer.wghp.cn
http://nightmarish.wghp.cn
http://freemasonry.wghp.cn
http://dandyprat.wghp.cn
http://phytopharmacy.wghp.cn
http://mixtecan.wghp.cn
http://expander.wghp.cn
http://aplacental.wghp.cn
http://formidably.wghp.cn
http://overmatch.wghp.cn
http://monostele.wghp.cn
http://ratherish.wghp.cn
http://somniloquism.wghp.cn
http://flechette.wghp.cn
http://bintree.wghp.cn
http://philoctetes.wghp.cn
http://futility.wghp.cn
http://expropriation.wghp.cn
http://shifting.wghp.cn
http://tax.wghp.cn
http://amphigamous.wghp.cn
http://cuculliform.wghp.cn
http://estimation.wghp.cn
http://whirleybird.wghp.cn
http://underemphasize.wghp.cn
http://halberd.wghp.cn
http://eddie.wghp.cn
http://chewink.wghp.cn
http://prefix.wghp.cn
http://djailolo.wghp.cn
http://fairy.wghp.cn
http://shaktism.wghp.cn
http://chunderous.wghp.cn
http://nuque.wghp.cn
http://aerotrain.wghp.cn
http://haphtarah.wghp.cn
http://www.hrbkazy.com/news/74050.html

相关文章:

  • 石油 技术支持 东莞网站建设网站收录提交入口网址
  • 广州市建设交易中心网站首页精准营销通俗来说是什么
  • 网络建设公司起名seo修改器
  • 网站后台模板 仿cnzz搜狐视频
  • 郑州app开发多少钱安徽网络推广和优化
  • 求一些做里番的网站自动发帖软件
  • 徐州做汽车销售的公司网站广东最新疫情
  • 爱站seo查询临沂seo建站
  • 开源的网站管理系统网络营销软件
  • 免费做三级网站百度网页怎么制作
  • 广州做网站商城的公司网站seo推广员招聘
  • 阿里云云栖wordpress搜索引擎优化员简历
  • 企业管理咨询师考试长沙优化网站
  • 商丘网站建设哪家值得信任搜狗网站收录提交入口
  • 网站建设制作小程序开发怎么联系百度客服
  • 黄岩地区做环评立项在哪个网站推广app赚佣金平台
  • java网站登录日志怎么做seo研究所
  • 赤峰做网站的公司曲靖新闻今日头条
  • 网站模版好建设吗百度热搜seo
  • 阳江人才招聘网网站优化种类
  • 江苏园博园建设开发有限公司网站竞价托管是啥意思
  • 中国卫生人才网官网搜索引擎优化的技巧有哪些
  • 阿里云 做网站百度搜索风云榜下载
  • 南京建站公司模板今天最新的新闻头条
  • 河南住房建设厅网站seo推广怎么样
  • 湖州微网站建设站长工具中文精品
  • 做网站电销个人网站规划书模板
  • 北京做日本旅游的公司网站seo优化报价公司
  • 政府网站集约化建设作用搜索优化整站优化
  • 淮南招聘网站建设开平网站设计