Although I must agree the topic discussed here is not beginner friendly, the way you explained a lot of the details and even went back one point to reiterate what you wrote for the train ai script was extremely well done. Thank you for the tutorial!
To those implementing this: you will need the x and y velocity of the ball too if you use a ball speedup-mechanic (like i do) where the ball moves faster than the paddles. then it's not enough to simply keep the paddle y the same as the ball y, you need the velocity so it can predict where the ball will go.
Coming back to this, it turns out genetic algorithms get stuck in a local minimum, with absolutely no way to get out of it. This minimum means that the model only learns to keep the paddle at the same height as the ball... So it's seemingly impossible to train a competent AI for Pong using a genetic algorithm if the above strategy stops working once the ball speeds up. Perhaps reinforcement learning would work, but i don't see how that would get out of the same local minimum.
If I am correct in around 49:50 you lower later genomes fitness. Lets say we have 3 genomes. We set genome1 fitness to 0 in first for loop then in second for loop test it against genome2 and genome3. After this genome1 has fitness 10, genome2 fitness 4 and genome3 fitness 6. The we go to genome2 and set it fitness to 0 but due to second for loop " in genomes[i+1:]" genome2 wont play against genome1 now only against genome3 so it will have lower fitness.
Yeah, I’ve noticed this as well. Also, genome1 only plays on the left side (and the last genome only plays on the right), while all the other genomes play on both side. A simple fix would be to iterate over the whole range in both the outer and inner loop, and in the inner loop make sure that the two IDs are different (if you don’t want the genomes to play against themselves). It really says something about the robustness of evolutionary genetic algorythms that it still produced a genome that plays well.
Bro I was looking some tutorial to make a pong ai using python at 2 days later ur video is here love it and don't know how you know what the views want thnx alot
Amazing video thank you! Had an issue with the data printing but then realised I was just being impatient and needed to wait lol. I can't tell you how useful this was as an introduction to neural networks for me 😁
I'm working on my first NEAT AI project, and this tutorial is very helpful because the documentation is quite scarce. Before this video, I watched a NEAT AI video by sentdex channel, and it's quite bad compared to this one - his video is literally a copied example from the documentation, without any new explanations - it's just not worth watching, it's better to read the documentation, than to watch his video - my experience. Overall, good tutorial!
Love your videos! I'm going to use what I've learned from this and your Flappy Birds series to build an AI for a 2D fighting game.... taking me one step closer to Skynet
Just finished the video. I can't wait to actually start writing some code. Firstly on pong and next on some random game i'll find. The cool part about neural networks is that they do all of the hard work for you by optimizing the output without knowing what it is going to be used for. They just adjust weights and biases waiting for a treat 😂. Unfortunally for genetic algorithms they are going to die without being rewarded 😢😂. Thank you for the video.
love ur videos tim . i have been Following u for a long time ( probably 3 years ). i love how u're explaining various concepts clearly and smoothly and i would love to see u creating a ray casting engine or ray tracing engine in pygame . a lot of fun math ( linear algebra , geometry ... ) and some cool physics concepts to discover while coding it
Awesome video, Could you please make a series of DeepFakes technology using Python from beginner to Advanced with all concepts and it's mechanism. Thanks alot, I follow all your videos and really appreciate your hard work. 加油 ❤️
@@heelercs don't know man, but this technology is kinda cool and futuristic. If we could master it and combine with the 3D modelling and printing to create human looking AI robots, then the world could turn into a Terminator
@@namashaggarwal7430 Agreed, it is really cool technology. Unfortunately it's almost always seen as a harmful technology (for now). I doubt Tech With Tim would want to publicly associate with something that's almost always associated with pornography.
@@heelercs every technology in the world has 2 sides , one is positive and second is negative. To exemplify, nuclear technology can be used for destruction of a nation using nuclear bomb but on the other side, the same thing can be used as an excellent carbonless energy source for the construction of the humankind. We must need to make certain rules and protocols for each and everything to keep a positive balance. It all depends on us, how we make use of it.
@@namashaggarwal7430 I never disagreed with that. However, just because two sides exist doesn't mean they hold equal weight. To use your own example, surely you don't think that the positives and negatives of nuclear bomb technology is equal? There's definitely much more potential negative harm than positive harm. Since we're going to extremes, gas chambers are another example. Surely you don't think the positive and negative are equivalent, right? So my point still stands.
Maybe you could do part to and analyze how those NNs evolve. The key point for me was that some randomly generated set of connections will produce some output (three numbers) . We CHOOSE to interpret these numbers as movement of the paddles - order of stay/up/down is arbitrary. Once we chose some interpretation we apply it to paddle movements and we asses if given NN (given genome) actually makes good decisions (is more fit). What is completely elusive for me is how they make a decision to merge network topologies - without some actual analysis what changes in structure could be responsible for performance improvement - how do you pick up what to merge? Either way very good tutorial - thanks! PS. If your generation runs slow definitely turn of screen rendition during training - program runs ~30 times faster. Also I found out that limiting exchanges (hits) to less than a suggested 100 speeds up hitting the target fitness. With 70 limit I hit 430 fitness in 18 generations.
Thank you a lot Tim, I really appreciate your work, the way you explain is phenomenal, I am a fan of your programming videos please keep them coming. kind regards,
Hi Tim! My name is Ian and I am a 16 year old developer, right now I am working on a compiled multipurpose programming language from scratch in C and I was wondering if you could maybe check it out. That would really make my whole day. But if not, I totally understand. -Ian
Hey Tim, Thanks for the video! I was wondering though, because you used NEAT with flappy bird, and now with pong, is neat used just for games? I've been learning Python through you and Sentex and neuralnines videos for the past 2 years and I have learned a lot but I still have a long way to go, I am interested in building some of my own small robots and I am wondering if you would ever work on a series about incorporating computer vision with a voice assistant and some form of AI (maybe neat?) so my little robots can recognize objects and people, and tell you that it has recognized those objects or people?
NEAT would probably not be useful in that particular use case. You would be better served by a couple of discrete models with code that passes your inputs to the models. Something like the below. 1) Computer Vision model for object recognition. 2) Speach recognition model, TTS model for the voice commands and output. 3) Whatever code you would need to handle moving the robot/passing inputs to your models.
The video was very useful. Please use neat more in the videos. I watch almost all of your videos, but AI is very useful. Please provide a complete neat tutorial.👏🏽
Awesome video. Now can the AI be created that moves the ball x,y position. The future should be code-less apps. I want to try make a Python training that would make the AI generate the ball x,y coordinates for the game. But could this be done without coding as well? Could an AI be trained to watch a pong game and then be used to train the AI to control the ball x,y?
So, I am a neophyte for Pycharm & Tensorflow ,,, May i please be provided with "Tutorial videos on how to run models in "PYCHARM" which are listed on Tensorflow website. I tried to run Image Classification Model but it's running till "Visualize Training Results" in PYCHARM & after that it's not showing any result for "Overfitting, DataAugmentaion, And Code parts". I tried to search but didn't found any relevant result for issue. If this doubt is not clear to me , I can't start my Tensorflow Developer Certificate Exam.
Hey Tim, I have a question. Does the frame rate you train it with affect its performance? I've been training it with no frame rate cap for a long a time until I played against it and it wasn't as good as I hoped. So then I changed the frame rate and (although it was humanly impossible for me to play the game) the AI did MUCH better at receiving the ball. What do you think?
good question. yes it does affect the performance, as it gets more input and actions per second if you have a higher tickrate. But i'm surprised to hear it's a big difference.
actually, if your tickrate is tied to the framerate, it shouldn't matter. It means the game speeds up as your tickrate increases. So actually, no it should be identical during training and playing against you.
Hey Tim, I have a question about the oscilating best fitnesses... How is it possible for best fitness to drop in comparison to last generation if there is elitism involved? In your config the elitism parameter is set to 2, which means 2 of the most fit individuals from each species will get pasted in the next generation (according to neat-python docs), thus the algorithm is not supposed to score lower than their previous score...
I think it's because if the first genome gets a mutation, his fitness can decrease and if nobody has exceeded the previous best fitness, the global fitness will just decrease. Or maybe it's because the first direction of the ball in pong in random and maybe the first genome got an extremely good luck and that didn't happen later.
Please update the code on Github to the finalized file, I attempted to follow along step by step but too many errors occurred and I ended up with a frankenstein mashup of code.
This was amazing. Thanks so much. 1 question. What about rewards? You didn’t mention it or I missed it. How do they learn the right movement to do? Thanks
I've been trying to implement this, so far I've had 197 generations ran and the best fitness till now was 23, is this normal? is it supposed to take that long?
Hi, thank you. It is very interesting. I made simple modification wchich allow play with player and check ai in 1 game session with dynamic switch between player and ai. If you want I can put this on github. So who is better you or ai ;)
Hey Tim, Can you Explain how can i make logic in programming?, like when i start wrting code i have no idea what to write in first line i get so confused, How do you do it?, how can be good in coding like you?
Hey thanks so much for the informations, I am just wandering JavaScript or python ? Someone says python slow others says it has many libraries but I don't get it . Everything is confusing and there's no clear path to start, I really want your help, thanks 🙏 you are the best
What's the point of making an AI for ping pong for this kind of games you van just make a simple bot that's impossible to loose and it's faster, easier, no need to wait the AI to learn, You can simply make the paddle follow the y position of the ball and you can make some modernization and let it predict the ball balance of the walls and here you go easy and so simple !
@@TechWithTim Ah yeah got it but I think working on a harder game would be good and reasonable like if I saw your AI I would think it like a simple bot. But anyways I got it you want to start easy and learn then make something reasonable. And btw I really think that making an AI for snake is really good for multiple reasons (because making a snake AI with a snake(Python) is great XD).
Just make a bot . You have a ball and make another one that go faster then him or a line that go and just when the second ball is > then the bot x so then just move to he's y no need an AI for this
Just make a bot . You have a ball and make another one that go faster then him or a line that go and just when the second ball is > then the bot x so then just move to he's y no need an AI for this
Although I must agree the topic discussed here is not beginner friendly, the way you explained a lot of the details and even went back one point to reiterate what you wrote for the train ai script was extremely well done. Thank you for the tutorial!
To those implementing this: you will need the x and y velocity of the ball too if you use a ball speedup-mechanic (like i do) where the ball moves faster than the paddles. then it's not enough to simply keep the paddle y the same as the ball y, you need the velocity so it can predict where the ball will go.
Coming back to this, it turns out genetic algorithms get stuck in a local minimum, with absolutely no way to get out of it. This minimum means that the model only learns to keep the paddle at the same height as the ball... So it's seemingly impossible to train a competent AI for Pong using a genetic algorithm if the above strategy stops working once the ball speeds up. Perhaps reinforcement learning would work, but i don't see how that would get out of the same local minimum.
@@Djellowmanweird, genetic algorithms are supposed to avoid local minimums. Is the speciation implemented correctly?
If I am correct in around 49:50 you lower later genomes fitness. Lets say we have 3 genomes. We set genome1 fitness to 0 in first for loop then in second for loop test it against genome2 and genome3. After this genome1 has fitness 10, genome2 fitness 4 and genome3 fitness 6. The we go to genome2 and set it fitness to 0 but due to second for loop " in genomes[i+1:]" genome2 wont play against genome1 now only against genome3 so it will have lower fitness.
Yeah, I’ve noticed this as well. Also, genome1 only plays on the left side (and the last genome only plays on the right), while all the other genomes play on both side. A simple fix would be to iterate over the whole range in both the outer and inner loop, and in the inner loop make sure that the two IDs are different (if you don’t want the genomes to play against themselves).
It really says something about the robustness of evolutionary genetic algorythms that it still produced a genome that plays well.
Happy to support Tim's videos - keep up the great work! :)
Im addicted to your tutorials, keep it up Tim!
Sammeee
Thanks!
Thank you so much! I've never done anything with AI before, so even if this is hard for me it'll probably be very educational.
Bro I was looking some tutorial to make a pong ai using python at 2 days later ur video is here love it and don't know how you know what the views want thnx alot
Amazing video thank you! Had an issue with the data printing but then realised I was just being impatient and needed to wait lol. I can't tell you how useful this was as an introduction to neural networks for me 😁
Liked and subscribed. Thank u so much for the knowledge, kind sir.
I'm working on my first NEAT AI project, and this tutorial is very helpful because the documentation is quite scarce.
Before this video, I watched a NEAT AI video by sentdex channel, and it's quite bad compared to this one - his video is literally a copied example from the documentation, without any new explanations - it's just not worth watching, it's better to read the documentation, than to watch his video - my experience.
Overall, good tutorial!
Love your videos! I'm going to use what I've learned from this and your Flappy Birds series to build an AI for a 2D fighting game.... taking me one step closer to Skynet
This is so cool! Awesome tutorial
Hey Tim, thanks for the great video. Would love to see more cool things with AI and NEAT
Just finished the video. I can't wait to actually start writing some code. Firstly on pong and next on some random game i'll find. The cool part about neural networks is that they do all of the hard work for you by optimizing the output without knowing what it is going to be used for. They just adjust weights and biases waiting for a treat 😂. Unfortunally for genetic algorithms they are going to die without being rewarded 😢😂. Thank you for the video.
Tim is such an amazing teacher , how can i support this channel financially??
love from syria
This was an awesome tutorial and a great way to dip my toes into learning machine learning. Thanks for the video!
Great tutorial Tim.
Your tutorials have really helped me improve my programming skills Tim in a way I can't put in words. Thank you so much!
Thanks for the tutorial, I have been waiting for this...
thank you so much!, was hard to find a cool & easily understandable tutorial.
Very good and a lot of hard work! Thanks 🙂
love ur videos tim . i have been Following u for a long time ( probably 3 years ). i love how u're explaining various concepts clearly and smoothly and i would love to see u creating a ray casting engine or ray tracing engine in pygame . a lot of fun math ( linear algebra , geometry ... ) and some cool physics concepts to discover while coding it
good explanation! wish to watch more video about reinforcement leaning in python
Awesome video,
Could you please make a series of DeepFakes technology using Python from beginner to Advanced with all concepts and it's mechanism.
Thanks alot, I follow all your videos and really appreciate your hard work. 加油 ❤️
I have a feeling that he won't due to the ethical concerns.
@@heelercs don't know man, but this technology is kinda cool and futuristic. If we could master it and combine with the 3D modelling and printing to create human looking AI robots, then the world could turn into a Terminator
@@namashaggarwal7430 Agreed, it is really cool technology. Unfortunately it's almost always seen as a harmful technology (for now). I doubt Tech With Tim would want to publicly associate with something that's almost always associated with pornography.
@@heelercs every technology in the world has 2 sides , one is positive and second is negative. To exemplify, nuclear technology can be used for destruction of a nation using nuclear bomb but on the other side, the same thing can be used as an excellent carbonless energy source for the construction of the humankind. We must need to make certain rules and protocols for each and everything to keep a positive balance. It all depends on us, how we make use of it.
@@namashaggarwal7430 I never disagreed with that. However, just because two sides exist doesn't mean they hold equal weight. To use your own example, surely you don't think that the positives and negatives of nuclear bomb technology is equal? There's definitely much more potential negative harm than positive harm. Since we're going to extremes, gas chambers are another example. Surely you don't think the positive and negative are equivalent, right?
So my point still stands.
Thank you so much Tim, this is so valuable, could you make another one on AI plays Snake game that would so helpful.
Saw this coming on your GitHub so I activated notifications here 🌚
Maybe you could do part to and analyze how those NNs evolve. The key point for me was that some randomly generated set of connections will produce some output (three numbers) . We CHOOSE to interpret these numbers as movement of the paddles - order of stay/up/down is arbitrary. Once we chose some interpretation we apply it to paddle movements and we asses if given NN (given genome) actually makes good decisions (is more fit). What is completely elusive for me is how they make a decision to merge network topologies - without some actual analysis what changes in structure could be responsible for performance improvement - how do you pick up what to merge? Either way very good tutorial - thanks!
PS. If your generation runs slow definitely turn of screen rendition during training - program runs ~30 times faster. Also I found out that limiting exchanges (hits) to less than a suggested 100 speeds up hitting the target fitness. With 70 limit I hit 430 fitness in 18 generations.
Impressive work, thanks a lot for sharing this
Love ur vids. Because of you i am getting better and better in python. I just started like 5 days ago and i made an own made command prompt!
Rly
@Shinero Oh man
this is an awesome video, thank man
Nice vid. Had to stop everything to watch this👍
The way you say VIDEO 😂😂 it’s your signature !!
you are the number one, fantastic video
Thank you a lot Tim, I really appreciate your work, the way you explain is phenomenal, I am a fan of your programming videos please keep them coming. kind regards,
Love the way you explain things
Thank you, it was great, please continue the same path and take more NEAT videos for us 👌🏽🙏🏽
Hi Tim! My name is Ian and I am a 16 year old developer, right now I am working on a compiled multipurpose programming language from scratch in C and I was wondering if you could maybe check it out.
That would really make my whole day.
But if not, I totally understand.
-Ian
thanks for the epic project Tim! I had 0 knowledge of ML but I still had fun following along, and learned many things on the way.
Knowledge_of_ML +=1
Really good video!
Hey Tim, Thanks for the video! I was wondering though, because you used NEAT with flappy bird, and now with pong, is neat used just for games? I've been learning Python through you and Sentex and neuralnines videos for the past 2 years and I have learned a lot but I still have a long way to go, I am interested in building some of my own small robots and I am wondering if you would ever work on a series about incorporating computer vision with a voice assistant and some form of AI (maybe neat?) so my little robots can recognize objects and people, and tell you that it has recognized those objects or people?
NEAT would probably not be useful in that particular use case.
You would be better served by a couple of discrete models with code that passes your inputs to the models. Something like the below.
1) Computer Vision model for object recognition.
2) Speach recognition model, TTS model for the voice commands and output.
3) Whatever code you would need to handle moving the robot/passing inputs to your models.
A great CV model would be YOLOv5
Note: You can turn off the pygame drawing to speed things up
I am not going to do some beginner coder stuff. I'm jumping right into this (like people who jump from an easy demon to an extreme demon)
The video was very useful. Please use neat more in the videos. I watch almost all of your videos, but AI is very useful. Please provide a complete neat tutorial.👏🏽
Protip for viewers: use multiprocessing to train the model use all your cores in parallel
Using
Daamn,. How did you become so great in programming..?.
Hey Tim when does new time out with Tim podcast comming
Woww, a dream come true 😍
for me it creates only 1 ID per generation... is this OK? Tried your code as well but aways only 1 ID after every generation...
Difficult but cool 👍🏻
Awesome video. Now can the AI be created that moves the ball x,y position. The future should be code-less apps. I want to try make a Python training that would make the AI generate the ball x,y coordinates for the game. But could this be done without coding as well? Could an AI be trained to watch a pong game and then be used to train the AI to control the ball x,y?
So, I am a neophyte for Pycharm & Tensorflow ,,,
May i please be provided with "Tutorial videos on how to run models in "PYCHARM" which are listed on Tensorflow website.
I tried to run Image Classification Model but it's running till "Visualize Training Results" in PYCHARM & after that it's not showing any result for "Overfitting, DataAugmentaion, And Code parts". I tried to search but didn't found any relevant result for issue.
If this doubt is not clear to me , I can't start my Tensorflow Developer Certificate Exam.
Tim - the best!
Fantastic work. Impeccable teaching abilities. Learning a lot from your videos. Thank You!
thanks clear explanation
Hey Tim, I have a question. Does the frame rate you train it with affect its performance? I've been training it with no frame rate cap for a long a time until I played against it and it wasn't as good as I hoped. So then I changed the frame rate and (although it was humanly impossible for me to play the game) the AI did MUCH better at receiving the ball. What do you think?
good question. yes it does affect the performance, as it gets more input and actions per second if you have a higher tickrate. But i'm surprised to hear it's a big difference.
actually, if your tickrate is tied to the framerate, it shouldn't matter. It means the game speeds up as your tickrate increases. So actually, no it should be identical during training and playing against you.
@@Djellowman oooh then perhaps my tickrate was different. Thanks for answering Tim!
amazing tutorial tim! tho i'm having trouble why am I getting negative values in my population average fitness; what could be the problem?
Hi thanks for your work. Can This also work in Jupiter notebook?
Hey Tim, I have a question about the oscilating best fitnesses...
How is it possible for best fitness to drop in comparison to last generation if there is elitism involved?
In your config the elitism parameter is set to 2, which means 2 of the most fit individuals from each species will get pasted in the next generation (according to neat-python docs), thus the algorithm is not supposed to score lower than their previous score...
I think it's because if the first genome gets a mutation, his fitness can decrease and if nobody has exceeded the previous best fitness, the global fitness will just decrease. Or maybe it's because the first direction of the ball in pong in random and maybe the first genome got an extremely good luck and that didn't happen later.
Please update the code on Github to the finalized file, I attempted to follow along step by step but too many errors occurred and I ended up with a frankenstein mashup of code.
What program are you using to draw?
Huh, very interesting! I'm guessing this can be used on any kind of supervised learning as well?
This was amazing. Thanks so much.
1 question. What about rewards? You didn’t mention it or I missed it. How do they learn the right movement to do? Thanks
Reward is the fitness variable. Tim set the reward to the number of balls hit in total throughout all the games.
it's not reinforcement learning
I've been trying to implement this, so far I've had 197 generations ran and the best fitness till now was 23, is this normal? is it supposed to take that long?
Can anybody tell me whether this will be good project that to be kept in our resume ??
Pretty neat
Thank you
You hav to show how can remove ia for player to play against and generate differente type of ia (norma,l hard, easy
Can you teach us how to create a forum website?
your flappy bird video is taken down?
Please and please I request you make video on how to use multiple databases in flask
Wow, this is neat! Lol.
Nice
@♜ Pinned by Tech With Tim shut up bot
❤❤❤
whn I run test_ai the ai dosent move at all
@♜ Pinned by Tech With Tim dont worry got it fixed
Hi, thank you.
It is very interesting. I made simple modification wchich allow play with player and check ai in 1 game session with dynamic switch between player and ai. If you want I can put this on github. So who is better you or ai ;)
How about A.I. tutorial for chess game in Python?
pls make a vid on burnout
Thanks 😊 :) (I was wondering if it's possible to write a Python code that would automatically send birthday messages to my WhatsApp contacts?)
1:05:00
Most of The People get bored when doing there favorites thing sometimes. I have a question that did you get bored doing programming sometimes.
cool!
17:20 hehe
Hey Tim, can you please teach how to download dlib and face_recognitiom PLEASE. Thank you
Please teach how to download face recognition
Hey Tim, Can you Explain how can i make logic in programming?, like when i start wrting code i have no idea what to write in first line i get so confused, How do you do it?, how can be good in coding like you?
Hey thanks so much for the informations, I am just wandering JavaScript or python ?
Someone says python slow others says it has many libraries but I don't get it . Everything is confusing and there's no clear path to start, I really want your help, thanks 🙏 you are the best
holy shitfuck, this is amazing * _ *
Please make a video on licenses, no one talks about them! There isn't a decent video to watch.
What's the point of making an AI for ping pong for this kind of games you van just make a simple bot that's impossible to loose and it's faster, easier, no need to wait the AI to learn,
You can simply make the paddle follow the y position of the ball and you can make some modernization and let it predict the ball balance of the walls and here you go easy and so simple !
To learn how to train ais to play games and examine the behaviour!
@@TechWithTim
Ah yeah got it but I think working on a harder game would be good and reasonable like if I saw your AI I would think it like a simple bot.
But anyways I got it you want to start easy and learn then make something reasonable.
And btw I really think that making an AI for snake is really good for multiple reasons (because making a snake AI with a snake(Python) is great XD).
second
10th comment
Just make a bot . You have a ball and make another one that go faster then him or a line that go and just when the second ball is > then the bot x so then just move to he's y no need an AI for this
this is just about learning how to use ai
please speak IA play game chess
Booster to improve performance, mutch faster: for genome_id2, genome2 in genomes[random.randrange(i+1):]:
Thanks!
Just make a bot . You have a ball and make another one that go faster then him or a line that go and just when the second ball is > then the bot x so then just move to he's y no need an AI for this