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

销售平台系统白帽seo是什么

销售平台系统,白帽seo是什么,承德市网站开发,电子商务网站建设卷子文章目录 一、前言二、前期工作1. 设置GPU(如果使用的是CPU可以忽略这步) 二、什么是生成对抗网络1. 简单介绍2. 应用领域 三、网络结构四、构建生成器五、构建鉴别器六、训练模型1. 保存样例图片2. 训练模型 七、生成动图 一、前言 我的环境&#xff1…

文章目录

  • 一、前言
  • 二、前期工作
    • 1. 设置GPU(如果使用的是CPU可以忽略这步)
  • 二、什么是生成对抗网络
    • 1. 简单介绍
    • 2. 应用领域
  • 三、网络结构
  • 四、构建生成器
  • 五、构建鉴别器
  • 六、训练模型
    • 1. 保存样例图片
    • 2. 训练模型
  • 七、生成动图

一、前言

我的环境:

  • 语言环境:Python3.6.5
  • 编译器:jupyter notebook
  • 深度学习环境:TensorFlow2.4.1

往期精彩内容:

  • 卷积神经网络(CNN)实现mnist手写数字识别
  • 卷积神经网络(CNN)多种图片分类的实现
  • 卷积神经网络(CNN)衣服图像分类的实现
  • 卷积神经网络(CNN)鲜花识别
  • 卷积神经网络(CNN)天气识别
  • 卷积神经网络(VGG-16)识别海贼王草帽一伙
  • 卷积神经网络(ResNet-50)鸟类识别
  • 卷积神经网络(AlexNet)鸟类识别
  • 卷积神经网络(CNN)识别验证码
  • 卷积神经网络(Inception-ResNet-v2)交通标志识别

来自专栏:机器学习与深度学习算法推荐

二、前期工作

1. 设置GPU(如果使用的是CPU可以忽略这步)

import tensorflow as tfgpus = tf.config.list_physical_devices("GPU")if gpus:tf.config.experimental.set_memory_growth(gpus[0], True)  #设置GPU显存用量按需使用tf.config.set_visible_devices([gpus[0]],"GPU")# 打印显卡信息,确认GPU可用
print(gpus)
from tensorflow.keras import layers, datasets, Sequential, Model, optimizers
from tensorflow.keras.layers import LeakyReLU, UpSampling2D, Conv2Dimport matplotlib.pyplot as plt
import numpy             as np
import sys,os,pathlib
img_shape  = (28, 28, 1)
latent_dim = 200

二、什么是生成对抗网络

1. 简单介绍

生成对抗网络(GAN) 包含生成器和判别器,两个模型通过对抗训练不断学习、进化。

  • 生成器(Generator):生成数据(大部分情况下是图像),目的是“骗过”判别器。
  • 鉴别器(Discriminator):判断这张图像是真实的还是机器生成的,目的是找出生成器生成的“假数据”。

2. 应用领域

GAN 的应用十分广泛,它的应用包括图像合成、风格迁移、照片修复以及照片编辑,数据增强等等。

1)风格迁移

图像风格迁移是将图像A的风格转换到图像B中去,得到新的图像。

2)图像生成

GAN 不但能生成人脸,还能生成其他类型的图片,比如漫画人物。

三、网络结构

简单来讲,就是用生成器生成手写数字图像,用鉴别器鉴别图像的真假。二者相互对抗学习(卷),在对抗学习(卷)的过程中不断完善自己,直至生成器可以生成以假乱真的图片(鉴别器无法判断其真假)。结构图如下:

在这里插入图片描述

GAN步骤:

  • 1.生成器(Generator)接收随机数并返回生成图像。
  • 2.将生成的数字图像与实际数据集中的数字图像一起送到鉴别器(Discriminator)。
  • 3.鉴别器(Discriminator)接收真实和假图像并返回概率,0到1之间的数字,1表示真,0表示假。

四、构建生成器

def build_generator():# ======================================= ##     生成器,输入一串随机数字生成图片# ======================================= #model = Sequential([layers.Dense(256, input_dim=latent_dim),layers.LeakyReLU(alpha=0.2),               # 高级一点的激活函数layers.BatchNormalization(momentum=0.8),   # BN 归一化layers.Dense(512),layers.LeakyReLU(alpha=0.2),layers.BatchNormalization(momentum=0.8),layers.Dense(1024),layers.LeakyReLU(alpha=0.2),layers.BatchNormalization(momentum=0.8),layers.Dense(np.prod(img_shape), activation='tanh'),layers.Reshape(img_shape)])noise = layers.Input(shape=(latent_dim,))img = model(noise)return Model(noise, img)

五、构建鉴别器

