Placeholder Image

字幕列表 影片播放

  • What is going on?

  • Everybody welcome to a part 11 of the artificial intelligences in Starcraft two with python tutorial.

  • Siri's In the last video, we built our neural network convolution a ll model.

  • And in this tutorial, what were we doing?

  • Is working on iterating through a data and feeding it through this model.

  • And we should actually begin to train the model in this tutorial.

  • Don't forget.

  • In the previous tutorial, the training data was linked.

  • Also, the trained model I will also be hosting.

  • Um, I am already hosting it.

  • Um, so again, that's in the text based version of this tutorial.

  • So with that, let's go ahead and get started.

  • So, uh, the first thing we need to operate through the training director training data is to generate through the training data directory.

  • So I'm just gonna call that train data because that's what mine looks like.

  • Try to bring it over.

  • Here we go.

  • Um, that's what mine is on.

  • Here is all the data.

  • So when you download it from the training data I just extracted into whatever you're working directory is.

  • Okay, So once you've done that, we're ready to start, So the way that we're going to do this is we're going to iterated through, um So each one of these files in here is a game that we won in.

  • Each game has, like, 32 maybe 60 actions that it took that we saved.

  • So each of these is a game?

  • No, we don't have to load in just one game at a time.

  • And in fact, we really don't want to do that because that would be sometimes a very small batch size that we probably wantto blowed in.

  • Much more.

  • Plus, we can load in much more.

  • Most likely depends on your GP you.

  • Or I guess you're RAM if you're not running the GPU version of sensor flow, Um, so either v rammer Ram regardless way have more than four megabytes, right?

  • So we want a load in a few games at a time, so we're gonna do it in like chunks.

  • But we still also probably want to have more than one epoch.

  • So our epic for those that get really angry at me for saying it So So So what we want to do is, um, we want to liberate through all of this data many times, but we have to do it in chunks now built in a caress.

  • If you pass your entire data set, you congratulate that data.

  • But you still have to have it in memory.

  • So I'm sure and caress there's a way to do this.

  • Um, because this is like a super common problem, right?

  • Your training data is much larger than your V.

  • Ram it, ram.

  • So somebody knows the way.

  • Please feel free to link below.

  • The way I'm going to do it is hacky way around it, but it gets the job done.

  • So move this side and we're going to specify h m E pox.

  • There is a 10 and, um, now is gonna literate over those iPAQ.

  • So for I in range, Hmm?

  • A pox.

  • What do we want to do?

  • Well, we need to track, um, where we are because we want to stop slicing through the data again.

  • There's probably a python IQ answer to this question.

  • I don't know it.

  • I guarantee you one of my viewers knows that those so posted below.

  • If you've got a sexier solution to this, so then we're gonna say increment by 200 so I know you can generate through something, um, in increments, but that wouldn't stop us.

  • I don't.

  • Anyway, it's not important.

  • If you know the answer.

  • Put it below anyways, then I'm going to say not maximum.

  • Someone's going to just be really bothered by the way I'm doing this.

  • But that's okay.

  • All files, uh, evils o s dot list.

  • Dir.

  • And we're just gonna list out this train dated her.

  • So, um so So now that we've got all these files Ah, thing that would be nice to add in is to not because we have the opportunity.

  • Um, we don't need to go through the same order of the files every single time, right?

  • We're gonna keep loading these in for each epoch.

  • So one thing that we could do is you shuffle them every time we load them in.

  • So first of all, let's grab the maximum.

  • So I was gonna say maximum equals Len, all files this way.

  • We know when to stop Iterating.

  • Um, and then what we're gonna do is, um, random dot shuffle and we're gonna shuffle all these files.

  • So then what we're gonna say is four file in all files and then we're gonna say current to current plus increment.

  • And then ah, what we're going to Dio is, um and in fact, let me think about this for a second.

  • So actually probably would want to dio is random shuffle.

  • We would rather say, Wow, not Max Maximum while not maximum, um then we want to liberate through the files.

  • And as we generate through the files, we would probably Well, first, let's just say print currently doing blank colon link and let's format and then we'll format current and then current plus increment.

  • This way we know where we are in the training and then four file, um, for each of the files.

  • What we're gonna want to do is we're gonna want to take the samples that we have in populate lists.

  • That are those actions.

  • So populate lists that our attack enemy base, um, do nothing that sort of thing, eh?

  • So what we're gonna do is we're gonna specify four empty lists or to say, no attacks.

  • That's an empty list.

  • And then we're gonna say attack.

  • Closest to nexus, Empty list, attack enemy structures.

  • That's an empty list and then attack enemy start.

  • That'll be an empty list, A swell.

  • And then, um, as we literate over these files, we're going to just give the full path to that file eyes going to host a path dot join trained data directory.

  • And whatever the file is, then data equals np dot Load the full path.

  • What's that?

  • You said?

  • 02 O's.

  • Got it.

  • So the next thing that we're going to do is data is gonna equal list data.

  • Uh, you actually don't need it to be numb pie.

  • We probably pickled it or something like that.

  • But right now we want it to be a list Now we're gonna do is for D In data, there is a choice is n p dot Argh, max D zero.

  • So the zero with so the zeroth was the choice.

  • And then the first death was the actual image itself.

  • So?

  • So the choice.

  • Um, and in fact, we we didn't really need art.

  • Max this We could have done this another way, but I feel like it's a little more clear if we do it this way.

  • So if choice equals zero, then we're gonna know attacks dot upend.

  • Um, we actually shit.

  • So in my in the text versions tutorial.

  • I wrote D zero and then, uh, d one we should be able to just say a pen d right.

  • That was kind of silly.

  • So now I'm gonna copy this and paste.

  • Now it's l If this will be a one, and I'll fix the other, uh, the list in a second.

  • So 123 and then we're just gonna go in order.

  • So no attacks.

  • Um, one is a attack closest to the nexus.

  • Uh, two is attack enemy structures, and then a three was attacking enemy start.

  • Okay, Um, once we have that, we've iterated through all of the files in that slice, and we've populated these lists.

  • Now we want to do is, um we want to balance these lists.

  • We want them to be the same length as everyone else.

  • So we're gonna say lengths we want to get all the links of lists equals check data.

  • So now we need to build check data.

  • But first, a quick thank you to my recent sponsors.

  • Johanna's Geisler.

  • You want us?

  • Geisler, Brock, Elmore, Vera, Um, and high end lim.

  • Thank you guys very much.

  • You guys are incredible.

  • Okay, so for our check data function, this is some basic stuff I'm gonna copy and paste this one in.

  • So I'm just gonna stuff this.

  • Ah, here.

  • And all this does is, um, again, not the most ideal.

  • You pry one I like past the lists in some as parameters to make this, like a Maura utilize herbal function.

  • But anyways, all it's all it's doing is a block of code that you ended up using twice.

  • So I just threw it in a function.

  • But you probably want to improve that a little bit again.

  • None of this is gonna be very polished stuff.

  • I'm just trying to run through it, find things that work and keep iterating over.

  • So feel free.

  • If you guys wanna clean up the code or whatever have at it anyways, we're gonna do is generate over the lists, get the lengths of all the lists and then return the lengths of all the lists.

  • So once we've got the lengths of all of these lists, the next thing that we want to do, um, is go with the smallest one.

  • So I'm gonna say lowest data equals the minimum of those lengths, and then we want to shuffle all of them.

  • So we want to shuffle No attacks because we're about to trim.

  • Um, so I'm gonna copy, paste, paste, paste, be nice.

  • Maybe to generate over the lists rather than doing doing this like copy and paste.

  • But change One little thing, like four list and a list of the lists basically do that anyway, so we're gonna shuffle those.

  • And then what we're gonna say is, um we want all of these lists to be sliced from the beginning to the length of whatever the lowest data is.

  • So again, this would be better if we iterated, because then we would also be able to generate this part.

  • So we're gonna say no attacks equals no attacks up to the lowest data amount.

  • So again, this is how we're going to balance all of the data.

  • So if one action had, let's say you got a binary choice, right, you've got ah, yes or no.

  • Then you're gonna feed yeses and noes to a neural network.

  • If the yeses and nos are 50 50 balance, chances are the neural network is likely to figure out the real reasons why um, Why you might have a yes or no if you have.

  • Yes.

  • Is that air Eight?

  • You know, 80% of your training data is yes.

  • The neural network is instead most likely or more likely to just learn.

  • Always predict.

  • Yes, that's a really easy thing.

  • Toe learn.

  • So it's a really quick descent or ascent in whichever way you're going.

  • Um, and that it's just not good.

  • Right?

  • Um, so you want to avoid that?

  • And one way you can avoid doing that or falling into that pit bull is if you balance all your data.

  • So again, I'm just going to copy Paste That was closest to Nexus Paste.

  • You based.

  • Okay, so now we're trimming all of the data, and then I just want to check data one more time to make sure it's of the lengths that we intended.

  • Some to go ahead and run that real quick.

  • Make sure everything's working.

  • Um, before we do the rest, Really?

  • I could have sworn check data printed.

  • It does, uh, words.

  • What would be happening here?

  • Why wouldn't, um there's no error.

  • There's just these, Like tensorflow keep dims warnings, which is fine.

  • Uh, why did this?

  • Not what?

  • Why's it running?

  • And it doesn't make any sense.

  • So runs through the pox.

  • No problem, while not maximum.

  • Oh, uh, okay.

  • Pretty sure I'm in that while we have not reached the maximum.

  • If what?

  • We're gonna do that for 10 e box.

  • So we're doing the slices.

  • Cool, Coca.

  • Cole.

  • Okay, so?

  • So you can already see it's trimming and stuff.

  • What was the deal?

  • X?

  • I don't think that cancels the build, though.

  • Yeah, let's just hit.

  • Cancel build.

  • Okay.

  • All right.

  • So everything's working up to this point.

  • So now what I want to do is, um we want to combine all this data, so we're gonna say trained data and there's gonna be no attacks plus attack.

  • Close is it doesn't really matter.

  • We just need all four list.

  • So attack structures attack.

  • Closest in X is cool.

  • So now we have all the train did it.

  • Now we again want a random dot shuffle the train data, and again, we want to do this because these air pretty long lists and the way the neural networks gonna work is you might start with no attacks, But you're ending on this like it's a attack closest to nexus.

  • So the last you know, 2000 samples that the neural network is going to see or gonna be all one answer.

  • Um, that's gonna cause problems.

  • So it's gonna go through new attacks and then slowly start, always predict no attacks, and then we're going to switch over to attacking me.

  • Start, and it's gonna only protect that is going to just keep doing that over and over.

  • This is not a good idea, so we'll do this way.

  • Um, the next thing is test size.

  • So we're gonna test.

  • We're gonna set our test size to be 100 and then we're gonna set her batch size to be 1 28 Now we're gonna set ex trainer.

  • Why train?

  • I'm gonna copy and paste these ins kind of arduous to type these out, and it's not really too much point.

  • So somebody somewhere help me avoid what's a man got to do to not have to type?

  • I understand why we have to re shape here, but if I just tried to do, um let's say I try to do train data and just do a slice of the train data.

  • Um, and like so, for example, if you always want the first If you like Colon, was it colon, comma one or I can never remember the exact order.

  • Think it's colon comma One for the always the first element.

  • Anyway, if you try to do that here, it just doesn't work.

  • Why?

  • Why do I have to rebuild the array and then reshape it?

  • There's got to be a better way.

  • So anyways, somebody somebody tell me the better way basically, so I can avoid doing this part.

  • This I won for I and trained data to the test sides to through the never mind anyways, so I could avoid avoid doing this.

  • Thank you.

  • So what's going on here is basically what we're really trying to do is we're just saying, OK, the training data for X X is always like your input.

  • Why is your target so X?

  • The input this is this is the imagery.

  • This is the the picture that we drew an open CV of the game map and all our units and colors and sizes.

  • So that's what our exes are in the wiser, the attack choice that we make.

  • So what we're doing is we're just going to say the training X is all the way up to, um basically keep the last 100 right?

  • The last test sides.

  • So up to the last 100 elements, that's our training data And then the last 100 elements down here for the testing data, and then we just have to reshape in this way.

  • This is just what what the models want.

  • Um, that's basically the case.

  • If you're passing this toe, psychic learn or you're doing straight raw tensorflow or in this case, cares.

  • Okay, so once we've got that, we're ready to do a model dot fit and to fit we need X train.

  • We need our white train, and then we're gonna have our batch size equals batch signs.

  • Um, the validation underscore data.

  • We'll go with x test.

  • And why test?

  • And we do wanna shuffles.

  • Shuffle equals true, actually, way probably don't need that.

  • I think we're kind of handling the shuffling and old that ourselves verbose for booze is one.

  • And callbacks is just going to be that tense or board s.

  • Oh, um, actually haven't toyed with verbose, but I'm gonna wager that, um that's gonna be in conjunction, Uh, is how much logging that you want to dio.

  • I think that's the first straight up tents or bored.

  • What?

  • You know, it's like a test with the way that we're doing things here.

  • We should be keeping track of accuracy and validation, accuracy and loss like the main things.

  • But you can raise this up and in track more things.

  • Um, I'm not 100% on that, but I'm pretty confident.

  • That's that's all that is.

  • After we do the fit mint, we're gonna go ahead and model, not save.

  • And we can say this is whatever we want.

  • In fact, I'm gonna cut and paste this last part.

  • I don't feel like typing that out.

  • Uh, and then so all I'm doing is kind of dynamically saving this.

  • I'm saying, how many eat pox am I doing?

  • What was the learning rate?

  • You could make other things.

  • I'm putting stage one just because that first model and then all I'm doing is incremental.

  • Our current number where we are and as long as current, um is not greater than maximum, we're gonna continue moving along.

  • So once it is boom, we pop out.

  • And if we have Maury Pox to do we do Marie pox again.

  • Not the most ideal thing.

  • Also, ex testing.

  • Why test these air?

  • Not not out of samples.

  • Um, because they're random, right?

  • We shuffled every time.

  • So, you know, you might wanna separate out your, you know, have some truly out of sample testing.

  • So, like, the validation accuracy that we're going to get here, Um, you know, take it with a green assault.

  • Basically, again, I'm just trying to get answers.

  • Can a model learn with this input?

  • Um, I'm gonna run it just to see the recording.

  • May screw up.

  • Uh, doesn't like it's just gonna hog my entire GPU, so as long as it works, I'm going to stop it.

  • We'll see.

  • May not work.

  • I hear it.

  • I see it.

  • Okay, so we can see his training right now.

  • We can look at loss and we can kind of see what's going on.

  • It's gonna take a while so we at least concede losses going down.

  • Accuracy is about 25%.

  • What's 25%?

  • I should stop this.

  • Actually, I have no idea.

  • Probably cutting out at this point.

  • I can see I'm lagging at least on O.

  • B s.

  • Anyways, 25% is is Ah.

  • You know, if you were to choose all one right or anything at random, you would probably have a 25% accuracy.

  • But over time, things get better.

  • So these are just some of the graph side took from tensor board.

  • Um, and I just put them in the text based version.

  • That tutorial.

  • So initially I just used 6000 samples.

  • Um, things weren't really going very good.

  • Then I increased to having about 110,000 samples.

  • And then after some training, I got this and then this was the loss.

  • But then if I zoomed in really, really far into the loss graph because he Oh, it's still sort of going down.

  • So So I let it go for very much longer time, and you can see here basically, what happens?

  • It just kind of levels out and then in search of all so yeah, very interesting.

  • So anyway, here is over a much longer time frame.

  • This was after 30 full pox.

  • Um, the results.

  • So it definitely can learn a 60% accuracy on four choices is actually pretty decent.

  • You would want it to be a little better.

  • But then again, the like the model and the actual structure of everything is pretty crude here.

  • So 60% accuracy.

  • I'm taking that as a victory.

  • Um, Anyway, full code is in the text based version of editorially, if you need it.

  • Um, in the next tutorial we're gonna be talking about is using the model.

  • So actually, using the model is not too hard.

  • We should build a run through that pretty quickly, and then we're gonna talk a little bit about a lot of the problems, at least the ones off the top of my head.

  • I've been taking notes throughout this entire kind of segment.

  • Now, of all the things I kind of want to work on, stuff like that.

  • And that will be if you have any suggestions for things you think we should improve.

  • That would be the time.

  • So I started thinking about those things.

  • Anyways, if you've got questions, comments, concerns, whatever you know, the deal leaving below.

What is going on?

字幕與單字

單字即點即查 點擊單字可以查詢單字解釋

B1 中級

訓練神經網絡--《星際爭霸II》中的Python AI教程第11頁 (Training Neural Network - Python AI in StarCraft II tutorial p.11)

  • 3 1
    林宜悉 發佈於 2021 年 01 月 14 日
影片單字