Python Pong AI Tutorial - Using NEAT

Поделиться
HTML-код
  • Опубликовано: 20 дек 2024

Комментарии • 124

  • @yubinxie4475
    @yubinxie4475 23 дня назад

    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!

  • @Djellowman
    @Djellowman Год назад +14

    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.

    • @Djellowman
      @Djellowman Год назад +4

      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.

    • @Seedx
      @Seedx Год назад

      @@Djellowmanweird, genetic algorithms are supposed to avoid local minimums. Is the speciation implemented correctly?

  • @Nimnimpac
    @Nimnimpac 2 года назад +4

    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.

    • @HcmfWice
      @HcmfWice 2 года назад

      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.

  • @Apify
    @Apify 2 года назад +9

    Happy to support Tim's videos - keep up the great work! :)

  • @krit6847
    @krit6847 2 года назад +8

    Im addicted to your tutorials, keep it up Tim!

  • @arnavgupta2400
    @arnavgupta2400 Год назад +1

    Thanks!

  • @astrovation3281
    @astrovation3281 2 года назад +7

    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.

  • @ShubhAgarwal__
    @ShubhAgarwal__ 2 года назад +1

    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

  • @jamieharper5665
    @jamieharper5665 Год назад +3

    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 😁

  • @ezb_ai
    @ezb_ai 2 года назад +2

    Liked and subscribed. Thank u so much for the knowledge, kind sir.

  • @goranjosic
    @goranjosic 2 года назад

    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!

  • @samurai-capybara
    @samurai-capybara 2 года назад +2

    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

  • @TomDoesTech
    @TomDoesTech 2 года назад +1

    This is so cool! Awesome tutorial

  • @eitanshpigler8072
    @eitanshpigler8072 2 года назад +2

    Hey Tim, thanks for the great video. Would love to see more cool things with AI and NEAT

  • @lorenzofiore7438
    @lorenzofiore7438 4 месяца назад

    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.

  • @Tafawaq
    @Tafawaq 2 года назад

    Tim is such an amazing teacher , how can i support this channel financially??
    love from syria

  • @mindofpaul9543
    @mindofpaul9543 Год назад

    This was an awesome tutorial and a great way to dip my toes into learning machine learning. Thanks for the video!

  • @HypnosisBear
    @HypnosisBear 2 года назад +1

    Great tutorial Tim.

  • @fhtagn20
    @fhtagn20 2 года назад +3

    Your tutorials have really helped me improve my programming skills Tim in a way I can't put in words. Thank you so much!

  • @gidartsproduction5439
    @gidartsproduction5439 2 года назад

    Thanks for the tutorial, I have been waiting for this...

  • @xGino_n
    @xGino_n 2 года назад

    thank you so much!, was hard to find a cool & easily understandable tutorial.

  • @anthonydawson9700
    @anthonydawson9700 Год назад

    Very good and a lot of hard work! Thanks 🙂

  • @kiat4797
    @kiat4797 2 года назад +1

    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

  • @jeremyheng8573
    @jeremyheng8573 2 года назад

    good explanation! wish to watch more video about reinforcement leaning in python

  • @namashaggarwal7430
    @namashaggarwal7430 2 года назад +7

    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
      @heelercs 2 года назад

      I have a feeling that he won't due to the ethical concerns.

    • @namashaggarwal7430
      @namashaggarwal7430 2 года назад +1

      @@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

    • @heelercs
      @heelercs 2 года назад

      @@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.

    • @namashaggarwal7430
      @namashaggarwal7430 2 года назад

      @@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.

    • @heelercs
      @heelercs 2 года назад

      @@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.

  • @Ta_3-k8n
    @Ta_3-k8n 2 года назад +1

    Thank you so much Tim, this is so valuable, could you make another one on AI plays Snake game that would so helpful.

  • @karlbooklover
    @karlbooklover 2 года назад

    Saw this coming on your GitHub so I activated notifications here 🌚

  • @jantonisito
    @jantonisito 11 месяцев назад

    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.

  • @guillaumerousseau9549
    @guillaumerousseau9549 Год назад

    Impressive work, thanks a lot for sharing this

  • @xucr0516
    @xucr0516 2 года назад +2

    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!

  • @samuelbouhanik1004
    @samuelbouhanik1004 5 месяцев назад

    this is an awesome video, thank man

  • @nobertwekesa8923
    @nobertwekesa8923 2 года назад

    Nice vid. Had to stop everything to watch this👍

  • @Lahmeinthehouse
    @Lahmeinthehouse 2 года назад

    The way you say VIDEO 😂😂 it’s your signature !!

  • @filippostazi4502
    @filippostazi4502 2 года назад

    you are the number one, fantastic video

  • @Global_Reality-bcn
    @Global_Reality-bcn Год назад

    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,

  • @maspot7718
    @maspot7718 2 года назад

    Love the way you explain things

  • @Ghazalli
    @Ghazalli 2 года назад

    Thank you, it was great, please continue the same path and take more NEAT videos for us 👌🏽🙏🏽

  • @teaqllabs6174
    @teaqllabs6174 2 года назад +2

    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

  • @bellpepper_red
    @bellpepper_red Год назад

    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

  • @marcusberge8378
    @marcusberge8378 2 года назад

    Really good video!

  • @drydenstewartenterprises
    @drydenstewartenterprises 2 года назад +9

    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?

    • @ravenblackspike
      @ravenblackspike 2 года назад +1

      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.

    • @hubowenstudent3599
      @hubowenstudent3599 2 года назад

      A great CV model would be YOLOv5

  • @aowowow-no1xe
    @aowowow-no1xe 9 месяцев назад

    Note: You can turn off the pygame drawing to speed things up

  • @hazelNoFake
    @hazelNoFake 2 года назад

    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)

  • @KhazaeeTech
    @KhazaeeTech 2 года назад

    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.👏🏽

  • @Djellowman
    @Djellowman Год назад +1

    Protip for viewers: use multiprocessing to train the model use all your cores in parallel

  • @georgenjeru9627
    @georgenjeru9627 2 года назад

    Daamn,. How did you become so great in programming..?.

  • @babitabarman2582
    @babitabarman2582 2 года назад +1

    Hey Tim when does new time out with Tim podcast comming

  • @lawson1310
    @lawson1310 2 года назад

    Woww, a dream come true 😍

  • @Gunsi-kb2xq
    @Gunsi-kb2xq 2 года назад

    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...

  • @universecode1101
    @universecode1101 2 года назад +1

    Difficult but cool 👍🏻

  • @ChrisJames-tf8yw
    @ChrisJames-tf8yw 8 месяцев назад

    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?

  • @soul-igion7221
    @soul-igion7221 2 года назад

    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.

  • @AlexDevQa
    @AlexDevQa 2 года назад

    Tim - the best!

  • @manfredsteyn
    @manfredsteyn 2 года назад

    Fantastic work. Impeccable teaching abilities. Learning a lot from your videos. Thank You!

  • @online.python.dersim
    @online.python.dersim Год назад

    thanks clear explanation

  • @ethitlan
    @ethitlan 2 года назад +3

    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?

    • @Djellowman
      @Djellowman Год назад

      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.

    • @Djellowman
      @Djellowman Год назад

      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.

    • @ethitlan
      @ethitlan Год назад +1

      @@Djellowman oooh then perhaps my tickrate was different. Thanks for answering Tim!

  • @iancardona3719
    @iancardona3719 Год назад

    amazing tutorial tim! tho i'm having trouble why am I getting negative values in my population average fitness; what could be the problem?

  • @frosbee6344
    @frosbee6344 2 года назад

    Hi thanks for your work. Can This also work in Jupiter notebook?

  • @ninek1902
    @ninek1902 2 года назад

    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...

    • @mmdrlolfr2612
      @mmdrlolfr2612 2 года назад

      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.

  • @0Clappy
    @0Clappy 2 года назад

    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.

  • @0Clappy
    @0Clappy 2 года назад

    What program are you using to draw?

  • @nicom9853
    @nicom9853 2 года назад

    Huh, very interesting! I'm guessing this can be used on any kind of supervised learning as well?

  • @danilotrix
    @danilotrix 2 года назад

    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

    • @NinjaTxGaming
      @NinjaTxGaming 2 года назад +1

      Reward is the fitness variable. Tim set the reward to the number of balls hit in total throughout all the games.

    • @Djellowman
      @Djellowman Год назад

      it's not reinforcement learning

  • @reyhane2266
    @reyhane2266 6 месяцев назад

    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?

  • @MachineLearner-p7k
    @MachineLearner-p7k 4 месяца назад

    Can anybody tell me whether this will be good project that to be kept in our resume ??

  • @BentleyKingToebeansOwenRhett
    @BentleyKingToebeansOwenRhett 5 месяцев назад

    Pretty neat

  • @FireFly969
    @FireFly969 2 года назад

    Thank you

  • @tcgvsocg1458
    @tcgvsocg1458 2 года назад

    You hav to show how can remove ia for player to play against and generate differente type of ia (norma,l hard, easy

  • @TheTheuhh
    @TheTheuhh 2 года назад

    Can you teach us how to create a forum website?

  • @nobbytho
    @nobbytho 2 года назад

    your flappy bird video is taken down?

  • @Kennethlumor
    @Kennethlumor 2 года назад

    Please and please I request you make video on how to use multiple databases in flask

  • @leonardsmith9870
    @leonardsmith9870 2 года назад +2

    Wow, this is neat! Lol.

  • @visiblecode5238
    @visiblecode5238 2 года назад +1

    Nice

    • @visiblecode5238
      @visiblecode5238 2 года назад

      @♜ Pinned by Tech With Tim shut up bot

  • @___OmerAJ___
    @___OmerAJ___ Год назад +1

    ❤❤❤

  • @stefanlin5086
    @stefanlin5086 2 года назад

    whn I run test_ai the ai dosent move at all

    • @stefanlin5086
      @stefanlin5086 2 года назад

      @♜ Pinned by Tech With Tim dont worry got it fixed

  • @PP-tc1zp
    @PP-tc1zp 2 года назад

    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 ;)

  • @SkyFly19853
    @SkyFly19853 2 года назад

    How about A.I. tutorial for chess game in Python?

  • @mayman8415
    @mayman8415 2 года назад

    pls make a vid on burnout

  • @rayankhan12
    @rayankhan12 2 года назад

    Thanks 😊 :) (I was wondering if it's possible to write a Python code that would automatically send birthday messages to my WhatsApp contacts?)

  • @pravachanpatra4012
    @pravachanpatra4012 2 года назад

    1:05:00

  • @karma_senpai
    @karma_senpai 2 года назад

    Most of The People get bored when doing there favorites thing sometimes. I have a question that did you get bored doing programming sometimes.

  • @gzbin365
    @gzbin365 2 года назад

    cool!

  • @ElPsyVega
    @ElPsyVega Год назад

    17:20 hehe

  • @MnM_rulz
    @MnM_rulz 2 года назад

    Hey Tim, can you please teach how to download dlib and face_recognitiom PLEASE. Thank you

    • @MnM_rulz
      @MnM_rulz 2 года назад

      Please teach how to download face recognition

  • @codesaif8075
    @codesaif8075 2 года назад

    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?

  • @BlhJ400
    @BlhJ400 2 года назад

    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

  • @sintax9286
    @sintax9286 2 года назад

    holy shitfuck, this is amazing * _ *

  • @lrnzdc7199
    @lrnzdc7199 2 года назад

    Please make a video on licenses, no one talks about them! There isn't a decent video to watch.

  • @karamsabbagh7465
    @karamsabbagh7465 2 года назад +1

    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
      @TechWithTim  2 года назад +1

      To learn how to train ais to play games and examine the behaviour!

    • @karamsabbagh7465
      @karamsabbagh7465 2 года назад +1

      @@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).

  • @DGHere12
    @DGHere12 2 года назад

    second

  • @coolguy7160
    @coolguy7160 2 года назад

    10th comment

  • @shalevforfor5550
    @shalevforfor5550 9 месяцев назад

    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

    • @xidiffiyt7986
      @xidiffiyt7986 6 месяцев назад

      this is just about learning how to use ai

  • @walney2008
    @walney2008 Год назад

    please speak IA play game chess

  • @PP-tc1zp
    @PP-tc1zp 2 года назад

    Booster to improve performance, mutch faster: for genome_id2, genome2 in genomes[random.randrange(i+1):]:

  • @adityaraina7727
    @adityaraina7727 Год назад

    Thanks!

  • @shalevforfor5550
    @shalevforfor5550 9 месяцев назад

    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