Placeholder Image

Subtitles section Play video

  • What's going on, everybody New day.

  • New tutorial Today we're gonna be going over part four of the tensorflow dot Js suit Auriol.

  • Siri's in this video.

  • I'm gonna be showing you guys how we can go about building the falling application, which basically plays Pong.

  • I'm that bottom player and then the top is just a pawn playing a I that we trained on about 100,000 samples still could be beat with the same tactics, mostly because this actual punky I was trained by the computer itself.

  • It hasn't really done any randomized learning, so, like, really know, like reinforcement, learning principles or anything like that.

  • So really just acts very similar to how the computer player acted, but it learned it pretty well, actually learned up to about a little over 80% accuracy.

  • So with that, let's get into it.

  • We got a donna stuff to cover, but I think we'll be able to cover it within a reasonable amount of time.

  • So, again, just like before, you'll definitely need the text based versions tutorial both to save you a lot of time in coding, but also in just data creation.

  • All that.

  • So, um what I've done is 1st 5 already hosted the training data itself.

  • So, um, this is the data here, so?

  • Well, it was it was loaded.

  • Um, it's just it's a ton of data is 100,000 samples of exes and wise.

  • I don't know why I disappeared.

  • It was already loaded, but anyways exists.

  • There's a link to it in the text based versions.

  • Tutorial just had their and downloaded.

  • Well, how come I can't click on it or any of these things?

  • Oh, my goodness.

  • What's going on?

  • Hold on.

  • Let me close out the out of their chrome.

  • See if that's caught what's happening anyway.

  • They really are there.

  • I promise.

  • Is my Internet dead or something was going on?

  • Am I still trying to load that other one?

  • There we go.

  • Okay.

  • Everything's all right, guys.

  • I don't want to be worried about me.

  • All right?

  • So anyways, um, while I have most of the data, if you want to check out how it was done, you can There's the Java script in the HTML, um, here.

  • Basically, it's just two computers playing against each other as fast as we could reasonably do it and JavaScript.

  • Um, and by we I mean Daniel.

  • So anyways, that's the collector.

  • Both in Java script HTML.

  • You don't have to use it, but if you wanted to use it, maybe adapt it to your own needs or something like that, you totally could.

  • But anyways, the other is So, uh, so once we have that, basically all you need to know it was first.

  • We'll download that AI ai training data.

  • It's just right.

  • Click.

  • Save it.

  • I've already got it actually saved.

  • Uh, right.

  • No, not there.

  • Where's my, uh Let's open this back up again, I guess.

  • Open, sir.

  • Okay, so in training Data 100 Kate out.

  • Jason, that's Ah, that's what we're working with.

  • I'm not gonna open that.

  • And sublime either, is pregnant throw a fit if I do that.

  • So now we want to do that.

  • We have that trained as we actually wanna train against that data.

  • But, um, we want to do that python not intense.

  • Reply Js because sensor alleges is much, much slower.

  • So, like we were saying before.

  • Yeah, on a single inference, it's maybe 2 to 3 to four times slower.

  • Um, but it's actually much worse than that when you run it in batches.

  • So we definitely want to train large amounts of data in python.

  • We gonna transfer learning and all that kind of fun stuff.

  • Intense footage, as you saw quickly, you know, adding, let's say one games worth of data that could train pretty darn fast.

  • It's noticeable, but not horrible.

  • It doesn't really ruin the experience, But training with 100,000 samples, that's gonna not be a comfortable experience from whoever has to go through that.

  • So So, anyway, we want to train it first.

  • So this is the code that we're gonna do?

  • We actually could just write that out.

  • I'm here, so I'm just gonna copy and paste it.

  • Uh, whoops.

  • We're not entitled.

  • So let's go ahead.

  • New text document.

  • And let's just call this pong train dot Hi.

  • Yeah, right.

  • Click open with sublime.

  • And let me just copy Is that back in there?

  • So all this is doing is just gonna open it.

  • It just loads with Jason into, uh, you know, a python, Jason Data.

  • Then we're going to put him out.

  • We're just gonna grab all of the exits.

  • All the wise into excess and wise creating aren't simple.

  • Uh, and then we're splitting them here with the train is just the first up to the lab, basically up to the last 10,000 samples.

  • So 90,000 samples, um, and then here, the wise, the exact same thing.

  • And then this is the last 10,000 samples in the last 10,000 samples for the testing.

  • So we want to split those because these were used for training and then this is the out of sample testing.

  • The reason why we want to do that, I want to see.

  • So like, while it's training, it's also gonna validate.

  • It's gonna split.

  • It is going to split even the train out into, like, validation and training, right?

  • So it's going to do that already.

  • But then what you want to do is you want to use out of truly out of sample never before seen by that model data.

  • And that's what this date is gonna be in Your hope is that it's very close, like the accuracy of the truly out of sample data is very close to the validation accuracy.

  • If it is congratulations, you didn't over fit.

  • If there's like a huge divergence.

  • You you've probably over fit.

  • The data is most likely the case.

  • So now we want to do is go into training.

  • It's his data, and we're gonna be using caress for that.

  • Just simply because first, will caress is actually pretty good.

  • If I was ever import cares I keep getting forced into using caress but have ever given the choice again in the future.

  • And I have to use a higher level a p i to trains a model.

  • I'll probably use caress in this case Reason caress because, um, converting a caress saved model to the model dot Jason that you need for tensorflow Js is super simple.

  • So we're gonna use cares.

  • Um, so we're gonna go ahead, import Caris, We're gonna, uh, make these other two imports that I'm just gonna copy pasta.

  • So from care stop, models were gonna import sequential from Carrie Stott layers were gonna import dense layer air.

  • We're gonna include some drop out, at least for us.

  • Swimmer.

  • When you're training a model dropout is pretty significant.

  • It's a good thing.

  • Toe test out.

  • Using various amounts of drop out just makes a much more robust network, usually when you're actually performing inference, it's questionable whether or not you'd actually want to use dropout.

  • Um, so we're because this is our model.

  • I actually think it will wind up using drop out in the inference anyway.

  • But you you could either do it or you don't have to, but anyways, um well, just we're gonna leave that in there, and we're gonna create a sequential model.

  • This should look very similar to what we've been doing in tensorflow.

  • That J s like the syntax is very, very similar.

  • Next, um, always haven't meant to bring it up.

  • In the last tutorial, someone was mentioning that if you don't specify a activation layer in the tents are flooded Js at least with the corps A no, the layers A p I probably will.

  • Court is going to totally different, but it was in the layers.

  • A p I if you don't specify an activation layer, there is no activation layer.

  • Well, okay, so that explains some strange behavior that I had seen before, but anyway, so So so definitely specified activation later.

  • Anyway, carrying on.

  • Um Okay.

  • So once we've defined our model, we need to go ahead and start giving all of our program like are basically we need to compile the model just like we did before.

  • So Adam is just gonna be caress Stop Optimizers um stuck Adam optimizer and then the learning rate that we're going to use a 0.0 011 the native tree.

  • Next, What we're gonna dio is model dot com pile and we're going to compile.

  • Actually, I'm gonna copy and paste these.

  • Keep reverting back to writing and there's really not much reason to anyway, model that compile our loss calculation.

  • We categorical cross entropy.

  • Optimizer will be Adam are metrics that we're after Like they were curious better just going to accuracy.

  • They were gonna fit the model.

  • We're going to Tennessee pox, and we're gonna batch in sizes of 128 at a time.

  • Finally, we can output and saving all that.

  • We could get the score of the evaluation of the testing data that out of sample data and then we can save that model to a caress model.

  • Once we've saved that model, we actually can convert that, um, to a tensorflow Js model with a view pip install tensorflow Js You could make the conversion of all your caress models to model Jason's.

  • But make sure you do that.

  • Go ahead and pip install tensorflow Js.

  • But instead, what we're gonna do is we're gonna go to the top of our script and we're just going to import 10th sir Flow Js as t f g s gods and then we're gonna come down here, and you you might want to save your Continue saving your model.

  • It's probably a good idea to keep it saved.

  • Um, but we're also gonna t f j s dot converters dot save caress model model and then t f J s model.

  • And because I'm serious, actually, don't know the answer.

  • Tensorflow j s, um documentation.

  • It's like its own little could be so hard how to import it.

  • Caress mal intent.

  • I'm trying Thio.

  • I want to know like this is save caress model like very specifically wonder how if there's a method that exists for doing um, for doing just a straight tensorflow model, let me just google this rook with tensorflow Js dot converters.

  • So I'm thinking, Is this so there is a private TF save save caress model Ah, but you can do it with just a straight tensorflow model.

  • Well, yeah.

  • So, actually, it's pretty simple to convert a lot of them.

  • Um anyway, uh, what I did not see, though, it's This is the wrong one.

  • What I didn't see is, like TF learn or something like that.

  • But you can do Oh, man, you could do all.

  • So you do the frozen models.

  • I'm not sure this session bundle is, but it sounds interesting.

  • So, Carris, TF saved model frozen model.

  • Wow.

  • Yeah, that's a lot of things that we can actually converted.

  • Do pretty cool stuff.

  • You know, be cool is like a a deep dream.

  • Let anybody take a photo and then do a deep dream of that photo or something in the browser.

  • That be kind of cool.

  • I know those exist already, but that's all done server side.

  • That'd be pretty cool to do one client side.

  • Pretty nifty.

  • Anyway, back to the editorial.

  • Um, so we're gonna save that, and we're gonna put it in t of jazz model, like, just in that directory.

  • So let's say that I don't know if I'll get away with running caress in.

  • Ah, No, I don't think about it Properly installed.

  • Let me, uh, in 36 Let's run this in 35 Opening the command prompt.

  • See Python 35 Hi.

  • Thon Pong trained up pie.

  • Wait for it.

  • Okay, so that's often Training, as you can see, is actually learning quite quick getting into the mid to upper seventies within, Like what?

  • To eat pox.

  • That's pretty crazy.

  • So, uh, while we wait on that should be done any moment.

  • What that's gonna do is just gonna output for us into a new directory, our actual model that we could load in a tensorflow dot Js.

  • Now, what's unfortunate with this is that it's actually kind of challenging toe load.

  • These models in, um, I think they've done it because you're going to run it on a Web app.

  • So it's like it's made with that in mind, but it's actually very frustrating to load it in, um, via that web app.

  • So if you're not in that web app, so anyways, it's up here.

  • Now, let's just go back here.

  • And, um so this is our caress model, and then this is basically our actual model Jason file for the for the model itself and then I honestly don't know.

  • Whatthe shards are I'm gonna guess those air your weights.

  • Uh, I really couldn't tell you, though.

  • I'm gonna guess weights, but I I really don't know.

  • So, um, now how would we use that model in Inter actual script?

  • So let me just pull up python programming dot net.

  • Let's go to slash pong I and I'll just show you how we've done it.

  • Um Okay, so click on this.

  • And so rather than loading the Mott, we've tried multiple ways of doing it.

  • This is the way that we've done it here, where you just wait for the model tow load from and then we've hosted the model right here on python programming dot net.

  • Now, unfortunately, if you try to do that, if you try to use this locally, you're gonna hit all kinds of issues.

  • Like if you just try to use the model locally, you're gonna hit an issue that you're not using your not making hdb request on.

  • And then if you do try to make the HDP request, are going to hit some some sort of cross origin air.

  • I didn't want to enable cross origin requests on Python Burnett Net.

  • But I did do it on a TSH kinsley dot com.

  • So, um, you can use the model I've hosted from h kingsley dot com.

  • If you want to continue making changes, you wanna fall long, and you can't train your own model for whatever reason, or you've trained your model.

  • But you can't really use it because you don't have your own Web server to put it up to to pull it down from or to develop on that Web server.

  • There has got to be about a way to do this.

  • I just don't know.

  • It's my best solution I have to offer you guys right now is I will host the model, and I will enable cross origin requests on a different domain, not Python performing dot net and, um, and you guys can still continue to work, at least locally for those of you without a an actual VPs or something.

  • Okay, so let's say you want to use this.

  • So what I'm gonna do is I guess we'll come down to um, yeah, let's go to the text based version tutorial and just go down to the bottom.

  • And then really, all we need to dio is we could just copy and paste that coat up into here to set codes.

  • Pretty similar.

  • Um, I don't really think that there's much been changed lips.

  • In fact, what we can do is we can use pong game dot html and I'm gonna copy pasta and then punky, I I think it's actually pong game dot Js Yeah.

  • So, pong game dot Js I'm gonna save that.

  • Come back in a year, open up on game dot Js And then I'm gonna copy and paste this code hoof.

  • It's a mile long.

  • Copy.

  • Pasta save scroll out a little bit.

  • Um, how do I get rid of this?

  • I see.

  • No, that's not what I want.

  • Isn't there?

  • Like, a clear I'm not blind.

  • Bill.

  • Result hide panel.

  • There it is.

  • All right, so then I'm a screw up to the very tippy top, and here you can see, you can use the the version from h kinsley dot com.

  • I just really wanted to stress that before anybody was like, I don't want to use his model train my own model, and then they tried train their own model and then can't so Or at least they can't use it.

  • I know you can use, like local storage.

  • So if there was some way to, like, injected into local storage, that would be cool.

  • Maybe there's like some sort of, ah extension that it will allow you to do that.

  • Or maybe you could load it locally.

  • Maybe there's some Java script you could run tau load something that I don't know how you would do that.

  • That it just seems like a huge security risk.

  • So, anyway, I have no idea how to do it.

  • Someone who knows Java script better might have a heaven idea.

  • Or at least there's gotta be some way to, like load the model from another website via Java script cause it's just the Jason and there's, like three little tiny files.

  • Load those into local storage and then load those as your model.

  • And I think you could probably do that so you could load local storage like so let me just pull it tensorflow Js load model, and I'll just open this one.

  • Let's see if they have darn it, they don't really have.

  • This is for Caris specifically, um Let's see if they have the local storage.

  • I don't really see in local storage here.

  • T f No, no, no, no, no, no, no.

  • Load a model tensorflow J.

  • S.

  • Here we go.

  • This is what I was looking for.

  • Um, see these air your your four options for over this or saving what I actually wanted to do is low.

  • Where's the load?

  • Here we go.

  • So you can use index TV.

  • You can use the local storage.

  • So what I was thinking is, maybe you could load that with some sort of JavaScript and store it to local storage and then load it this way.

  • I don't really know.

  • Um you could have the user also just do, like, some sort of upload, apparently, and then somehow make use of that.

  • I don't know anything about that.

  • He's just for me to figure out was just the HDP request.

  • So Okay, So once you have all this, you can run the file, you can play with it, and then I think what we'll do in the next tutorial is trained this?

  • Aye.

  • Aye, because they say I doesn't actually learn any further.

  • All it does is just play Pong against you for Infinity.

  • So what I think would be kind of cool is to start the model here.

  • So it's basically just learned from from the computer player and then after every game or every two games, used some transfer learning to further change the weights of that model and make the learning rate like really, really low.

  • Uh, and then see if that can make the model any better.

  • So anyways, that's all for now, if you got questions, comments, concerns, whatever feel free leaving below.

  • Thank you for your support, your subscriptions.

  • You're sponsorships, all that fun stuff, and I will see you in another tutorial.

What's going on, everybody New day.

Subtitles and vocabulary

Click the word to look it up Click the word to find further inforamtion about it