Тёмный

🚗 Neural Networks and Genetic Algorithms for a Self Driving Car in Unity [Part 3/3] 🚗 

AJTech
Подписаться 8 тыс.
Просмотров 11 тыс.
50% 1

PROJECT FILES (PLUGINS & COURSE) :
☢ github.com/AJTech2002/Self-Dr...
Also, if you want save functionality and are noticing some errors our very helpful commentors have solved these issues down below! Thank you all for the combined effort to make this an even more valuable resource to people who are learning.
A fully self driving car in Unity from scratch using Neural Networks and Genetic Algorithms! Yes I said from scratch, we will be coding everything ourselves so that you can understand from the base up how everything works. I have been working on this video for quite a while to make it the best I can for you ❤ Of course you can apply all of these concepts and techniques into your own games, research and simulations.
* NEWS : Welcome to the community!! I want to congratulate everyone on reaching 2500 subscribers, this is a collective accomplishment and I thank you all for your support. *
I'm glad that I have been able to catchup and complete the series without any delay from the episode, hopefully this has been useful to everyone that has watched it. Be sure to improve upon it, share your results and if you need any help please be sure to drop a comment and I'll get back to you as soon as possible.
----- LETS TRY AND HIT : 25 LIKES ✌ ---------
★ Upcoming Videos :
- Open World Series Part 5 ❤
✄ LINKS MENTIONED IN VIDEO ✄ :
GENETIC ALGORITHM RESOURCES
☢ blog.sicara.com/getting-start...
FEED FORWARD NEURAL NETWORK RESOURCES
☢ towardsdatascience.com/a-gent...
NEAT ALGORITHM
☢ towardsdatascience.com/neat-a...
MATRIX MATH
☢ en.wikipedia.org/wiki/Matrix_...
☁ In this video we begin our journey by creating the first of the three scripts, the Car Controller which is a script that provides the inputs to the neural networks, calculates the fitness function for the genetic algorithm and does the most important job of moving the car itself.
◕‿◕ The next part is even better and in order for you to see it you have to subscribe and tap that bell icon to be notified :
►► ru-vid.com_... ◄◄
☾ Stay tuned for the next episode, I will be releasing new videos once every 5 to 6 weeks discussing what I have done over the course of the weeks, always giving you some good entertainment with some knowledge on how you can tackle complex challenges in your own games! (◕‿-)
I'll see you next time ✌
✄ IMPORTANT LINKS YOU SHOULD CHECK OUT ✄ :
DEV LOG PART 1
☢ • Video
DEV LOG PART 2
☢ • Video
DEV LOG PART 3
☢ • Video
CUSTOM CHARACTER CONTROLLER TUTORIAL
☢ • (01) Stealth Game - Cu...
INVERSE KINEMATICS SERIES
☢ • (05) Stealth Game - In...
♬ MUSIC ♬ :
☮ Wayr - Follow the light
► CORE VIDEOS ►:
✌ WOW Trailer
If any of these videos or music belong to you and you wish for them to be taken down, please email me at : ajays.workemail@gmail.com
Thank you, for watching guys :)

Хобби

Опубликовано:

 

3 янв 2020

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 107   
@DanRasmussen72
@DanRasmussen72 4 года назад
Saving network to JSON files. Install Newtonsoft.JSON Nuget package and add using in NNet class: Then something like this... public void SaveNetwork() { string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); if (!System.IO.Directory.Exists(path + "\\SavedBrains")) { Directory.CreateDirectory(path + "\\SavedBrains"); } path = path + "\\SavedBrains"; string ID = DateTime.Now.Ticks.ToString(); string json = JsonConvert.SerializeObject(inputLayer.ToArray()); File.WriteAllText(path + "\\inputLayer_" + ID + ".txt", json); json = JsonConvert.SerializeObject(hiddenLayers.ToArray()); File.WriteAllText(path + "\\hiddenLayers_" + ID + ".txt", json); json = JsonConvert.SerializeObject(outputLayer.ToArray()); File.WriteAllText(path + "\\outputLayers_" + ID + ".txt", json); json = JsonConvert.SerializeObject(weights.ToArray()); File.WriteAllText(path + "\\weights_" + ID + ".txt", json); json = JsonConvert.SerializeObject(biases.ToArray()); File.WriteAllText(path + "\\biases_" + ID + ".txt", json); }
@batchprogrammer108
@batchprogrammer108 4 года назад
Awesome! Just saved me creating another video for this, I'll pin this comment so anyone looking to save their networks can :) Thank you sir.
@DanRasmussen72
@DanRasmussen72 4 года назад
@@batchprogrammer108 No problem, I'll do a save of networks when quitting game and load of saved when starting also... Been working on sound and spheres for extra fitness point along my track. New to Unity, but been coding business software for 23 years, time to play around with this :)
@DanRasmussen72
@DanRasmussen72 4 года назад
ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-XHqubiHkYbA.html
@DanRasmussen72
@DanRasmussen72 4 года назад
@@batchprogrammer108 Wow, loading values back is much harder! :) I'll have a go at it later, but
@batchprogrammer108
@batchprogrammer108 4 года назад
@@DanRasmussen72 Yeah I thought it would be difficult, hope you figure it out and then if you can send us all a github link I'm sure everyone would appreciate it :)
@generalis2095
@generalis2095 2 года назад
Following your tutorial and coding my own neural network is a life changing experience. Thank you.
@chor6422
@chor6422 4 года назад
Can you do a tutorial of how to use multiple "agents" for faster training?
@hoapham7389
@hoapham7389 4 года назад
I thought you stopped!! your tutorials are so good!
@batchprogrammer108
@batchprogrammer108 4 года назад
Nah just took a break, thank you very much! : )
@tomtomkowski7653
@tomtomkowski7653 2 года назад
This was a great series! Bravo! But... A couple of mistakes is made if you read this in the future. - NNet shouldn't inherit from Monobehaviour - just create it via a new keyword there is no point in adding this as a component. - Sorting bubble is wrong - is sorting with ascending order so to the next generation dumbest are taken. Just replace whole this class with one line of code using Linq: population = population.OrderByDescending(x => x.fitness).ToArray(); - there is no point to add dumbest (worst) to the genePool- remove this. - increase the number of smartest going through or add an if fitnes is > 80% of bestscore under index[0]) then add it as more and more smart cars you will have in population - leave intact cars only couple of cars or all cars with perfect score (or is needed as this might be a situation no car is perfect at the beginning ,of course) - with all of these above you will see (printing out pthe opulation.fitness) that every next population is smarter and smarter. - remove this whole copy loops by just creating a list with a constructor. NNet n = new (); n.weights = new(weights); n.biases = new(biases); - remove Math.Tanhf - you already did it in this class for turning return (Sigmoid(outputLayer[0, 0]), outputLayer[0, 1]); - replace all [xxx.count -1] with [^1] notation. Instead for example weights[weights.count -1] just use weights[^1] - with looping 100x times you cannot be sure child1 != child2. Replace this with AIndex = randomnumber; do{BIndex= random number;} while(AIndex == BIndex); - then you will be 100% sure they won't be the same.
@TheTechpreneurs
@TheTechpreneurs 4 года назад
Yeh... Was Eagerly waiting for this🏆🏆🏆
@batchprogrammer108
@batchprogrammer108 4 года назад
Sorry about the wait, hope you enjoy :)
@julianrockl4228
@julianrockl4228 4 года назад
Thank you for your Video and your work. Learned very much!
@batchprogrammer108
@batchprogrammer108 4 года назад
Thanks so much for the compliments, I'm glad you enjoyed! :D
@outerstudios830
@outerstudios830 4 года назад
You are a real inspiration Amazing!!! I am also creating devlogs for my 2d open world game cant to see how your open world game is going!!!
@moneodev
@moneodev Год назад
Hi could you still please make a video on saving and loading the neural network? I couldn't get it to work for me😅
@noureldeenkhaled9166
@noureldeenkhaled9166 4 года назад
Thanks man, this is helping me a lot with my graduation project.
@batchprogrammer108
@batchprogrammer108 4 года назад
I'm so glad it helped :]
@roryedmonds9415
@roryedmonds9415 4 года назад
Welcome back AJ!
@batchprogrammer108
@batchprogrammer108 4 года назад
Thank you! Happy to be back :)
@ghoulghoul
@ghoulghoul 4 года назад
Heya, I did the full 3 videos to apply it on my own! There's something I noticed though, in the RunNetwork function, when you return the outputs, you return the sigmoid of the acceleration value, which gives a value from 0 to 1. However you should apply the tanh function, so the genome can use breaks; your way of doing it is a bit like cheating, since you're telling the genome from the start that going forward is a good thing, yet it should learn on it's own. Also, this raises another issue, when the car goes backwards, the distance increases still, so so does the fitness function, so the agent never actually learns that going forwards is good. After allowing it to go backwards too, one of the agents realized that this bug exists, and kept on going forwards and backwards to increase fitness, lmao. I sorted this by comparing magnitudes of transform.position and lastposition, and only then adding to the totaldistance. Anyway, I absolutely loved your videos, I'm doing the same thing, but on a more complex track, so I really need to optimize it better haha. GL with your game
@batchprogrammer108
@batchprogrammer108 4 года назад
Hey Cristian, haha yeah I noticed a lot of these problems too but I didn't want to complicate this video; but this comment will serve useful to people who are looking to extend it's functionality. Good luck with your project :)
@arhziz
@arhziz 3 года назад
hello, please can you show me how you compared the magnitudes to eliminate backwards direction fitness error?
@patriksuba9027
@patriksuba9027 4 года назад
At first thank you for sharing knowledge with us , could you please help me with saving the agent that for example completes the track 3 times to a Json or a txt file ? and also to be able load it for the next simulation?
@csm12s
@csm12s Год назад
Thanks for the tutorial. By the way you can use linq or matrix operations instead writing for loops.
@akashgupta6287
@akashgupta6287 4 года назад
Can you please send the link of the paper that you were mentioning? Because I want to study them to learn more.
@rocketwastaken
@rocketwastaken 3 года назад
Can you make a tutorial about how to save the best cars and add it to another course? The JSON file stuff doesn't really have good directions and I figured the best person that knows how to is you.
@toenpl2094
@toenpl2094 3 года назад
Really nice Tutorial! keep it up!!!!! By using nn files can i run my self-driving car in real world??
@kobe_24
@kobe_24 3 года назад
Also, i do not see the biases list updating in the inspector
@acropolise1319
@acropolise1319 4 года назад
Do the Cars able to drive in Slopes and Ramps? Please answer!
@christopheboven6589
@christopheboven6589 4 года назад
It's on the geneticManager about the NNet script.
@gamzprism113
@gamzprism113 4 года назад
Thank you could you please show us how to save an agent and load it into another simulation.
@Crxyptic999
@Crxyptic999 4 года назад
Dude when u gonna finish your game that you have been working on for so long and also welcome back long time no see
@batchprogrammer108
@batchprogrammer108 4 года назад
Bro I'm working hard on the game and I'm going to push out the next Dev log in the next day or two :) Thanks for the comment, I'm happy to be back
@______7794
@______7794 4 года назад
@@batchprogrammer108 Bruh, WHat platforms u gonna release the game on?
@kobe_24
@kobe_24 3 года назад
Please tell me how can i load these saved values from json file into my project
@dardilac
@dardilac 2 года назад
I need some help. When running the code i get this error from the return of RunNetwork function: ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index. When the script of the Genetic Manager is on an empty object i get this error, but when is on the car object, it works, but the bias doesnt increases
@maxhe6714
@maxhe6714 2 года назад
Check that if the References in the Genetic Manager Script has been added
@xanderidkutellme.3356
@xanderidkutellme.3356 4 года назад
Very enjoyable vid good work and are you still working on the open world game?
@batchprogrammer108
@batchprogrammer108 4 года назад
Thanks for the comment man, yeah I am I'm releasing the development log in the next few days. I lost motivation a bit over the last couple of months but I'm back :)
@unnameddev1192
@unnameddev1192 2 года назад
hi what variables do I have to save? thx
@emeraldavocado7215
@emeraldavocado7215 4 года назад
Pretty neat. Any chance Unity ML Agents are going to be covered in the future?
@batchprogrammer108
@batchprogrammer108 4 года назад
Unity ML Agents look really awesome, once I get to play around with it I would love to release a video on it. First I was planning on releasing some tutorials on the Job System and ECS because I've been working with them a lot lately and I think it's a very interesting topic.
@PESCADORSHOES
@PESCADORSHOES 3 года назад
I've been working with your AI for the last month. It is fun. Thank you. I'm tempted to put one more LAYER on because my track is about 24 km long. What starting configuration would you put for long tracks?
@batchprogrammer108
@batchprogrammer108 3 года назад
Wow, that's amazing; glad it's going well for you. I'm not really experienced enough to say, however logically since it's a longer track it will need to store more information, so I would increase the number of layers however the number is completely up to experimentation. However, I came across a similar problem and the solution I used was to write a program that would incrementally increase the number of layers and neurons and run about 100 trials, then I would graph the average fitness across the different layers and neurons and pick the highest one; hope this helps :)
@PESCADORSHOES
@PESCADORSHOES 3 года назад
@@batchprogrammer108 Yes! This is a good plan. Thanks a lot.
@dardilac
@dardilac 2 года назад
Hi. So im noticing that the biases value is not increasing. Is just on 0 always. Im doing something wrong?
@tomblackdev
@tomblackdev 4 года назад
cybertruck?
@iaxsgames6029
@iaxsgames6029 8 месяцев назад
@batchprogrammer108 I finished the build but is it possible so it gets a reward if it copleates it and if it goes around the track faster it gets a bigger award?
@krlunshira8276
@krlunshira8276 4 года назад
what happen with the open world game?
@lukamandic9694
@lukamandic9694 3 года назад
Hello, I have some questions. You didn't initialise variables numberToCrossover and currentGeneration, but still you are incrementing them in the code and use currentGeneration in the for loop. Did I miss something or you just forgot to give them some starting values? Also, why we dont use newPopulation[naturallySelected] = population[i].InitialiseCopy(controller.LAYERS, controller.NEURONS); newPopulation[naturallySelected].fitness = 0; naturallySelected++; when we pick worst nets? Thanks :)
@sonjaarnhold5094
@sonjaarnhold5094 Месяц назад
Unity tells me I cant use "new" as a keyword in the FillPopulationWithRandomValues() funktion in this line: newpopulation[StartingIndex] = new NNet();. Can anyone help please?
@rajinhossain9522
@rajinhossain9522 4 года назад
Have my kids Ajay
@akashgupta6287
@akashgupta6287 4 года назад
Can you please send the link of the paper that you were mentioning?
@akashgupta6287
@akashgupta6287 4 года назад
Can you please send the link of the paper that you were mentioning? I need to study those papers. Please
@amdevmam
@amdevmam 4 года назад
@AJTech thank you for the tutorial it was very helpfull even tho i came across a snall problem lately and i couldn't find a way to fix it, so basically my problem is that whenever i press the play button in unity my car starts moving a little bit than it just go through the wall even if it's colliding (i didn't forget to add the meshCollider it's there) and the death() method isn't working but i've noticed that when i turn the gravity On in the rigidbody of the car it doesn't fly away it keeps respawning, it would be amazing to get an answer from you how i could solve this problem thanks
@batchprogrammer108
@batchprogrammer108 4 года назад
The reason is the death is called on any collision, what you can do instead is remove the death on collision and instead call death on a trigger that is above the ground.
@amdevmam
@amdevmam 4 года назад
@@batchprogrammer108 Thank you very much it helped me solve my problem at some extend
@sondre2902
@sondre2902 4 года назад
AJ, what happened to the open world in unity? miss the series a lot!
@batchprogrammer108
@batchprogrammer108 4 года назад
Thanks Sondre, I just finished writing the script for it; it's a long episode and the editing may take a while but I'm back so I'm going to be releasing more development log videos :)
@mateusdsp6871
@mateusdsp6871 5 месяцев назад
:D Jesus is coming back, God bless!
@user-bc5kb1pk8x
@user-bc5kb1pk8x 4 года назад
acceleration??
@christopheboven6589
@christopheboven6589 4 года назад
Hi AJ, Nice tutorial, but I get this warning that the new keyword is not allowed when deriving from monobehaviour. Have you maybe got a solution for this? Thanks
@batchprogrammer108
@batchprogrammer108 4 года назад
Can you send the code at the line where this is happening, and I'll try fix it
@chor6422
@chor6422 4 года назад
Replacing new with addComponent seems fix that...
@christopheboven6589
@christopheboven6589 4 года назад
You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed. MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all UnityEngine.MonoBehaviour:.ctor() NNet:.ctor() (at Assets/NNet.cs:20) GeneticManager:FillPopulationWithRandomValues(NNet[], Int32) (at Assets/GeneticManager.cs:54) GeneticManager:CreatePopulation() (at Assets/GeneticManager.cs:41) GeneticManager:Start() (at Assets/GeneticManager.cs:35)
@connorkoury5434
@connorkoury5434 4 года назад
Christophe Boven have you found a fix?
@MusicIndustries420
@MusicIndustries420 4 года назад
@@connorkoury5434 use (new GameObject().AddComponent()) istead of new NNet(). This will create a new gameObject and attach the script to it and you can reference it later. I am not sure if this is a proper approach but it worked out for me.
@jamalihmalih4303
@jamalihmalih4303 3 года назад
hey uhmmm, i follow all your tutorial here but the problem is about the car is moving around until its going up. Can somebody help me how to fix that ?
@jamalihmalih4303
@jamalihmalih4303 3 года назад
and then in my unity says " You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed. MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all UnityEngine.MonoBehaviour:.ctor () " i don't know what is happen can anyone help me ?
@jamalihmalih4303
@jamalihmalih4303 3 года назад
but when i change the setup in the rigidbody when i click freeze position and use gravity it run properly slow i still confuse what i must supposed to do ?
@cosmingugoasa5949
@cosmingugoasa5949 4 года назад
tried my first project, which is basically like yours but instead of a circuit i have a road going forward with some curves... i've reached generation 150 with a population of 50 cars each time but they do not improve.. is that a matter of time or is something wrong with my implementation ? EDIT : i've tried your scripts in my track and they do not even reach curve 1 in 100 generations...
@connorkoury5434
@connorkoury5434 4 года назад
There might be a problem in the way you pick your bestPop
@batchprogrammer108
@batchprogrammer108 3 года назад
Might be a problem with how your inputs are being processed, you may need to scale them differently.
@PESCADORSHOES
@PESCADORSHOES 3 года назад
Do you have collider on the sides of the track?
@batchprogrammer108
@batchprogrammer108 3 года назад
@@PESCADORSHOES Yes I do, that's how it detects whether or not it has failed.
@cosmingugoasa5949
@cosmingugoasa5949 3 года назад
@@PESCADORSHOES yes
@user-qh2vq6md2g
@user-qh2vq6md2g 4 года назад
dammit i feel like an idoit i did not understand the last part of the coding nor this part too D:
@carsonholloway
@carsonholloway 4 года назад
1:04:52 Ok daddy AJ I will
Далее
AI Learns to Park - Deep Reinforcement Learning
11:05
Finger Heart - Fancy Refill (Inside Out Animation)
00:30
I programmed some creatures. They Evolved.
56:10
Просмотров 4,1 млн
Deep Learning Cars
3:19
Просмотров 10 млн
Making a First Person Shooter with Thomas Brush!
4:50
ML-Agents 1.0+ Creating a Mario Kart like AI
16:32
Просмотров 36 тыс.
Physically accurate conveyors in Unity
2:23
Просмотров 1 млн
Клавиатура для девушек
0:14
Просмотров 1,7 млн
Платье для богинь на свадьбу
1:00
АРТ-ОБЪЕКТ СО СМЫСЛОМ
0:23
Просмотров 9 млн
PRADO 250 - классная машина!
0:28
Просмотров 3,1 млн