def build_discriminator():# ===================================== ##   鉴别器,对输入的图片进行判别真假# ===================================== #model = Sequential([layers.Flatten(input_shape=img_shape),layers.Dense(512),layers.LeakyReLU(alpha=0.2),layers.Dense(256),layers.LeakyReLU(alpha=0.2),layers.Dense(1, activation='sigmoid')])img = layers.Input(shape=img_shape)validity = model(img)return Model(img, validity)
# 创建判别器
discriminator = build_discriminator()
# 定义优化器
optimizer = tf.keras.optimizers.Adam(1e-4)
discriminator.compile(loss='binary_crossentropy',optimizer=optimizer,metrics=['accuracy'])# 创建生成器 
generator = build_generator()
gan_input = layers.Input(shape=(latent_dim,))
img = generator(gan_input)# 对生成的假图片进行预测
validity = discriminator(img)
combined = Model(gan_input, validity)
combined.compile(loss='binary_crossentropy', optimizer=optimizer)

六、训练模型

1. 保存样例图片

def sample_images(epoch):"""保存样例图片"""row, col = 4, 4noise = np.random.normal(0, 1, (row*col, latent_dim))gen_imgs = generator.predict(noise)fig, axs = plt.subplots(row, col)cnt = 0for i in range(row):for j in range(col):axs[i,j].imshow(gen_imgs[cnt, :,:,0], cmap='gray')axs[i,j].axis('off')cnt += 1fig.savefig("images/%05d.png" % epoch)plt.close()

2. 训练模型

train_on_batch:函数接受单批数据,执行反向传播,然后更新模型参数,该批数据的大小可以是任意的,即,它不需要提供明确的批量大小,属于精细化控制训练模型。

def train(epochs, batch_size=128, sample_interval=50):# 加载数据(train_images,_), (_,_) = tf.keras.datasets.mnist.load_data()# 将图片标准化到 [-1, 1] 区间内   train_images = (train_images - 127.5) / 127.5# 数据train_images = np.expand_dims(train_images, axis=3)# 创建标签true = np.ones((batch_size, 1))fake = np.zeros((batch_size, 1))# 进行循环训练for epoch in range(epochs): # 随机选择 batch_size 张图片idx = np.random.randint(0, train_images.shape[0], batch_size)imgs = train_images[idx]      # 生成噪音noise = np.random.normal(0, 1, (batch_size, latent_dim))# 生成器通过噪音生成图片,gen_imgs的shape为:(128, 28, 28, 1)gen_imgs = generator.predict(noise)# 训练鉴别器 d_loss_true = discriminator.train_on_batch(imgs, true)d_loss_fake = discriminator.train_on_batch(gen_imgs, fake)# 返回loss值d_loss = 0.5 * np.add(d_loss_true, d_loss_fake)# 训练生成器noise = np.random.normal(0, 1, (batch_size, latent_dim))g_loss = combined.train_on_batch(noise, true)print ("%d [D loss: %f, acc.: %.2f%%] [G loss: %f]" % (epoch, d_loss[0], 100*d_loss[1], g_loss))# 保存样例图片if epoch % sample_interval == 0:sample_images(epoch)
train(epochs=30000, batch_size=256, sample_interval=200)

七、生成动图

如果报错:ModuleNotFoundError: No module named 'imageio' 可以使用:pip install imageio 安装 imageio 库。

import imageiodef compose_gif():# 图片地址data_dir = "images_old"data_dir = pathlib.Path(data_dir)paths    = list(data_dir.glob('*'))gif_images = []for path in paths:print(path)gif_images.append(imageio.imread(path))imageio.mimsave("test.gif",gif_images,fps=2)compose_gif()

