Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an example with GAN and MINIST #5426

Merged
merged 23 commits into from
Jan 18, 2023

Conversation

Liyulingyue
Copy link
Contributor

@paddle-bot
Copy link

paddle-bot bot commented Nov 18, 2022

感谢你贡献飞桨文档,文档预览构建中,Docs-New 跑完后即可预览,预览链接:http://preview-pr-5426.paddle-docs-preview.paddlepaddle.org.cn/documentation/docs/zh/api/index_cn.html
预览工具的更多说明,请参考:[Beta]飞桨文档预览工具

@Liyulingyue Liyulingyue changed the title Add a example with GAN and MINIST Add an example with GAN and MINIST Nov 18, 2022
"cell_type": "markdown",
"metadata": {},
"source": [
"## 5. 模型训练"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以写一下预估的训练时间

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

solved

Copy link
Collaborator

@momozi1996 momozi1996 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RD认为:1、网络结构没问题
2、代码质量,无错误,无冗余,整体看起来整洁
3、运行无报错,一个训练完了可以达到图例效果,一个训练一半,看loss是收敛的
4、能否达到上线“官网-》文档-〉应用实践”的标准:这两个实例代码比较简单,但整体质量还可以,感觉可以合入

Copy link
Collaborator

@momozi1996 momozi1996 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@jzhang533 jzhang533 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可能有些格式错误,在Github展示,或者本地浏览,都显示'Invalid Notebook`

@momozi1996
Copy link
Collaborator

@Liyulingyue hi~ 需要回复一下RD们的审核意见~ 并回复h

@Liyulingyue
Copy link
Contributor Author

可能有些格式错误,在Github展示,或者本地浏览,都显示'Invalid Notebook`

@Liyulingyue hi~ 需要回复一下RD们的审核意见~ 并回复h

文件已更新~请查阅

Copy link
Collaborator

@momozi1996 momozi1996 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM,修改后已经补充一些基本说明,我这边没太多意见了~

"\n",
"作者信息:[Liyulingyue](https://github.com/Liyulingyue)\n",
"\n",
"更新日期:2022 年 11 月 18 日\n",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加上,摘要:一句话描述

"更新日期:2022 年 11 月 18 日\n",
"\n",
"## 1. 简要介绍\n",
"### 关于GAN\n",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GAN全称为Generative Adversary Network,**

"- 目前Paddle的梯度反馈是自动累加模式,所以可以多个batch,或者多个模块的loss单独进行backword\n",
"- 通过[Tensor].detach()的方式可以截断梯度传播\n",
"\n",
"### 致谢\n",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

致谢部分,放最最后

"- [一文搞懂生成对抗网络之经典GAN(动态图、VisualDL2.0)](https://aistudio.baidu.com/aistudio/projectdetail/551962)\n",
"- [生成对抗网络七日打卡营](https://aistudio.baidu.com/aistudio/course/introduce/16651)\n",
"\n",
"**什么?上面没看懂?不重要!往下看就行了!锐利的loss!锐利的更新!永远的两步走!**\n",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

删除这个“什么?上面没看懂?不重要!往下看就行了!锐利的loss!锐利的更新!永远的两步走!\n"”。暂时不需要太活泼的语言。

"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import matplotlib.animation as animation\n",
"import cv2"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请展示paddle的版本。print(paddle.version)

"一个手写数字数据集,Paddle已经集成了这个数据集。\n",
"\n",
"### 关于Paddle的梯度反馈\n",
"- 目前Paddle的梯度反馈是自动累加模式,所以可以多个batch,或者多个模块的loss单独进行backword\n",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

详细一点,关于Paddle的梯度反馈,的说明

"**什么?上面没看懂?不重要!往下看就行了!锐利的loss!锐利的更新!永远的两步走!**\n",
"\n",
"## 2. 环境设置\n",
"导入包,主要包括paddle和一些画图辅助,如plt\n",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

画图辅助? 改为:绘图函数plt等

"\n",
"如果想要换成其他数据集,可以自行参考如何使用`paddle.io.Dataset`和`paddle.io.DataLoader`,封装后即可轻松复用本项目代码进行训练。\n",
"\n",
"首先,加载数据集。"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3.1 数据集的加载

"cell_type": "markdown",
"metadata": {},
"source": [
"查看数据的形状,可以看到从dataloader返回的数据格式中,每张图大小为32*32,每张图片带有一个标签。"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3.2 示例数据展示

"cell_type": "markdown",
"metadata": {},
"source": [
"通过下述代码可以快捷查看十张图片。"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

下述改为下列

@momozi1996
Copy link
Collaborator

@wangna11BD wangna11BD 请RD在确认一下代码质量。

@wangna11BD
Copy link
Contributor

LGTM

@momozi1996
Copy link
Collaborator

2.环境设置,补充paddle的版本, print(paddle.version)
4. 模型组网“由于GAN只是一种框架,因此我们可以使用任何网络,这里简单使用了全连接层。” , 改为,介绍Generator+Discriminator

5.模型训练:
补充:参数设置的描述,包括分类器,step, loss, 梯度grad设置等,这些更重要。

@sunzhongkai588
Copy link
Collaborator

  1. 简要介绍那块儿,步骤描述里,“5. 重复第一到第五步直到收敛” 的前标应该改成 “6. 重复第一到第五步直到收敛”

  2. 模型训练那块儿也写下涉及到的 损失函数

  3. 模型预测那块儿的文字,可以去掉“啦~”之类的口语化文字。tutorial是面向所有开发者的,文字需要严谨~

"### 关于MINIST\n",
"[MINIST](http://yann.lecun.com/exdb/mnist/)是一个手写数字数据集,Paddle已经集成了这个数据集,可以通过封装好的API直接获取这个数据集中的内容。\n",
"\n",
"### 关于Paddle的梯度反馈\n",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"梯度反馈",这个词听起来有些怪。
是不是直接用梯度计算就好了。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"梯度反馈",这个词听起来有些怪。 是不是直接用梯度计算就好了。

solved

"关于梯度累加和梯度截断的介绍如下:\n",
"\n",
"1. 梯度累加:梯度累加是指在模型训练过程中,训练一个 batch 的数据得到梯度后,不立即用该梯度更新模型参数,而是继续下一个 batch 数据的训练,得到梯度后继续循环,多次循环后梯度不断累加,直至达到一定次数后,用累加的梯度更新参数,这样可以起到变相扩大 batch_size 的作用。受限于显存大小,可能无法开到更大的 batch_size,使用梯度累加可以实现增大 batch_size 的作用。动态图模式天然支持梯度累加,即只要不调用梯度清零 clear_grad 方法,动态图的梯度会一直累积。\n",
"2. 梯度截断:在一些任务中,只希望拿到正向预测的值,但是不希望更新参数,或者在反向的时候剪枝,减少计算量,阻断反向的传播,即可使用`paddle.Tensor.detach()`产生一个新的、和当前计算图分离的,但是拥有当前变量内容的临时变量。\n",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"梯度截断" ,这个说法,一般指把计算出来的梯度的值限制在某个范围内。
这里用,阻断反向传播,更恰当。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"梯度截断" ,这个说法,一般指把计算出来的梯度的值限制在某个范围内。 这里用,阻断反向传播,更恰当。

solved

Copy link
Collaborator

@sunzhongkai588 sunzhongkai588 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sunzhongkai588 sunzhongkai588 merged commit 8023c31 into PaddlePaddle:develop Jan 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants