用Resnet101+GPT搭建一个玩王者荣耀的AI

Overview

基于pytorch框架用resnet101加GPT搭建AI玩王者荣耀

本源码模型主要用了SamLynnEvans Transformer 的源码的解码部分。以及pytorch自带的预训练模型"resnet101-5d3b4d8f.pth"

注意运行本代码需要注意以下几点 注意!!!!!

1、目前这个模型在用后裔100多局对战数据下训练出来后,对局表现出各种送人头之类的问题,以及代码本身各种不规范,请多原谅。
2、本代码本来只是我试验模型能否玩王者荣耀,B站朋友强烈要求开源。仓促开源估计问题很多,请多原谅。
三、运行环境win10;win7未测试,估计是可以。 需要一张6G或以上显存的英伟达显卡,虽然4G的1050ti勉强也可以。
四、需要一台打开安卓调试并能玩王者荣耀的手机,虚拟机没有试过,理论上应该可行。
五、需要下载scrcpy 的windows版本。 把所有文件解压到项目根目录即可(这是我的笨办法) 。
位置如图
scrcpy
六、pyminitouch库运行时会自动安装minitouch。如果无法自动安装则需要手动安装minitouch ,比较麻烦,如有困难请多多百度。
还有,minitouch不支持Android10
七、本人用的手机分辨率是1080*2160的,本代码并没有针对不同的手机做优化。不同的手机minitouch命令中所描述的位置会有差异,需要对代码做出相应调整,请务必注意。
八、注意游戏的布局,务必要一样。布局可参考B站视频或者我上传的训练用截图。如图。
布局图
九、游戏更新以后可能会导致无法预料的后果,因此并不能保证此代码玩王者荣耀的长期有效性。
我之后可能出视频教程,同时讲讲我的设计思路。部分地区截图不可见,可下载项目在pycharm下打开readme.md即可见。

运行与生成训练数据

需要的库
torch
torchvision
pynput
pyminitouch
可能还有其它库

运行训练好的模型

如果前面的工作做好了就可以把模型跑起来了,这里声明这个经过训练的模型仅仅训练100多局,水平很低,青铜人机都未必能打过。
一、首先下载模型 你可以从google云盘 下载训练过的模型,也可以百度网盘下载
链接:https://pan.baidu.com/s/1Bt7BXukDDCpc1aWFI2iKxg
提取码:5c1k
后放入weights文件夹下
二、先运行 “启动和结束进程.py” 启动scrcpy 把“训练数据截取_A.py” 中的两项改成你的,_DEVICE_ID 是 adb devices后显示的那个id
启动和结束进程.py
三、启动王者荣耀进入5v5人机对战 运行 “训练数据截取_A.py” 即可。

生成训练数据

运行 “训练数据截取_A.py” 时可以通过按键操控角色,这时就可以生成训练用的数据,如果没有操控则会生成一个空文件夹和空json文件。
按"i"键则结束或则是重新运行
按键'w' 's ' 'a' 'd'控制方向 左、下、右箭头对应是1、2、3技能,上箭头长按则攻击。其它按键请参考源码。
每次获取训练图片最好不要超过5000张

你也可以下载训练数据样本(只是样本,数据量不大,不能指望两局对战数据就有效果,我估计这个模型现有参数可以吃下上万场的对战数据)
百度网盘 链接:https://pan.baidu.com/s/1Ak1sLcSRimMWRgagXGahTg 提取码:t4k3
google云盘
解压后注意存放位置,请参考源码。

如何训练

一、数据预处理
将图片用resnet101预处理后再和对应操作数据一起处理后用numpy数组储存备用。
具体要做的就是运行 “处理训练数据5.py”
二、训练
预处理完成以后运行 “训练_B.py”即可。

游戏按键映射本地化

按键映射通过 './json/名称_操作.json' 文件完成,如前文所述,由minitouch进行按压模拟。

  1. 前期准备:

