65、生成对抗网络(GAN):原理、挑战与实践

生成对抗网络(GAN):原理、挑战与实践

1. 生成对抗网络基础

生成对抗网络(GAN)由生成器和判别器两个部分组成。生成器的目标是学习创建与给定数据集相似的新数据,而判别器则要学会区分生成器的输出和真实数据。在训练过程中,两者相互学习,交替进行训练,以提升各自的能力。

1.1 训练过程

训练时,从训练集中选取一个小批量的点,然后按照特定的四阶段流程,交替训练判别器和生成器。在训练生成器时,我们希望仅更新生成器的权重,而控制层权重是否更新的机制因使用的库而异,通常会使用“冻结”“锁定”或“禁用”等术语来防止特定层的权重更新,在训练判别器时再解除这些限制。

1.2 简单GAN示例

为了训练一个简单的GAN,我们从初始的高斯分布中随机抽取10,000个点作为训练集,使用大小为32的小批量进行训练,将所有10,000个点通过系统一次称为一个训练周期。

训练结果显示,经过一个训练周期后,GAN生成的点在西南 - 东北方向形成一条模糊的线,大致以(1,1)为中心。随着训练周期的增加,生成的点逐渐接近原始数据的中心和形状。在第4个训练周期左右,生成的样本会超过中心,并且变得越来越椭圆而不是圆形,但随后会逐渐调整,到第13个训练周期时,匹配效果已经非常好。

判别器和生成器的损失曲线显示,理想情况下判别器的损失应稳定在0.5左右,这意味着它无法确定输入是来自真实数据集还是生成器。在这个小例子中,判别器的表现已经相当接近理想状态。

2. DCGAN:用于图像的生成对抗网络

如果要处理图像数据,我们通常会选择使用卷积层来构建判别器和生成器,这种由多个卷积层构建的GAN被

相关推荐

GAN原理与实战:从对抗机制到稳定训练的完整指南

生成式对抗网络(GAN)是一种基于博弈论思想的无监督生成模型,其核心是通过生成器(Generator)与判别器(Discriminator)的极小极大动态博弈,逼近真实数据分布。该机制本质上是学习隐空间到数据空间的非线性映射,依赖纳什均衡达成分布一致性,而非简单分类或像素重建。技术价值在于无需显式概率建模即可合成高维复杂数据,在图像生成、数据增强、隐私保护等场景落地广泛。但实际应用中常受模式坍缩(Mode Collapse)、训练不稳定(Training Instability)和梯度消失(Vanishin

ciya3282的博客 341

GAN原理通俗解析:造假者与鉴酒师的对抗博弈

生成式对抗网络(GAN)是一种基于博弈论思想的生成模型,其核心在于生成器与判别器之间的动态对抗优化过程。它通过极小极大(minimax)目标函数驱动两个神经网络相互竞争、协同进化,从而逼近真实数据分布。相比自编码器等单模型方法,GAN能有效缓解模式坍塌问题,提升生成多样性与真实性。该技术已广泛应用于图像合成、风格迁移、数据增强及AIGC内容生成等场景。本文以‘造假者vs鉴酒师’为认知锚点,结合Keras代码实操,深入浅出地揭示GAN中标签平滑、tanh归一化、交替训练等关键设计背后的工程逻辑。

weixin_30338481的博客 502

基于GAN生成动漫人物图像

基于GAN生成动漫人物图像是一项具有广泛应用前景的技术,通过对抗训练,生成器和判别器不断提升,在多种场景下创造逼真的图像。

走向CTO的路上... 741

Arduino粉尘传感器DIY:打造智能PM2.5监测仪

本文详细介绍了如何利用Arduino和粉尘传感器DIY一个智能PM2.5监测仪。从硬件选购、接线步骤到代码编写,提供了完整的制作指南,帮助读者以低成本打造透明可靠的空气质量监测设备,并探讨了数据解读与智能升级方案。

i3j4k5的博客 393

APK静态分析(取证角度)——理论部分

APP是指应用程序(Application),是指能够在手机、平板电脑、电脑等移动设备上运行的软件。APP可以帮助用户进行各种功能操作,如社交媒体、游戏、购物、学习、工作等。用户可以通过应用商店或者在线下载安装APP,然后在设备上使用它们。APP的种类非常丰富,能够满足用户不同的需求和兴趣。

currify的博客 3210

Hifiasm参数调优实战:当N50不理想时的7个排查方向与解决方案

本文详细解析了Hifiasm参数调优实战,针对基因组组装中N50不理想的7个排查方向与解决方案。通过调整--hom-cov、-D、-N等核心参数,结合HiFi数据和参考基因组分析,有效提升组装质量。文章以猪毛菜基因组为例,展示了从2.1MB到4.3MB的N50优化过程,为生物信息学研究者提供实用指南。

weixin_30642561的博客 426

QT+QTimer+QThread实现线程内的定时任务并且和主线程进行交互

在制作qt软件时,我们经常会用到qtimer定时器以及将其在非主线程中进行使用,甚至有的时候还需要和主线程进行交互。我总结了两种用法,仅供参考。以上即为QTimer和QThread联合使用的学习记录。

u011826081的博客 5686

GD32单片机引脚复用指南:如何让JTAG接口的PA15/PB3发挥第二功能?

本文详细介绍了GD32F103Cx系列单片机如何通过AFIO模块进行引脚复用,特别是将默认用于JTAG调试接口的PA15、PB3等引脚释放为普通IO或复用功能引脚。文章从原理出发,结合代码实践,讲解了如何配置调试端口重映射,将JTAG引脚安全地转换为GPIO或定时器通道,并提供了常见问题排查与最佳实践,帮助开发者高效利用有限的引脚资源。

nept的博客 810

台达PLC DIAdesigner-AX 编程实战:从安装到通信配置

本文详细介绍了台达PLC DIAdesigner-AX编程的实战操作,从软件安装、项目创建到通信配置的全流程。重点讲解了TCP/IP通信设置、库文件管理及常见错误处理,帮助工程师快速掌握台达PLC编程技巧,提升工业自动化项目的开发效率。

weixin_29215391的博客 532

复旦微FMSH_Procise安装流程

双击FMSH_Procise_2021.1_full_win64_202103151947.exe 选择好安装目录后点击“Next” 一路next 点install 找技术支持代为申请 License,将电脑MAC地址发过去,将获得的 license 拷贝到 procise 安装目录“data”文件夹,即可使用 procise。点license manager和copy license 将licence,.lic文件放到这个目录 要是报下面错误要...

wangjie36的博客 1万+

超大规模系统(千万级用户)中实现字段级权限控制

摘要:本文提出了一套分布式架构下的字段级权限优化方案,结合RBAC+ABAC混合模型与技术手段实现性能与安全的平衡。方案包括:1)权限模型优化,采用RBAC预计算基础权限与ABAC动态校验敏感字段;2)数据层优化,实现动态字段过滤与加密存储;3)多级缓存策略与预计算机制提升性能;4)分布式架构设计,通过网关校验和策略引擎集群保证扩展性。最终在千万级用户系统中实现99.9%可用性,权限校验延迟控制在50ms以内。

从技术实践立足,从项目管理方法论延伸思考 1354

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: 32、开发Widget与探索ARKit增强现实技术
下一篇: 51、DeRis:支持企业违约风险预测的信息系统
java5
博客等级 码龄22年 85粉丝 2103原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值