×

Srdjan Susnic's video: AI learns to play Tetris using Machine Learning and Convolutional Neural Network

@AI learns to play Tetris using Machine Learning and Convolutional Neural Network
In this video you'll see how AI learns to play Tetris using Convolutional Neural Network. To play a live demo and learn more on machine learning in this project, visit my blog: https://www.askforgametask.com/tutorial/machine-learning/ai-plays-tetris-with-cnn/ 00:00 - Intro 00:08 - Playing Tetris in 1984 (♥♥♥ special thanks to Toni Susnic ♥♥♥) 00:26 - Playing Tetris in 2020 00:54 - Collecting Data 01:10 - Augmenting Data 01:26 - Building Model 01:39 - Training Model 02:16 - Playing with Trained Model 02:35 - Clearing 4 Rows at once 03:08 - Scoring 999,999 Points 03:22 - Getting Out of a Tricky Situation 04:14 - How Long Can It Survive? 04:21 - The End To simulate a human brain, I used Machine Learning with Convolutional Neural Network. The game is programmed in Javascript using Phaser 2 and TensorFlow.js. ★Dataset ★ To train the network, I needed a high-quality dataset of the various board configurations described by images with corresponding labels where: ● the image is a snapshot of the board. ● the label is an action that represents the final column placement and rotation of a played piece on that board. Here I found a Youtube channel with a lot of Tetris Championship matches. There, all competitors play Tetris at the top level producing a small number of errors. Besides, they aim to score the most points by clearing four rows at once all the time. So these matches are a great resource of high-quality Tetris data! To analyze and collect data from these videos, I made a Tetris Data Scraper tool. Using it, I processed 15 matches, generating around 50,000 records. Unfortunately, that was not enough to train the network. So I made a Data Augmentation tool to artificially expand the dataset by creating modified versions of the original boards. After generating 1,000,000 data records with this tool, I merged all of them into one final 180MB dataset file. Now, I could train the convolutional neural network. ★ Model ★ The architecture of the model used in this game is a simple sequential convolutional neural network. It is consisted of a linear stack of layers with no branching as follows: ● input: 20x20 image of a board configuration ● three convolutional layers ● a flatten layer ● three fully connected layers ● output: one of the 44 possible actions Each action is a combination of the final column position and rotation that must be applied to a piece on the current board configuration. To place a piece on its final position, we need 11 columns. Since each piece has 4 rotations, that is a total of 44 actions (11*4). The model is compiled with these parameters: ● Optimizer: Adam with a learning rate of 0.0005 ● Loss Function: Categorical Crossentropy ● Evaluation Metric: Accuracy ★ Training ★ During the training, the network was showing gradual progress. After 40000 training iterations, the bot began to place pieces in the correct positions and clear the rows continuously. After 75000 iterations, it was playing pretty well. It clears four rows at once and scores more than 999,999 points. It also knows how to get out of some tricky situations most of the time. However, it still makes some funny mistakes and sometimes loses the game very quickly. But generally speaking, it can survive for a long time. ★ Conclusion ★ The goal of this project was to create artificial intelligence that learns to play Tetris using a convolutional neural network. It wasn't an easy task, and the biggest challenge was how to generate a high-quality dataset to train the network. The final result shows that predictions from a trained model are not always 100% accurate, but still quite acceptable to play Tetris pretty well. Due to the variability of the real world, the network doesn't know how to handle all situations. It then makes stupid mistakes that ultimately lead to the loss of the game. More details about making this project, you can find on the official website. The source code will be available on Github as soon as possible. So stay tuned, and don’t forget to like, share, and subscribe. ★ Credits ★ MUSIC 'Euro Pop 80s‘ Jay Man - OurMusicBox http://www.youtube.com/c/ourmusicbox Breaktime by Kevin MacLeod Link: incompetech.filmmusic.io/song/3457-breaktime/ License: https://creativecommons.org/licenses/by/4.0/ Fretless by Kevin MacLeod Link: incompetech.filmmusic.io/song/3777-fretless/ License: https://creativecommons.org/licenses/by/4.0/ ★ Contact ★ Official Website: https://www.askforgametask.com Github: https://github.com/ssusnic/ Facebook: https://www.facebook.com/askforgametask Twitter: https://twitter.com/ssusnic

197

27
Srdjan Susnic
Subscribers
3.3K
Total Post
22
Total Views
878.1K
Avg. Views
39.9K
View Profile
This video was published on 2020-04-03 20:43:02 GMT by @Srdjan-Susnic on Youtube. Srdjan Susnic has total 3.3K subscribers on Youtube and has a total of 22 video.This video has received 197 Likes which are lower than the average likes that Srdjan Susnic gets . @Srdjan-Susnic receives an average views of 39.9K per video on Youtube.This video has received 27 comments which are lower than the average comments that Srdjan Susnic gets . Overall the views for this video was lower than the average for the profile.Srdjan Susnic #MachineLearning #NeuralNetwork #ArtificialIntelligence #MachineLearningAlgorithms #AI #DataScience #Tensorflow #JavaScript has been used frequently in this Post.

Other post by @Srdjan Susnic