鼠哥day

导航

tensorflow2 tf2 DDPG算法玩立棍小游戏

 DDPG算法就不做过多解读了,就是用来进行连续值预测,本文是使用DDPG进行立棍小游戏,详细过程解读注释在代码中,算法和模型都非常简单,考验的是基础,使用两个全连接模型,相互配合更新,共同让整个模型进步,所以本篇文章不再对算法做过多解释

 

 

训练日志 :

观察加权分数,可以看到分数波动是非常剧烈的,但通过多次探索后,会以极快的速度达到游戏设定的满分3000分

加权得分 : 0.995累计奖励 + 0.005 最新奖励

....

 ....

 ...

 

版本:

python 3.9

tensorflow-gpu 2.6.0

 

除上述代码意外,其他环境准备

# 解决 tensorflow2 加载模型时报错的问题
# pip install keras==2.6.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
 
# 游戏环境完善
# pip install gym -i https://pypi.tuna.tsinghua.edu.cn/simple
# pip install ale-py  -i https://pypi.tuna.tsinghua.edu.cn/simple
# pip install gym[accept-rom-license] -i https://pypi.tuna.tsinghua.edu.cn/simple
 
# 安装后会报一些错,但测试已经可以运行
# pip install gym[all] -i https://pypi.tuna.tsinghua.edu.cn/simple

  

完整代码:

MouseDay/ddpg

 

ddpg                                            // 目录,存储了详细的日志文件
all_model.py                                    // 模型文件
begin.py                                        // 代码执行入口
cjs_util.py                                     // 工具类,主要是处理游戏运行数据,写入日志
env.py                                          // 游戏环境文件
replay_memory.py                                // 游戏运行数据缓存文件

 

 

 

 

 

 

 

 

 

 

 


posted on 2022-03-17 13:48  鼠哥day  阅读(210)  评论(0编辑  收藏  举报