Giter VIP home page Giter VIP logo

aichess's Introduction

aichess

使用alphazero算法打造属于你自己的象棋AI

一、每个文件的意义

collect.py 自我对弈用于数据收集

train.py 用于训练模型

game.py 实现象棋的逻辑

mcts.py 实现蒙特卡洛树搜索

paddle_net.py,pytorch_net.py 神经网络对走子进行评估

play_with_ai.py 人机对弈print版

UIplay.py GUI界面人机对弈

二、提供了两个框架的版本进行训练:

使用pytorch版本请设置config.py 中CONFIG['use_frame'] = 'pytorch',

使用pytorch版本请设置config.py 中CONFIG['use_frame'] = 'paddle'。

不管是使用哪个框架,都一定要安装gpu版本,而且要用英伟达显卡,因为我们蒙特卡洛一次走此要进行上千次的神经网络推理,所以必须要快!

三、本项目是多进程同步训练。

训练时,在终端运行python collect.py用于自我对弈产生数据,这个可以多开。

然后,在终端运行python train.py用于模型训练,这个终端只用开一个。

四、相关资源链接

B站视频链接:https://www.bilibili.com/video/BV183411g7GX

知乎文章:https://zhuanlan.zhihu.com/p/528824058?

aistudio上一键可运行项目:https://aistudio.baidu.com/aistudio/projectdetail/4215743 (可以使用免费的V100来进行训练)

五、参考与致谢

本项目主要参考的资料如下,十分感谢大佬们的分享 1、程世东 https://zhuanlan.zhihu.com/p/34433581 (**象棋cchesszero )

2、AI在打野 https://aistudio.baidu.com/aistudio/projectdetail/1403398 (用paddle打造的五子棋AI)

3、junxiaosong https://github.com/junxiaosong/AlphaZero_Gomoku (五子棋alphazero)

4、书籍:边做边学深度强化学习:PyTorch 程序设计实践

5、书籍:强化学习第二版

后续应该会对该AI继续训练下去,亲手造一个超强的下棋AI简直太酷了!

aichess's People

Contributors

socool1345 avatar tensorfly-gpu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

aichess's Issues

预测值

作者您好,请问走了一次前向传播的policy_value_fn预测出来的走子概率及状态估值都是Nan是怎么回事啊

关于gpu调用问题

大神的代码写的非常精巧,因为我是个小白,我看了您的代码不太理解是怎么调用的gpu,我感觉tensor还是跑在cpu上饿。。。

game.py graphic函数的调用

game.py graphic函数的调用是否都错了?
是否应该是下边这个样子??
if is_shown:
self.graphic(self.board, self.board.id2color[player1.player], self.board.id2color[player2.player])

半精度的计算速度问题

with autocast(): #半精度fp16

在使用自动精度之前,单步collect速度是20s左右,但是当我改成浮点固定精度float32并取消autocast后,单步速度到了16s左右,我猜是自动适配精度其实是额外的消耗,仅个人猜测,不知道有没有人跟我一样的实验结果?

合法动作的问题

大佬您好,我在看您写的Alpha chess,并按照您的意思,在自己写一个。
但是在collect过程中,他会做出不合法的动作,然后报错。
找了半天也没找到在哪里出问题了。
就是在您的这个demo里面,网络直接输出2084个动作,但是这些动作也是有不合法的,这不合法的动作,在哪里去掉或者约束呢。
因为马上要交作业了,所以有点着急请教您。

python collect.py后输出储存失败

已加载初始模型
F:\aichess-main\pytorch_net.py:75: UserWarning: Implicit dimension choice for log_softmax has been deprecated. Change the call to include dim=X as an argument.
policy = F.log_softmax(policy)
D:\Anaconda\envs\chess\lib\site-packages\torch\nn\functional.py:1949: UserWarning: nn.functional.tanh is deprecated. Use torch.tanh instead.
warnings.warn("nn.functional.tanh is deprecated. Use torch.tanh instead.")
走一步要花: 5.746572971343994
走一步要花: 5.981132745742798
F:\aichess-main\zip_array.py:51: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.
return np.array(zip_res)
存储失败

可能是库更新出现的小bug?分享一下

File "D:\MyResource\transport\aichess\zip_array.py", line 51, in zip_array
return np.array(zip_res)
^^^^^^^^^^^^^^^^^
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (123,) + inhomogeneous part.

要在返回的地方加一个return np.array(zip_res, dtype=object)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.