Sentdex / pygta5

Explorations of Using Python to play Grand Theft Auto 5.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

getkeys.py linux alternative

PeterGardas opened this issue · comments

Good morning

Is there any alternative to the sentdexe's getkeys.py for linux python3?. I have been trying a lot of things now and i am really nervous becouse i have to do my project fast. The key recorders that i tried worked but either stopped the loop or showed None when i try to play the training data.

Thanks for help

Petr Gardas

Okay so couple hours of coding and research and i found the alternative:
`
import keyboard #Using module keyboard
import time

w = [1, 0, 0, 0, 0, 0, 0, 0, 0]
a = [0, 1, 0, 0, 0, 0, 0, 0, 0]
d = [0, 0, 1, 0, 0, 0, 0, 0, 0]
wa = [0, 0, 0, 1, 0, 0, 0, 0, 0]
wd = [0, 0, 0, 0, 1, 0, 0, 0, 0]
sa = [0, 0, 0, 0, 0, 1, 0, 0, 0]
sd = [0, 0, 0, 0, 0, 0, 1, 0, 0]
s = [0, 0, 0, 0, 0, 0, 0, 1, 0]
space = [0, 0, 0, 0, 0, 0, 0, 0, 1]
nothing = [0, 0, 0, 0, 0, 0, 0, 0, 0]

def KeysGet():
if keyboard.is_pressed('w') and keyboard.is_pressed('a'):
return wa
if keyboard.is_pressed('w') and keyboard.is_pressed('d'):
return wd
if keyboard.is_pressed('s') and keyboard.is_pressed('a'):
return sa
if keyboard.is_pressed('d') and keyboard.is_pressed('s'):
return sd
if keyboard.is_pressed('w'): #if key 'up' is pressed.You can use right,left,up,down and others
return w
if keyboard.is_pressed('a'):
return a
if keyboard.is_pressed('d'):
return d
if keyboard.is_pressed('s'):
return s
if keyboard.is_pressed('space'):
return space
else:
return nothing
`

That is great! By the way, do u ballance data before training, and what version\net you are using?

Yes i balance data before training i am using alexnet 2 or alexnet but unfortunetally i only get accuracy of about 33% :(. Dunno why.

@SnailingGoat that's strange, i also use alexnet2, with a little lower values or it doesnt start, so how many ballanced files do you have? better to start with 200 files (100000 frames) and train it about 20-30+ epochs, i use it in crossout game, have accuracy about 80-90+% but on testing bot stucks too often( seems need more frames. for what game/project you training your net?

btw, you use 10 actions, but your array have only 9 elements, doesnt it couse error?

I changed everything now i use googlenet, i get a good accuracy. About 90%, but when i start the model it just chooses one action and makes that choice every time :( . I dont know what to do about this

@SnailingGoat i also tried with google net, but it trains so long, and i use smaller batch_size, that is not good for acc, and dont understand if my tensorflow-gpu even use gpu or hust cpu, so strange thing happens, but my net with 30-40 acc tryed to turn, so question is, did you ballance data?
Because if not, your training data mostly press w, thats why your model also press w whole time.

btw most of time i get this outpu in each iteration
2018-06-11 02:52:37.884704: W T:\src\github\tensorflow\tensorflow\stream_executor\cuda\cuda_dnn.cc:3526]
Training Step: 4596 | total loss: 1.51834 | time: 38.132s
| Momentum | epoch: 010 | loss: 1.51834 - acc: 0.3991 -- iter: 192/450

so it's kinda strange, seems trainig goes, but vram 0,2/3.9 gb
most fun is my card seems have 4gb vram, but this happens
2018-06-11 02:38:26.470734: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:1053] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 550 MB memory) -> physical GPU (device: 0, name: GeForce 940MX, pci bus id: 0000:01:00.0, compute capability: 5.0)

so only 550 mb!!!!!!
hashtag windowsmustdie

I got everything working now. It was stupid mistake i was not saving the model and the check point was set too high, anyways its weird you get that small accuracy... I trained on A CPU :O and here is my graph of accuracy:
graf_rocnikovka
How many training data do you have.
I personally only got 20 left turns recorded then trained it on that..

If you want i could make a github repo of my project :D. Just text me.

Petr Gardas a.k.a SnailingGoat

стоп, что?
у тебя грубо говоря 60 фреймов,
20 влево, 20 вперёд, 20 вправо?

@SnailingGoat it was just sample, after few training acc about 70-80%
game is just a bit complex(crossout), no normal roads and my model dont watch minimap for now, also have just 17000 frames, and had problems with hardware due to overheating, so looking for cloud server to train for now, better tell, how much training frames do you have and how much epochs trained, and is your model act good in game?

I have only about 1000 frames i did 250 epochs and i shuffled the data every epoch not just once, my model is fairly good..

@SnailingGoat thx, that's cool!

No problem pal :D.

Petr Gardas