开启“开发者模式”,允许“USB调试”,允许“USB调试(安全设置):允许通过USB调试修改权限或模拟点击”。后两项均在进入开发者选项后可以找到。

  1. 按键可视化,按键轨迹监控:

开启“显示点按操作的视觉反馈”,开启“指针位置”。后者方便查看自己手机屏幕点按的像素点坐标信息,从而生成对应本地手机按键映射的.json文件。

  1. 映射本地化计算说明:

layout_description 此计算以手机充电口朝右握持为例,反向握持同理可推。样例手机分辨率1080x2160。 Android“指针位置”中显示的坐标信息以图中左上角红色原点所示,xy轴如图。此原点不论如何握持(充电口朝左或右),其始终保持在视野左上角,由重力感应判定。 minitouch坐标原点如图中左下角蓝色原点所示,此点为物理固定点,不随手机握持方向改变,反向握持此点在右上角。 另外注意两个坐标系xy轴方向不同。 在图中设定下,Android指针坐标(X,Y)对应minitouch坐标(1080-Y,X):即在点按屏幕中某点时,安卓调试显示的(X,Y)在.json文件中的坐标应为(1080-Y,X)。

  1. 本地映射文件生成:

'check_json.py'为调试和生成本地.json按键映射文件的脚本。重映射时请一一记录每个按键在自己手机中显示的“指针位置”,并按照上述计算方法换算为.json文件中需 要输入的坐标。此脚本会生成一个'./json/local_layout.json'文件,请在'处理训练数据5.py'中进行相应替换。 此外,'处理训练数据5.py'中:‘加一技能’,‘加二技能’,‘加三技能’,‘购买’变量也许进行同样处理。.json文件中指令含义请参照minitouch

Owner
冯泉荔
冯泉荔
Chinese version of GPT2 training code, using BERT tokenizer.

GPT2-Chinese Description Chinese version of GPT2 training code, using BERT tokenizer or BPE tokenizer. It is based on the extremely awesome repository

Zeyao Du 5.6k Jan 04, 2023
PyTorch implementation of Tacotron speech synthesis model.

tacotron_pytorch PyTorch implementation of Tacotron speech synthesis model. Inspired from keithito/tacotron. Currently not as much good speech quality

Ryuichi Yamamoto 279 Dec 09, 2022
Modular and extensible speech recognition library leveraging pytorch-lightning and hydra.

Lightning ASR Modular and extensible speech recognition library leveraging pytorch-lightning and hydra What is Lightning ASR • Installation • Get Star

Soohwan Kim 40 Sep 19, 2022
Code for Findings of ACL 2022 Paper "Sentiment Word Aware Multimodal Refinement for Multimodal Sentiment Analysis with ASR Errors"

SWRM Code for Findings of ACL 2022 Paper "Sentiment Word Aware Multimodal Refinement for Multimodal Sentiment Analysis with ASR Errors" Clone Clone th

14 Jan 03, 2023
Reproduction process of BERT on SST2 dataset

BERT-SST2-Prod Reproduction process of BERT on SST2 dataset 安装说明 下载代码库 git clone https://github.com/JunnYu/BERT-SST2-Prod 进入文件夹,安装requirements pip ins

yujun 1 Nov 18, 2021
Honor's thesis project analyzing whether the GPT-2 model can more effectively generate free-verse or structured poetry.

gpt2-poetry The following code is for my senior honor's thesis project, under the guidance of Dr. Keith Holyoak at the University of California, Los A

Ashley Kim 2 Jan 09, 2022
[ICLR 2021 Spotlight] Pytorch implementation for "Long-tailed Recognition by Routing Diverse Distribution-Aware Experts."

RIDE: Long-tailed Recognition by Routing Diverse Distribution-Aware Experts. by Xudong Wang, Long Lian, Zhongqi Miao, Ziwei Liu and Stella X. Yu at UC

