freeCodeCamp.org
In this Python Reinforcement Learning course you will learn how to teach an AI to play Snake! We build everything from scratch using Pygame and PyTorch.
💻 Code: https://github.com/python-engineer/snake-ai-pytorch
✏️ Course developed by Python Engineer. Check out his YouTube channel: https://www.youtube.com/channel/UCbXgNpp0jedKWcQiULLbDTA
🎨 Art by Rachel: http://rachel.likespizza.com/
⭐️ Course Contents ⭐️
⌨️ (0:00:00) Part 1: Basics of Reinforcement Learning and Deep Q Learning
⌨️ (0:17:22) Part 2: Setup environment and implement snake game
⌨️ (0:40:07) Part 3: Implement agent to control game
⌨️ (1:10:59) Part 4: Create and train neural network
🎉 Thanks to our Champion and Sponsor supporters:
👾 Raymond Odero
👾 Agustín Kussrow
👾 aldo ferretti
👾 Otis Morgan
👾 DeezMaster
—
Learn to code for free and get a developer job: https://www.freecodecamp.org
Read hundreds of articles on programming: https://freecodecamp.org/news
Source
dumb question ik, but what is the box he is usint to code, is it CMD, or windows power shell etc ?
Thanks for the awesome video! Really fun to see agent improving during the games.
Very interesting topic, but a very bad teacher.
He doesn't explain almost anything and the little he explains he talks about them very briefly like we already know all of those things and we make a revision.
Very interesting tutorial. I was familiar with Snake code implementations, Tensorflow basics and RL principles and I could follow along. For some reason the plot doesn't appear, and I only get a small blank window where the plot should be. Probably some bug while typing the code down.
Other than that everything works for me.
Thank you very much!
A nice video. My only critique is that the presenter kept writing code for almost an hour without running it. That's not giving a good example.
I want it to play minesweeper
Incredible work, thank you Patrick! PS: It is very funny to spot the typos/bugs before you do 🙂
38:13 "It has to be [0,0,1]" <— What about [0,0,0]? I think you should have explicitly checked for [0,0,1].
(Or other weird states. 1,1,0 or 1,0,1 or etc…)
I did it!!! Thanks for showing this.
so i had the program run over 2000 games and it couldn't get past the 80s mark. how would i get it to improve past that?
thank you very much.
Does this tutorial teach how to write "inference" by myself, not using library?
Thanks for the video it was great but I have only one question if u can help after I run the agent and after a few try like 3rd game the game stuck and in the console suddenly start to count the number of game without the game really play
i just want to know after training, how can we load back a trained model?
Thank you so much for this tutorial. I have always wanted to introduce snake with ML. and now looking forward to learning more about pytorch
Nice video but Too big
Do you legally own the AI you trained?!!
you should blink more. your eyes look a lil dry.
Great tutorial
Is there a limit to when it stops learning? I mean the quality of the intelligence will stay the same at some point, or will it improve even more and more after those 12 minutes? Thanks.
nice algo, but how to solve a problem with self destroy, when the closest cell to move is "inside body circle". I think a state must be all field with each body part,head, food etc, but its endless states and all of them unique and it will never learns or may be i wrong?
The snake moves smoothly, but when it hits the first wall, the interface closes idk :/
Thank you for your great work. I couldn’t understand the equation you created in the video about the simplified Bellman equation, Q_new = reward + gamma * torch.max(model(next_state)). In this equation, model(nextstate) gives us a probabilistic action prediction. I couldn’t understand why we added one of the action probabilities to the reward. This is totaly different than the Bellman Equation. I would be very happy if someone could explain how the original Bellman equation was simplified in this way. Thanks in advance to everyone.
Been confused for a while with line 59 in model.py -> "torch.argmax(action)".
This is wrong, but your model still learning?) Dunno how that works, but in repo this looks like "torch.argmax(action[idx])"
Hello! Is there a way to save the state of the neural model? So I can load later a trained enemy AI, ready for being the player opponent? Thank you for the video!
So, my array for state is apparently returning NoneType. Anyone know a fix?
I use your code and train it with speed 60000 (just modify the "game.py" file)
Theres no need of waiting a lot of time to train, on the game script you can just change the varaible from 30 to 1000 so snake goes much more fast and trains intself on less time.
The training time is very very long
somoone knows hot to imporve the snake so he does not collide with itself and loop over itself?
Watched the first 4 mins and the game and the learning process is fantastic! 🎉 Will go on it with the rest hopefully soon.
What about using GA to train the NN itself ? Will be a very interesting comparison no?
Arial.ttf is not available.. Please provide the right link
set video speed at x1.25 or x1.5, thank me later.
Grüße aus Deutschland
I think handing the fundamental flaw in the design to others as "homework" is a bit stiff…
You're asking a neural network to solve an NP-Hard problem.
thanks, intresting!
Monotonous.
A video as valuable as a playbook👍🏻👍🏻👍🏻
no windows opened when I ran. not even any errors. how do i fix it?
Is it reinforcement learning even if you give some instructions about the movements?
For who want the anaconda tutorial from author is this link: watch?v=9nEh-OXVaNI