Get started with TensorFlow's High-Level APIs (Google I/O '18)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone good morning thanks for coming so early so my name is Josh Gordon and I'm Laurence Moroney and we are here today to speak with you about tensor close high-level api's and I have a lot of good news for you and I hope this talk will be concrete and useful so one area I'm particularly passionate about is making machine learning as accessible as possible to as many people as possible and the tensorflow team has been investing very heavily in the same thing so we spent a lot of energy making tensorflow easier to use and I'd like to show you basically a demo of what is in my opinion the very easiest way to get started with tensorflow today so there's three things that are concrete that I'd like to walk you through and the very first is even if you're brand new to tensorflow you're brand new to machine learning even if you're new to Python one area that seems silly but is non-trivial for a lot of people is actually just installing tensorflow in different dependencies and I know for Python developers is just pip install tensorflow but that can be hard for people that are brand new so I'm gonna show you something called collab and I'll walk you through collab it's basically a jupiter notebook server running in the cloud it's free of charge it has tensorflow pre-installed comes with a free GPU it's awesome I'll walk you through how to use that how'd it get started with tensorflow the next thing tensorflow has many different api's but my personal favorite what I'd strongly strongly recommend to you is something called chaos and chaos the chaos API is completely implemented inside of tensorflow it's great I can't tell you how much fun I've had using it so I'll walk you through writing hello world and care us the same API is also useful for tensorflow Jas and then I'm gonna point you to some educational resources to learn more cool so these are the api's that I want to briefly introduce so chaos it's basically Lego like building blocks for building and defining models TF data so when a lot of people start learning ml they get really hung up on okay they learned that a neural network is composed of layers and they find out that they can adjust the number of neurons per layer and there's different hyper parameters like the optimizer and stuff like that they spend a lot of time on what I call modeling but something that's really really important but doesn't get enough attention is actually how do you get your data into the network and writing input pipelines is non-trivial so I'm also going to show you an API called TF data which is a relatively easy to use but also a very high-performance way of writing your input pipelines and then I'm gonna show you eager execution if you're new to tips and Lawrence is gonna give you a lot more depth on eager yep by the way when you hear the word eager execution if you're new to tensor flow just ignore that and just think of this as this is the thing you always do so you should always write and run so develop and debug your tensor flow programs eagerly and it makes tensorflow feel just like regular Python this is a short talk so I'm not going to go into all the details of how tensorflow works under the hood but this is the right way to do it if you're learning tensor flow today so briefly this is what I would do if you want to try tensor flow and chaos and TF data and eager execution in the fastest possible way and I should tell you off the bat so all these API is there fully implemented and they're working well we are just now starting to write all the samples and Doc's around them so I have a feeling the samples I was able to cook up for this talk are they're quite rough but stay tuned and check back in the next few months as we flesh this out but let me just show you how to dive right in so if you go to this website it will bring you oh can we switch to the laptop for a minute please thank you it will bring you to this github site and if you scroll down to the readme you'll see a sequence of a few notebooks and I just want to show you how easy it is to get started if you just click on one what happens is they open up immediately in collab and so now you have a jupiter notebook it's running entirely in the cloud you can hit connect to connect to a kernel and now I can start running these cells and I'll walk you through this in more detail in a few minutes but if you go through the first notebook this is going to show you how to write your first neural network using Karos there's a little bit of pre-processing code but the notebook is very short the next notebook will show you how to do the same thing using Karos in combination with TF data and eager execution and then we go into a little bit more depth so it's literally that easy to get started it will take you about five minutes end-to-end to try this out all right so let's let's switch back to the slides please and let me give you a little bit more depth of what's happening in these notebooks so of using the Charis api this is the complete code - a few lines of pre-processing just formatting the data to write train evaluate and make predictions with your first neural network in tensorflow so if you were using tensorflow about a year ago it would have been substantially more code and there's other great high-level API is including estimators which are really really wonderful for doing machine learning at production but at least for learning ml I'd strongly recommend this so I will walk you through exactly what all of these lines are doing and one point I want to make is that the code is it's concept heavy but code light so writing the code itself should no longer be a barrier to getting started with ml I hope that far fewer people are gonna spend energy and time on the syntax and debugging and now you can spend more of your time and energy thinking about what you're trying to do and why oh yeah and before I dive into code I want to make a really really important point so machine learning is a broad field by far another mistake that a lot of students make when they're learning is they learn how to train an image classifier like we're gonna do in a moment and they find out when they write the classifier they start evaluating it and they see these numbers like 99% accuracy and then they find out that by tweaking the network you can get to like ninety nine point six or whatever and in reality it almost never matters the most important thing you can spend your time on is designing the experiment and what I mean by that is concretely thinking about what are you trying to predict and why how will it be used in practice what could go wrong where does the data come from thinking through the design of your system as you would in any type of software is much much more important than messing around trying to get higher accuracy I'm not gonna cover this today there's a whole talk on that but today I just wanna show you the code but always think about what and why in addition to how all right so before I dive into this a couple cool things not enough time to introduce tensorflow I just wanted to call out the community is the most important thing about tensorflow in addition to the thousand plus folks who have contributed code there are many many more who are doing things like teaching organizing events writing articles these things are incredibly valuable too and there's a few new things that I just wanted to call out this came out two days ago so there's another library called tensorflow J s part of tensorflow in JavaScript uses the same API is the Charis API that i'ma show you today weren't you gonna act out this slide I was gonna act this out great sandbox where you can try it I could dance it out anyway it basically it's tensorflow running in the browser and this runs in real time there's two links on the bottom if you check this out at home there's a really great demo you can play with on our blog and you can actually find the code on the website another thing there's a pair of links here which I'd really encourage you to try so this is magenta and magenta is a project that uses tensorflow for experiments in art and music and here this is computer assisted drawing so magenta is helping me draw duck so I'm drawing the duck with the mouse in magenta it's sort of like autocomplete for drawing there's a great game called quick draw which I'd encourage you to try it's great for kids it's yeah quick draw and the magenta demo is great to try just some fun stuff before we get in the code and also before I get the code in a personal note one of the reasons I care about machine learning so much is because of a project called cell bot and cell bot is a project from 2004 it was in a biology lab and so bot uses a neural network to identify specific types of cells in solution and then sort them and what was so cool to me as a student working on this is that machine learning is not just for computer scientists the fact that biologists were trying to do something useful using technology that originated in our field was really meaningful to me it's how can we use machine learning for medicine for art for healthcare just to do useful things in the world so that's that's kind of the thinking behind everything I do with no it's what can we do to help people basically all right so collab the URL for collab is collab research Google com collab is short for a collaboratory it's inspired a lot by Google Docs it's a Google Doc style of code editor and you can download basically you can save Jupiter notebooks in Google Drive you can download them back as regular Jupiter notebooks so there's no lock and I know a lot of people by the way are not from Python so I just want to spend a minute and introduce Jupiter notebooks so broadly here's collab and there's two types of cells there's markdown cells which contain markdown and if you edit a markdown cell like I'm doing with HelloWorld and you execute it it just renders the markdown the other type of cell is a code cell and if you edit the code and execute the cell it executes the code that's all it is and there's one really cool thing as well as that they give you access to GPUs yes I've spoken with a lot of people who either find it very difficult to set up their GPUs or you know maybe they're in a university environment and they don't have access to expensive GPUs and if you're using a colab you can actually connect it to a GPU in our data centers so that you can test out your code running on GPUs exactly with no coal at all yep it's a really good point the other thing you can do if you're new to Jupiter notebooks is you can create visualizations in line so here I'm using matplotlib to plot some data and the graph goes right in line with your notebook and this is really important because it's a great way to share results another thing that I wanted to mention quickly is you can pip install libraries so you're basically you're running in some containers sitting somewhere on GCP but you can install whatever libraries you need so here on pip installing matplotlib so you have root access to it and then the last thing a lot of people missed this feature but it's super useful it's called snippets and it's it's conveniently hidden in the table of contents but what I'm doing in this notebook is I'm going to create some data and then I'm going to download the data off of colab back to my laptop and to find out how to do that I click on the snippets thing and I start searching for downloading data and colab can't totally see it on the screen has a snippet of code that I could just copy and paste directly into notebook and run so it has examples how to install libraries and everything like that it's super useful don't have time to talk about this collab is great for reproducible examples alright so let me jump right into what it looks like to use chaos to write your first nil Network and I talked about this earlier but no one has ever looked at the code to write your first mil network regardless of how smart you are it doesn't matter if you have like a PhD in physics or whatever and it's just gone oh I get it it's impossible it takes months to learn this stuff so it's completely normal to see lots of concepts and have no idea what they mean but let me just at least introduce you and then I'll point you to a course you can use to get more depth oh the other thing I should probably look at my slides right so you'll see lots of parameters when you define these networks and really only one or two are important to spend your time on and I'll point you what those are as we go so there's broadly five steps to write hello world and tensorflow using chaos the good news is steps three four and five are literally one line of code so that's that's all the work of training the network evaluating your accuracy and making predictions collecting the data set in reality takes a long time pre-processing the data takes a long time that's just getting it to the right shape and building your model is where a lot of the concepts are so let's see what this looks like so we're gonna use em mist I know for people that are machine learning experts you know em this cold and the reason I picked it is just so we don't have to worry too much about the data if you're new to M this it's it's sort of the hello world of computer vision it's a data set of about 60,000 plus very low resolution handwritten digits and our goal is to train an image classifier to classify or recognize digits that it hasn't seen before so here's what we'll do we'll import tensorflow and you can see that on the second line we're importing emne stand this is easy because the data set is already we have a loader for it that's baked into tensorflow and if you're new to using kiosk mode tensorflow you can see that it's just included you can do TF care us and now you have access to the complete chaos API so there's nothing else to do it's just it's just there and this is awesome by the way there are many many awesome advanced things you can do using chaos and tensorflow like it's great here I'm just trying to show you the straight easiest possible way here's the format of the data set so as imported it's divided already for us since a train and test train is about 60,000 tests is 10,000 the top right I have a diagram of the format of the images if you look at them books on that workshop directory the best thing you can do when you import a data set is to spend a lot of time asking really basic questions so literally when you import the data print it out for an out the shape print out a single image look at the format what's the data type is a floating-point is it an integer what are the dimensions how many do I have spending a lot of time just understanding the format the plumbing will save you a lot of headache later on so it's always okay to ask really basic questions in the bottom right there's many neural networks that work with 2d images here we're gonna make a simplification and we're just gonna unroll the thing so instead of a 2d image we're literally gonna unstack the rows these images happen to be 28 by 28 pixels when we unstack them we get a vector that's 28 times 28 equals 780 something pixels in a line so it's a simplification that's all it is to import the data set I didn't show the code which is just numpy to reshape it but it's in the notebook so now we're gonna build our model and here's concepts that will be probably entirely meaningless to you if you're brand new to ml one funny thing about neural networks so there's many different types of classifiers and most of my background I was really invested in tree based models before deep learning was a thing and the reason I like tree based models like random forests is that I can look at a tree and intuitively my brain understands exactly what the tree is doing to classify the data like I get it it clicks the neural networks can be a little bit counterintuitive it's hard to describe in 30 seconds but let me just tell you what we're doing and you can take the course to learn more so here we're defining a fully connected deep neural network there's gonna be two layers that you can see so first we're saying we're defining our model we're saying we're gonna use the sequential API which is the simplest API to define your model it literally means our model is going to be a stack of layers the first layer that we're stacking on is gonna be a dense layer dense means it's fully connected and I'll show you diagram of this I'm sorry there's just this is a one layer network but the notebooks have an exercise where you can add a second layer and then we're adding an output layer with ten outputs and each of those outputs is basically going to gather evidence that the image that we feed through this network corresponds to each of the digits and this slide I was editing these slides last night so this slide is actually a little bit different but here we actually do have two dense layers the point that I want to mention there's a couple points that I want to make one this is the complete code to define the network so it's code concise too broadly the more layers you add to your network and the more neurons or units per layer the more capacity your network has meaning the more types of patterns that can recognize the problem is the more things your network can recognize the more likely it is to memorize the training data so in machine learning there's always this tension between memorization and generalization you don't want to just memorize the training data what you want to do is learn patterns that are useful to classify digits that you haven't seen before so it's very easy to get very high accuracy on the training set by building a deep neural network with many neurons and training it for a long time it's not necessarily the right thing to do though so when you're messing around with these architectures start as simply as possible and then slowly expand from there the next thing you have to do is compile your network this is the last step of building it it's just one line there's two concepts I'll get is the optimizer in a sec the loss function is basically the objective that your network is trying to optimize the good news here is this is a fancy word categorical cross entropy but what it literally means is your network is going to make a prediction so you feed an image of a two through your network and it gives you a probability distribution over all the digits that it could be so maybe with 10% probability it's a 0 with 5% probability to 1 hopefully with like 90% probability it's a 2 anyway this is a fancy word that compares the thing the network predicted to the thing you wanted it to predict and what you want it to predict is all the evidence is on it - the other thing is the optimizer and this is the method with which you're going to train the network the truth is there's a whole bag of different optimizers you can use you don't have to worry about what rmsprop means too much because there are good defaults so for this type of classification problem basically you're always using categorical cross entropy and rmsprop is a perfectly good vizor to start with using all the default parameters so there's there's good defaults broadly the way the network is trained is using gradient descent so here's here's how I would think about this what a neural network is when we add those dense layers there are many different weights connecting the pixels to the neurons and you can think of all those weights as a parameter so here's the simplest example that I had in my head if you think of linear regression so let's start with linear regression you have some points on some plot and you're trying to find the best fit line and if you think about from high school the equation for the best fit line you've got like y equals MX plus B and you've got two parameters that you're trying to learn M is the slope and you have B it's the intercept and for different values of M and B you can calculate how well your line fits the data and you can look at your error and there's different ways to get your error but maybe it's the sum of the distances from your line to the pixels so by adjusting m and B you can find the best fit line neural networks are trained in a very same in a similar way except instead of M and B you've got hundreds of thousands of parameters that you're trying to learn and these parameters connect the pixels to the neurons and so on and so forth and the way they're trained is using something called gradient descent and there's a fancy diagram on the right that's showing something that's not relevant but they all start at random values and you slowly adjust them over time until the network becomes better at recognizing digits anyway I'll point you more educational resources in a second so here's the cool part building your model is where there are many many machine learning concepts that you have to spend a lot of time learning the next three steps they're literally concepts that are basically involved with running an experiment so there's here's the only parameter so here's how you train the model so it's one line fit is synonymous with train and we're training it using the training images and the training labels here's the only parameter that really matters and the good news is this concept is a little bit simpler so Epic's basically means an epoch means one sweep over all the training day so we have 60,000 images one epic basically means that we're training the network on all those wants training a network is a little bit like tuning a guitar so think if you have a guitar and you want to it starts untuned and you want to tune the strings to hit a particular note so you start tuning it and like every time you twist the wheel in the guitar you can think about as an epic and you tune for a certain number of epochs until the guitar plays the right note if you keep tuning past that point it's no longer gonna play the right note and eventually the string is gonna snap so you have to stop tuning it at a certain point and you stop tuning it based on the sound you neural networks are exactly the same way so there's basically one very simple plot and it's this which I'd recommend you look at while you're training your networks on the y-axis we're seeing this fancy thing called loss that basically means air loss is the same thing as air it's just a fancy word for it what we're trying to do is minimize our air on the x-axis is how long we're tuning the network in terms of number of epics the longer if you notice after a few epics the loss reaches a low that's kind of when the guitar hits the right note if you keep training the loss will start increasing again so to find the right number of epochs you literally make a plot like this you just plot your air and then you take a look at you look for the point of lowest loss usually under validation data after that you can evaluate it and evaluate just means giving some new data classify it with my network and take a look at the accuracy in other metrics that's also just one line of code and as called this will give you your loss or your air and your accuracy when you train the model you can specify other metrics that you like returned and then to make predictions on new data it's also just one line of code so there's some syntax here so you can say model dot predict and you give it an image the syntax here is a little funny as it happened the model expects what's called a batch of data and a batch just means it's it's meant to predict on multiple images at once so you give it an image and you just wrap it in a list and this is just syntax to make it happy but we're making predictions on the on on the very first image from this test data and what the model gives you back is probabilities that that image corresponds to all the different digits and basically at the very lowest layer of the network you'll have evidence sitting in on the output nodes and if you do a numpy dot Arg max so you just find the largest element that will be the prediction so here it's predicting that it's a seven I'm gonna give you a really quick overview of TF data and then I'm gonna hand it over to Laurence to show us a little bit more about eager so when I would here's something to be aware of in tensorflow there's many different ways of doing things you should always do the simplest possible thing that's adequate for your problems so never basically when you're starting with ml and in probably 90% of settings don't worry about performance just try and minimize complexity so before we wrote our hello world just using the emne Stata in numpy format that's fine if we were working with a much larger data set or if we were reading images off disk or if we were pulling them from the cloud there's a lot of complexity there and performance starts to matter for example there's latency when you pull images over network so maybe you'd want to hit a bunch of different servers at once or maybe you'd want a bunch of different threads so TF data has all sorts of functionality to help you with things like this also one funny thing that's happened so GPUs and TP use have become surprisingly fast and the latency in training a lot of models is actually can you keep the GPU fed there's something called GPU starvation where the matrix multiply there is so fast that it's just sitting around waiting for data and so TF data has lots of utilities to get your stuff like prefetching it to the GPU if you need to anyway what we're gonna do here is hello world so we imported em missed just one care us and just for demonstration purposes I'm gonna wrap it in a TF data data set so I'm creating a data set from tensor slices which is a fancy word which basically tells it that hey this is a list of things and I want every element in the list to be an item of my data set the next thing to do it has this very nice clean API I can say I also want you to shuffle the data here TF data is designed to work with potentially very long lists things and it could be an infinite stream of data you don't want to shuffle the whole stream so shuffle has a size for the buffer so I'm here I have a buffer of a thousand elements in I'm going to shuffle them as they stream in and then I can batch it up that means when I call this data set I'm gonna get back a batch of 32 things and so now I want to show you very briefly how do you use it so to use it what you can do and this is the complete code by the way you can just say like for images and labels print them out so this looks obvious to me and it's the way things should work but if you're new to tensorflow it didn't used to always work this way so if you have previous experience in tensorflow you can take a look and you notice nowhere in this code is there a session there's no placeholders I'm not mentioning the word graph I'm just writing regular Python code and the thing just works so this is eager execution in tensorflow 1/8 plus the only thing I have to do is the second line of code there it's just I enable the thing you need to do this at the start of the Python file or notebook and now you're basically running tensorflow eagerly which if you're starting out it's just regular Python and this is the right way to use tensorflow it makes debugging much easier there's lots of reasons why you would use graphs and we still love grass there's great talks from the tensorflow developer summit that will go into them in lots of detail but at least when you're hacking definitely definitely do this okay so for more context and all that I've been talking for a while you search element been handed over to points thanks everybody just quick survey the crowd how many software developers here I were at i/o so we figured it would have a few so that's good so I've just been working on tensorflow for a few months and I think for a getting started intensive well can be a little bit difficult if you're coming from a software dev background and getting started in any kind of ml can be a little bit tricky because there's so many new and different concepts first of all there's all the math right I mean I didn't even understand this math when I was in high school and now I have to understand it again you know people tell me about linear regressions and my head explodes but then you know it's learn herbal it's something that you can pick up but then secondly is really the programming model and what what is the programming model all about and I come from a background of traditional program and in traditional programming you basically you feed in the rules you feed in the data and you get answers out so for example if you're writing something like an activity detector am i walking am i running a my biking am i driving you know you'd feed in rules about that probably something based around the speed or I'm a very slow runner so it's detecting something going at one-and-a-half miles an hour you know it's detecting me is running but I know josh is a really fast runner and you know so would uh it would it would probably think he's on a bicycle if you're using my rules those kind of things you're feeding those data are feeding those rules in and this is what we've been doing for years as programmers but when it comes to machine learning you got to kind of flip the axis on this a little bit and change it to this so when it comes to machine learning this is all machine learning is you feed in the answers and your feed in the data and you get back to the rules so when you when we talk about training a model when we talk about like building these models what we're ending up getting is this binary blob that you can run inference on and this binary blob that your own inference on is effectively got those rules that will give them you know that will give what you need back out to you so for example in my example of activity detection you know if I walk a lot and tell it that I'm walking and it's measuring my sensor data when I'm walking and if I run a lot which would be really nice right and if I run a lot and like feed in the data and if I bike a lot and drive a lot and go on trains and go on airplanes you know these kind of things I'm feeding all this data and feeding the answers telling it okay right now I'm walking right now I'm biking right now I'm on an airplane then the idea behind machine learning is it will build that binary blob for me which I can then run inference on and by running inference on that then it's like okay what am i doing right now and it will deduce what I'm doing right now from all of these rules and so instead of me trying to write all this if then if then if then if then you know I train a system with data and with answers and it gives me back rules so let me give an example of this so what if we wanted to build something that would determine from a picture what's a cat and what's a dog okay now if I was doing this with if-then rules I could probably do something like you know if it loves you unconditionally no matter what you do it's probably a dog right and if it's right now plotting your murder it's probably a but right now it's really hard to infer that from images so III couldn't think of what the if-then rules would be he like sometimes like you might have an image say well if it's got pointy ears it's a cat but guess what this dog has pointy ears so you know this this is where we start thinking about this is where machine learning starts opening up these new scenarios and these new ways that you as a programmer can bring value to your employers and to your business so let's talk about the answers in this case okay so the answers here is like you know this is this is a cat right you know and this is a I think it's a dog right okay and this has got really pointy ears this little guy but this is clearly a cat this is a walking tongue but it's also a dog and this one is what happens if you feed a Mogwai after midnight I think but this is actually one of the dogs in this set of cats and dogs so like you know here you know I've got the data and here I'm giving the answers I'm telling the Machine what all of these things are so now if I want to do as a programmer all I have to do is train a neural network by giving it the answers we call them labels and giving it the data but as a programmer here's where it was tough for me and I've only very recently been on tensorflow because what is it you know first of all I have start working in Python any Python developers here a few of you it's a lovely language but you tend to work in a text editor instead of an IDE and things like step through debugging because I came from a background of like Visual Studio and Xcode and Android studio so it was a big learning curve for me to get into that and then with if you started tend to flow with graph based execution it was very strange because you'd have all your code would like load up a graph and then you would execute that graph and it's like but what if I've got bugs in like reading my data or if I'm not reading it properly or if I haven't shuffled the data properly and it's really important as Joshua's mentioning already want to shuffle your data properly or you can insert a bias into your actual training and I'm not a very good programmer so I generally like to write two or three lines of code at a time step through them make sure they work then write another two or three step through them make sure they work in that kind of thing and that was really difficult for me to do as a tensorflow developer so if we can switch the laptop I want to show why I'm really excited about eager mode and the screen saver kicked in sorry I'm just signing in so why I'm really excited about eager mode intensive flow is I've taken and Josh's written a notebook with this cats vs. dogs so you can go and get this code online and run it in the notebook but right now I'm running it in PyCharm because like I said I'm not a very good developer so I want to write a few lines of code execute them write another few lines of code and PyCharm if you're not familiar with there's a free community edition which is what I'm running here if you've used Android studio it probably looks very very familiar and what I can actually do is I can go in and I can say run debug all right and then I'm gonna go and I'm gonna debug and I'm gonna debug cats vs. dogs and it's gonna start executing and look I hit a breakpoint you know it's like this this to me is magical as a developer so now when I'm when I've hit my breakpoint I can start stepping through my code and see what's going on in my code so you know I'm gonna I've hit another breakpoint I've set another breakpoint down here so I'm gonna execute my code down to that breakpoints and now when I start stepping through this I can start seeing that I'm doing things correctly you know like okay my data directory is set up properly and I've defined my labels and you know I'm gonna put another break I'll leave that breakpoint there and I'll run down to this breakpoint and I can start looking at what's going on in here so I have my training images and if I hover over that you see it's like it's a little too big to print but when I look at this in the debugger I can now start seeing that look I've started loading up these arrays of images and I can see the image 0 here sorry if it's a little small but image 0 here was cat number 921 and so if I then keep stepping through and this is what eager execution is giving me whoops sorry I had a break I hit a breakpoint I didn't want ahead so I'm just gonna go down to here and continue running alright so and if I then step over this it should show me a cat okay so like okay I've gotten this cat I'm loading it in but is this the right cat you know have I written my code badly I have I got the wrong cat so I can go hey look you know here's my training data I can go look at my cats I can find cat number 921 and hopefully it's the same cat so I know my code is working right you know anybody else develop like this you like to do it in little steps oh good it's not just me cuz I find it really really difficult to write a lot of code in one sitting so I just got to do a baby step by baby step and cat number 921 is here and there it is it's the same cat so I'm like excellent I know my code is working I know them I know I'm loading properly from my data and I'll go through here and I can see you know my load image code what it's doing is it's reading the image it's creating a tensor out of that image it's resizing it to like a smaller image that we're gonna use in training and when you come from a world where like the hello world and machine learning is handwriting recognition you know for me hello world was s printf hello world you know that there's there's some very complicated scenarios it's very complex scenarios but this breaks it down as a developer and I can start poking through I can start looking at data in the IDE and I can understand really what's going on so what I'm gonna do is I'm just gonna exit code and execute my code a little more and it really have a really cool point about this too so this load image function if you look at it it's using TF operations so we're saying like tensorflow dot read image and these are working exactly like they would work if you were using numpy because we're running eagerly this code is imperative and it executes right after you hit the line also you'll notice when Laurence which is really cool hovered over it you can see the data you can see the data and not it's it's concrete not symbolic because we're running eagerly so and of course if you're you know in in Python you like to use the console as well one of the nice things in pycharm is that I've got a console window so if my existing code is printing out to the console I can do that I'm just gonna step a little bit further down and I want to go just to the training and one of the nice things that Josh was talking about is that this is just an iterator in Python and you know I can now step through and I can take a look at what's going on in my training I can look at this batch by batch so if I've got six thousands images that I'm loading in I've split that into smaller batches and then once I've done all of those batches that's an epoch so now I can just go through and I can look at my actual epochs and I can look at my training and I can step into it and I can see what's going on as I said great another quick point to to show you how fast these api's are evolving you'll notice that we're actually getting the numpy value of the images and the labels yeah as of I think a few days ago that's no longer necessary so you can fit Karos models using TF data data sets so you no longer need that intermediate staff which is great but thank goodness it still works yeah yeah and one of the really neat things about it of course is because tensorflow is open source if you want to know what's going on with your training maybe something is going maybe you've loaded data that's causing it to crash or something along those lines as you're doing this and as you're executing these things let's see if I can do it you know and I'm gonna hit pause at some points and I've now jumped into the tensorflow source code so not only can I step through my source to see what's going on I can actually jump into the tensorflow source so maybe I've done something to trigger a bug in tensorflow or maybe I'm doing something wrong and tensorflow isn't handling it properly and I can fix it and then contribute back to tensorflow so all of this has been made possible by eager execution in an intensive low at Python and as Josh mentioned all you got to do is use sense flow version 1.7 or later and set up that executing eagerly can we switch back to the slides now please yeah so cryptic error messages are mostly a thing of the past so your third promise Josh yes thank you very much thank you I liked PyCharm a lot I spent a long time in eclipse before yeah anyway so to learn more about these concepts so I'm gonna recommend two educational resources so first is we have a machine learning crash course it's pretty good it's short so this is probably maybe a day or two days of your time full-time this won't teach you all there is about ml but it's a very solid thoughtful introduction to what is lost what is gradient descent next I'd like to recommend a book which is by Googler and I'm gonna badly mispronounce his name but the author of chaos Francois Sholay it's a wonderful wonderful book it's called deep learning with Python there are many many books with very similar titles to deep learning with Python but the one you want is written by Francois it's published by Manning and it comes with a collection of Jupiter notebooks which are all freely available in github by the way that will basically teach you how to use chaos because chaos is part of tensorflow all of that code will work with no changes other than the imports directly in tensorflow and that will give you a really solid foundation in chaos and then later if you're interested you can learn how to use things like TF data and other features of tensorflow to do even more but it's a wonderful starting point so take away Oh another thing - so I wanted to also show tensorflow just in this but we only have 40 minutes with the chaos model you can literally do model dots save it's one line of code you'll save model dot save and like foo dot some path or whatever food at hd5 now you've saved your model to disk using tensorflow j s if you go to j s tensorflow dat org they have tutorials that show you how to import relatively easily that saved chaos model into the browser and so the same api is compatible across these platforms so basically links check out collab regardless of your using tensorflow or not collab is a really really valuable resource it's also wonderful in educational contexts you know if you're teaching after work or anything like that students can just jump right in check out the workshops in the next three months or so we're gonna be updating a lot of our tutorials intensive loaded org to use chaos but in the meantime I'm just hacking some samples together so you can see what this looks like ten so J s and we have an education some really fun demos on J a sense of like there's one where you can actually train it to recognize your face going left right up and down and then you play pac-man by going like this it's it's really good super cool yep so take a look and it's open source yeah so thank you very much everyone I know it's early we'll be around afterwards for as long as you want to take questions really appreciate your time and hope this stuff is useful to you thank you [Music]
Info
Channel: TensorFlow
Views: 218,195
Rating: undefined out of 5
Keywords: type: Conference Talk (Full production);, pr_pr: Google I/O, purpose: Educate
Id: tjsHSIG8I08
Channel Id: undefined
Length: 39min 29sec (2369 seconds)
Published: Wed May 09 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.