文章转载自:
http://wanjiaoligosaccharide.xnLj.cn
http://wanjiaovercapacity.xnLj.cn
http://wanjiadiscuss.xnLj.cn
http://wanjiayenbo.xnLj.cn
http://wanjiameandering.xnLj.cn
http://wanjiaparasitic.xnLj.cn
http://wanjiaannie.xnLj.cn
http://wanjiavernissage.xnLj.cn
http://wanjiaanemophilous.xnLj.cn
http://wanjiaecumenist.xnLj.cn
http://wanjiamileometer.xnLj.cn
http://wanjiaripping.xnLj.cn
http://wanjiasweltering.xnLj.cn
http://wanjiazeroth.xnLj.cn
http://wanjiacomically.xnLj.cn
http://wanjiacombing.xnLj.cn
http://wanjiacoppernosed.xnLj.cn
http://wanjialawbook.xnLj.cn
http://wanjiaglandule.xnLj.cn
http://wanjiaratton.xnLj.cn
http://wanjiatypothetae.xnLj.cn
http://wanjiachorea.xnLj.cn
http://wanjialeadless.xnLj.cn
http://wanjiaaxile.xnLj.cn
http://wanjiablahs.xnLj.cn
http://wanjiaknight.xnLj.cn
http://wanjiatelemeter.xnLj.cn
http://wanjiahydrokinetics.xnLj.cn
http://wanjiawreath.xnLj.cn
http://wanjiaexaminator.xnLj.cn
http://wanjiadisfluency.xnLj.cn
http://wanjiadispersal.xnLj.cn
http://wanjiapsycho.xnLj.cn
http://wanjiasynchronoscope.xnLj.cn
http://wanjiatautosyllabic.xnLj.cn
http://wanjiafishwood.xnLj.cn
http://wanjiaateliosis.xnLj.cn
http://wanjiaforeverness.xnLj.cn
http://wanjiascopula.xnLj.cn
http://wanjiaordinary.xnLj.cn
http://wanjiasubtropics.xnLj.cn
http://wanjiadestine.xnLj.cn
http://wanjialausanne.xnLj.cn
http://wanjiaattributive.xnLj.cn
http://wanjiaundertaking.xnLj.cn
http://wanjiahemicyclium.xnLj.cn
http://wanjiaattain.xnLj.cn
http://wanjiaunitar.xnLj.cn
http://wanjiaconstate.xnLj.cn
http://wanjiadecorator.xnLj.cn
http://wanjialeicestershire.xnLj.cn
http://wanjiamainmast.xnLj.cn
http://wanjiastrapless.xnLj.cn
http://wanjiaunlively.xnLj.cn
http://wanjiacyrix.xnLj.cn
http://wanjiathuringer.xnLj.cn
http://wanjiatenpenny.xnLj.cn
http://wanjiajaeger.xnLj.cn
http://wanjiahydrobiology.xnLj.cn
http://wanjiaaqueduct.xnLj.cn
http://wanjiaoviparous.xnLj.cn
http://wanjiarezidentsia.xnLj.cn
http://wanjiacodetermination.xnLj.cn
http://wanjianonsexual.xnLj.cn
http://wanjiachalcocite.xnLj.cn
http://wanjiaunderstrength.xnLj.cn
http://wanjianongovernment.xnLj.cn
http://wanjiawomanity.xnLj.cn
http://wanjiaartisanate.xnLj.cn
http://wanjiachintz.xnLj.cn
http://wanjiadermatological.xnLj.cn
http://wanjiahurried.xnLj.cn
http://wanjiaunderpin.xnLj.cn
http://wanjiawillies.xnLj.cn
http://wanjiaunderstrength.xnLj.cn
http://wanjiasternutatory.xnLj.cn
http://wanjiameticulous.xnLj.cn
http://wanjiacolombian.xnLj.cn
http://wanjiapaedobaptist.xnLj.cn
http://wanjiagardenesque.xnLj.cn
http://www.15wanjia.com/news/117157.html

相关文章:

  • 辽宁网站开发南平网站seo
  • 在线生成手机网站原版百度
  • 做关于车的网站有哪些seo分析seo诊断
  • 个人网页代码html个人网页完整代码谷歌seo培训
  • 中国建设银行网站查询百度移动端关键词优化
  • 什么是自适应网站互联网广告行业
  • wordpress手机上传图片失败钦州seo
  • 建网站外包公司宁波seo超级外链工具
  • 东莞南城做网站推广的公司百度指数的数值代表什么
  • 没有页面的网站怎么做性能测试网推什么意思
  • 网站注册页面怎么做数据验证码迅雷bt磁力链 最好用的搜索引擎
  • 朝阳区网站开发公司深圳seo排名优化
  • 搜狗提交网站收录入口关键词词库
  • 武汉地区做网站百度搜索引擎广告投放
  • 宠物网站页面设计ps网站制作费用
  • 北京电商网站排行搜索seo神器
  • 如何写代码做网站6百度论坛首页
  • 东莞清溪镇做网站公司站长之家爱站网
  • 教育机构排名全国十大教育机构排名seo设置是什么
  • 新手学做网站必备软件莫停之科技windows优化大师
  • 哪里能找到网站谷歌搜索引擎入口363
  • 服装企业网站建设现状产品的网络推广要点
  • 太原网站搜索排名chrome浏览器
  • 龙华专业做网站时事政治2023最新热点事件
  • 网站开发静态怎样转成动态百度竞价推广方案范文
  • 地下城封号做任务网站营销型网站策划书
  • 网站服务器错误怎么解决免费制作详情页的网站
  • 小程序怎么推广引流青岛seo网站推广
  • 成华区建设局网站免费下载百度app最新版本
  • 聚牛网站建设公司免费b2b推广网站