what is going on everybody and welcome
to part 10 of the AI in Starcraft 2 with
Python series in the previous tutorial
what we were doing is working on some
code to build training data and I told
you guys that would build the training
data you didn't necessarily have to do
that and I have done that so what we're
gonna be doing is working on building
our model that's gonna work with that
and then probably in the next video
we'll feed it through the model and then
probably in the video after that we'll
do the actual you know test how did that
model do so in the text-based version
editorial I've put a link to the
training data you can just click that
link boom here you are downloaded
extract it there's your training data so
what we're gonna be doing is using
carrots if you don't have it you're
gonna want to do a pip install Kerris
that's probably a little too big but
anyway and at least for now I'm using
Karis two point one point two and then
also you'll need tensorflow - GPU so pip
well I guess you just need tensorflow
but probably want the GPU version so
tensorflow - GPU and the version I'm
actually using ray this present moment
is 1.9 point oh it just came out in the
text-based version I was using 1.8 both
of them work just fine
also some people have been noting that
you cannot do this in Python 3.7 which
is apparently the case because of
WebSockets I'm not really sure exactly
what the problem is there but there is a
problem there okay so we're going to be
using cares so we're going to import
cares and then from Charis stop models
we're going to import the sequential
type of model which just means it's a
feed-forward neural network it's gonna
do it like it's just things go in
sequence okay so it's not like anything
fancy from Charis layers we're going to
import the dense layer that's just your
typical layer we're going to import
dropout which is just use to make your
neural network theoretically more robust
and then we're gonna import flatten
because we're going to be using a
convolutional neural network but a
common thing that people are going to do
is you want to maybe write before you
have your output layer you're going to
do like it just a simple dense layer
which is why we're importing that there
and to do that you'll need to first
flatten the data so we've got those
things we also want comm 2d because
we've got a two-dimensional
convolutional layers that we're going to
be using and then also we're gonna have
pooling layers so we'll import those as
well
that's probably mad because I crossed
over the maybe not know just saying that
we haven't used him okay so then from
Kara Scott callbacks we're going to
import tensor board because we want to
be able to visualize how the bottle is
actually doing so we can track things
like accuracy and the loss and other
metrics too if you wanted so then
besides that we're gonna import numpy as
NP we're gonna I really don't like that
it does that to me
numpy as NP we're gonna import OS so
we're gonna use numpy when we're reading
in the data to do some shaping as well
OS to iterate through a training
directory and then we're also going to
import random so in the directory I'm
working in here pull it over we've got
the custom sc2 package that we got prior
to this and then I've also exported that
extracted the train data although that's
quite small well I'll need to put a more
full amount of training data in there
let me see if I've got a better I think
this one's pretty full
I just want at least enough so I
actually did all my training on a
different I did it on a paper space
machine I think I'll just delete that
one and then paste in there we go okay
hopefully that's done copying 13
gigabytes by the time we actually need
it actually we're not gonna need it till
the next tutorial anyway moving along so
the next thing is we're going to start
to find our models so our model is going
to be sequential then the next thing
we're going to do is just start adding
in all of the layers to the model and
don't really see much point in writing
all that one out so copy paste so what's
going on here is we're just adding in
the layers so you've got a convolutional
layer convolutional layer then we've got
some pooling so the convolutional layer
has 32 I guess you would call them
features and the windows are 3 by 3 and
then the input shape that is the shape
of the game data that we're passing so
that is 176 by 200 by 3 now when I first
started doing convolutional neural
networks I always thought if you wanted
to have color surely that would be a
three dimensional convolutional neural
network right but these are just
channels so even though yes that's a
third dimension that doesn't matter it's
still a two dimensional convolutional
neural network so three dimensions would
truly be like three dimensional data
like if you have like there was a kaggle
challenge with like lung scans basically
and that was three dimensional so you
can you can actually work with three
dimensional data anyway so with padding
because as you start shifting a window
basically at some point you're you might
shift to get some data and then you've
got some of the windows like hanging off
the edge the question is what do you do
well you're gonna Pat it and we're just
saying just repeat with the same padding
[Music]
and yeah that's basically there's if you
want to know more about convolutional
neural networks you can go to Python
programming that
I'm assuming we can type convolution in
the search bar and then here you go I
think I've got some lovely pictures yes
I do about what the windows are and all
that and then how pooling works
is super fascinating so anyways so that
is the the main bit of our neural
network and then drop out just in case
you're not familiar basically what
happens there is so in this case it's
like a 20% drop out so the idea is 20%
of the data we just kind of like toss it
before we go to the next layer to do our
inputs and the objective here is to have
no like really biasing nodes in the
network and so the thought is that it
would it makes things more robust
there's plenty of research to back it up
it's just not necessarily going to be
the case that it's always going to help
you and it might even hurt you in some
cases so you definitely kinda want to
poke around lots of times I see this
more like at 50% or even 80% stuff like
that and you'd want to make sure that
drop out sometimes drop out means how
much do you want to remain and then
sometimes it means how much do you
actually want to drop out I'm gonna
guess this is 20% in fact let's just
Karras drop out let's see if Karis is
super clear drop out so I just typed in
Karis drop out into Google for some
reason I'm clicking on this and it's not
- oh it's it took place robotic it's
just randomly setting a fraction okay
right so the fraction that we pass into
here is indeed the the amount that gets
just applied a zero - okay anyway the
more you know I think TF learned might
be the opposite of that so just keep
that in mind always check okay so those
are our convolutional layers but we
eventually have to get to an output that
just outputs four things but also we
want to throw in that last dense layer
so modeled that ad and then we're just
gonna do a flattened and then we're
going to do a model dot ad and we're
gonna add a dense layer we're gonna say
it's got five hundred and twelve units
activation will be rectified linear so
rail you and then we will do a another
dropout so I'm just gonna copy paste and
here we'll do like a 50% and then
finally we just need our output layers
I'm gonna make some space so we're gonna
say model dot add I'm gonna add dense
it's gonna have four because we've got
four choices and activation in this case
we're gonna go with softmax and we're
good with at least the model itself now
we're going to specify some basic just
parameters of that model so we're gonna
say the learning rate and the one I
eventually settled on was actually 1e
negative four
typically you'll actually start with a 1
a negative 3 and then you keep decaying
down to a 1e negative 4 but in this case
there was really no learning that was
taking place with a 1 a negative 3 so I
actually started at 4 and I never even
decayed it I just kind of left it there
we'll see as time goes on and if we have
a much much much larger training set
that in just different data or more
complex data that we might find that we
can get away with a smaller learning
rate and decay and all that but as it
stands here this the whole purpose of up
to this point which is purely just to
see is there anything there can we
actually learn on this data or should we
go back
and try something else so lots of people
have make been making lots of
suggestions and stuff like that for how
to make things better and we will get
there but the first thing you want to
make sure is if if we can simplify this
problem to be as simple as we can
possibly make it
and things still don't work then it's
probably just not gonna work with
whatever we have in our mind for you
know how we want to structure things so
we actually need to go back in and redo
the foundation so before we spend a
whole lot of time getting all fancy we
want to just do something really really
simple
anyways so there's our learning rate now
what we're gonna do is specify the
optimizer so in this case we're just
going to use the atom optimizer so
Kerris optimizers dots atom LR will
equal learning rate and then DK we can
what we could actually set the decay I
guess I lied I had said a decay my pad
anyway now we're gonna do a model dot
compile loss equals and we're gonna go
with categorical cross and Trippi hope I
spelled it right and then we're gonna
say the optimizer is opt and then the
metrics we're gonna go with just
accuracy for now and accuracy
okay and then the last thing I'm going
to add here probably before we finish
out this video is tensor board we're
gonna specify a tenth sport object here
so that's tensor board and then the log
der is going to be logs stash slash
stage one okay and then so that way as
this model trains we're gonna save
logging type data that we can display
with tensor board just so we can see how
the model is doing so sometimes if
you're just like watching it and you're
just kind of taking mental note of loss
or
accuracy or whatever you can miss
there's a lot of trends that you're
gonna miss that are going to be pretty
useful to see visualized in something
like tensor board so that's why that's
that's there okay yeah I think I'm gonna
cut it here and in the next tutorial
what we're gonna do is we're going to
just continue building on this script
and the next all we have to do now is
like read in the data and like start
iterating through the data and even this
is a pretty small training data set but
it's already like 13 gigabytes which is
probably more vram than like almost
everybody watching this probably has so
we need to figure out a way to more
reasonably go through our data so
anyways that's all we're gonna be
working on in the next tutorial if I've
made any mistakes here we'll figure them
out probably the next one otherwise if
you've got questions comments concerns
whatever feel free to leave them below
otherwise I will see you in the next
video