Xudong (Frank) Wang 205 Dec 16, 2022
Natural language Understanding Toolkit

Natural language Understanding Toolkit TOC Requirements Installation Documentation CLSCL NER References Requirements To install nut you need: Python 2

Peter Prettenhofer 119 Oct 08, 2022
A fast and easy implementation of Transformer with PyTorch.

FasySeq FasySeq is a shorthand as a Fast and easy sequential modeling toolkit. It aims to provide a seq2seq model to researchers and developers, which

宁羽 7 Jul 18, 2022
Negative sampling for solving the unlabeled entity problem in NER. ICLR-2021 paper: Empirical Analysis of Unlabeled Entity Problem in Named Entity Recognition.

Negative Sampling for NER Unlabeled entity problem is prevalent in many NER scenarios (e.g., weakly supervised NER). Our paper in ICLR-2021 proposes u

Yangming Li 128 Dec 29, 2022
A 30000+ Chinese MRC dataset - Delta Reading Comprehension Dataset

Delta Reading Comprehension Dataset 台達閱讀理解資料集 Delta Reading Comprehension Dataset (DRCD) 屬於通用領域繁體中文機器閱讀理解資料集。 本資料集期望成為適用於遷移學習之標準中文閱讀理解資料集。 本資料集從2,108篇

272 Dec 15, 2022
基于GRU网络的句子判断程序/A program based on GRU network for judging sentences

SentencesJudger SentencesJudger 是一个基于GRU神经网络的句子判断程序,基本的功能是判断文章中的某一句话是否为一个优美的句子。 English 如何使用SentencesJudger 确认Python运行环境 安装pyTorch与LTP python3 -m pip

8 Mar 24, 2022
Convolutional Neural Networks for Sentence Classification

Convolutional Neural Networks for Sentence Classification Code for the paper Convolutional Neural Networks for Sentence Classification (EMNLP 2014). R

Yoon Kim 2k Jan 02, 2023
Text to speech for Vietnamese, ez to use, ez to update

Chào mọi người, đây là dự án mở nhằm giúp việc đọc được trở nên dễ dàng hơn. Rất cảm ơn đội ngũ Zalo đã cung cấp hạ tầng để mình có thể tạo ra app này

Trần Cao Minh Bách 32 Jul 29, 2022
Python library for interactive topic model visualization. Port of the R LDAvis package.

pyLDAvis Python library for interactive topic model visualization. This is a port of the fabulous R package by Carson Sievert and Kenny Shirley. pyLDA

Ben Mabey 1.7k Dec 20, 2022
Trankit is a Light-Weight Transformer-based Python Toolkit for Multilingual Natural Language Processing

Trankit: A Light-Weight Transformer-based Python Toolkit for Multilingual Natural Language Processing Trankit is a light-weight Transformer-based Pyth

652 Jan 06, 2023
PyTorch source code of NAACL 2019 paper "An Embarrassingly Simple Approach for Transfer Learning from Pretrained Language Models"

This repository contains source code for NAACL 2019 paper "An Embarrassingly Simple Approach for Transfer Learning from Pretrained Language Models" (P

Alexandra Chronopoulou 89 Aug 12, 2022
Input english text, then translate it between languages n times using the Deep Translator Python Library.

mass-translator About Input english text, then translate it between languages n times using the Deep Translator Python Library. How to Use Install dep

2 Mar 04, 2022
My implementation of Safaricom Machine Learning Codility test. The code has bugs, logical I guess I made errors and any correction will be appreciated.

Safaricom_Codility Machine Learning 2022 The test entails two questions. Question 1 was on Machine Learning. Question 2 was on SQL I ran out of time.

Lawrence M. 1 Mar 03, 2022
Codes for coreference-aware machine reading comprehension

Data and code for the paper "Tracing Origins: Coreference-aware Machine Reading Comprehension" at ACL2022. Dataset There are three folders for our thr

11 Sep 29, 2022