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

/chapter7/project2 #33

Open
qiwang067 opened this issue May 15, 2021 · 10 comments
Open

/chapter7/project2 #33

qiwang067 opened this issue May 15, 2021 · 10 comments

Comments

@qiwang067
Copy link
Contributor

https://datawhalechina.github.io/easy-rl/#/chapter7/project2

Description

@MaxwellLiu
Copy link

参考代码 链接中dqn 应该改为 DQN.

@qiwang067
Copy link
Contributor Author

@MaxwellLiu
参考代码 链接中dqn 应该改为 DQN.

感谢反馈,github 的 pages 服务器出现问题了,不能更新在线阅读页面,等其回复正常,我们会及时更新

@qiwang067
Copy link
Contributor Author

@MaxwellLiu
参考代码 链接中dqn 应该改为 DQN.

感谢您的反馈,链接已更新

@mf093087
Copy link

cfg.max_episodes 这个在哪儿导入呢?

@johnjim0816
Copy link
Contributor

cfg.max_episodes 这个在哪儿导入呢?

你好,具体在哪个代码中,因为后面讲这个参数改为cfg.train_eps了,可能有漏掉的地方

@Johnsonzhao1
Copy link

您好,可以讲一下怎样用tensorboard查看结果吗,谢谢!

@15138922051
Copy link

moving average rewards有什么意义,怎么解释他呢

@vvvvvyron
Copy link

看到有人在问 tensorboard 的用法,刚好这几天看了 pytorch 的教程,就基于 pytorch 做个小结吧。

tensorboard 原本是 tensorflow 里的,随着版本的更新,目前 pytorchy 也支持了 tensorboard 这个功能。

tensorboard 是在 pytorchutils 库里,调用的时候需要 from torch.utils.tensorboard import SummaryWriter ,这个 SummaryWriter 就是将训练过程中的数据保存到日志中,然后在本地打开对应的端口查看对应的结果,模板如下:

from torch.utils.tensorboard import SummaryWriter

writer = SummaryWriter("logs")  # writer为自定义对象名,logs是日志文件名,这条代码实际就是创建一个日志文件以保存数据
writer.add_image("tag", image_tensor, global_step) # 往日志中添加单个图片,tensor和numpy array格式均可
writer.add_images("tag", images_tensor, global_step) # 往日志中添加一批图片
writer.add_scalar("tag", val, step)  #  # 往日志中添加常数
writer.close()   # 在结束整个流程后记得加上这一句,把writer关掉

还能添加其他东西,可以看一下 SummaryWriter 里边的内容,或者去 pytorch 官网看一下doc.
这里对上边的语句做一下解释。首先 tag 可以理解为曲线图的图名,如上边的图片中的 tag 就是 steps_of_each_episode, 然后 image_tensorval 就是我们想要保存的东西,对于曲线图可以理解为纵轴坐标, global step 就是横轴坐标。

那么如何如何查看 tensorboard 呢,可以在 pycharmterminal中输入 tensorboard --logdir=logs (这个代码其实就是把上边我们创建的日志文件的地址赋给logdir, logs要与上边定义writer一致)然后就有一个本地的端口链接,点进去就可以看到结果了,当然也可以自行修改端口避免在服务器上跑的时候和别人冲突了,语法: tensorboard --logdir=logs --port=xxxx(xxxx即为所要指定的端口, 默认为6006).

注意:如果不同训练过程中都使用 tensorboard 的话,且日志文件名没有更改,那么写入日志文件的 tag 应该进行修改,否则将会把结果绘制在之前的结果上边导致数据混乱,最好的方法就是更改日志文件名,比如这一次我用 writer = SummaryWriter("logs1"), 下一次用 writer = SummaryWriter("logs2")这样子。

最后举个简单的例子,比如要画个y = 2*x 的图,代码如下:

from torch.utils.tensorboard import SummaryWriter

writer = SummaryWriter("y_2x")
for x in range(20):
   y = 2 * x
   writer.add_scalar("y = 2x", y, x)

writer.close()

然后运行后在终端输入 tensorboard --logdir=y_2x 即可查看结果。

@leshui1991
Copy link

env.seed(1)已经废止,应当改用env.reset(seed=1)

@RaisaXmas
Copy link

请问这里的 Agent 的类和 cfg 类是要自己定义吗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants