 Hello Lots of people Too much too much First of all, thanks Pavel for for the laptop mine is broken so thanks a lot Introduction to TensorFlow Okay, let's start with a question What is this? It's a cat that that was an easy question But is that easy for a computer, you know a computer is a machine that makes computations that things with mathematical operations so the real question is is there a mathematical relationship between this input an image of a cat and the target a class cat and The answer is yes But it's very complex and we're gonna learn these complex relationship using tons of examples and this learning a very complex relationship using tons of examples is a Fairly well first definition of deep learning and You know, we're here in Rimini It would have Python 2017 We love Python. So we want to make deep learning with Python and What is the best tool for that? It's TensorFlow So what is TensorFlow TensorFlow is an open-south library? for deep learning it's Mainly used in Python and it was released by the Google brain project two years ago and But the first that the one zero zero version was not launched until February of this year So installation quickly The best practice is to download anaconda and then create a new environment with the classic data science libraries and then their peep install TensorFlow For Windows is the same but without the source word, okay Concepts Now we enter the most important part of the talk the concepts because TensorFlow could be a Difficult tool for beginners if you don't understand the basic concepts of deep learning and How TensorFlow works? So Recall this we have the cat The image of a cat and we have the class cat and we want to find the mathematical relationship between these two that mathematical relationship we call it the model and This model is gonna make predictions Given the input sometimes at first is gonna be random predictions Sometimes you could say it's a cat and sometimes you could say It's a non cat Well, so we have the input the image of a cat and we have The model that is gonna make predictions given the input and we have the target That is the correct class for that image and The prediction should match the target, but it doesn't So what we what we're gonna do is to change the model So it gets better and the predictions match the target So the first step the first step for this is to compute the difference between the prediction and the target and this is gonna be done by the cost function or loss function and This cost function is gonna produce an error and this error is Like how far are we from having a good model? the the greater the error the greater we have to the more we have to Change the model So we're gonna learn from errors That's life Learning from errors sometimes you win and sometimes you learn and the guy finally the guy in In charge of changing the model of training the model is the optimizer Okay, so this is the basic the basic structure of Learning process in deep learning and this is what tensorflow calls the graph and the graph is just Layout which contains both the model and the learning the learning process Okay So the graph it's totally independent from the data But There is really there is really a connection with the data so Because the graph is nothing without data. We couldn't have predictions without input data and we couldn't have Learning without targets So we set two gates that aren't Gonna one gate is for the inputs and we're gonna get this for the targets and these gates are Gonna let the data to come in but not all types of data only the data that we want so in this case we want Images for inputs and classes for targets. These gates are called placeholders well quick summary of what a graph contains and Well, there is a greenboard there Variables because the model is just a set of variables and we're gonna vary these variables we're gonna change these variables to make the model beta and Keep this word of mine because tensorflow uses it Well, we have we have the graph With the placeholders, but we want the data to come into the graph. So what we do is to open tensorflow session and Well When we're in a tensorflow session, we say we're feeding the graph with data Okay, so example We have this cat this cat goes through the model and the model say it's a non cat and That's not correct. So the cost function say we have an error of 100 the optimizer reads this Error and say we need to train the model and we train the model Now the case we have the cat and the model says it's a cat So the cost is zero and the optimizer does nothing Well, that's That's the the main part of the of the talk, but we're gonna see several cases of use In order to Stay with the concepts, okay, learn the concepts better It couldn't be otherwise the the the first thing we're gonna do is a hello world Not really a hello world because we're not gonna print hello world. We're gonna have two integers and The first thing is to import tensorflow. There's the convention imported as TF and This is the graph. We're gonna build We have two placeholders one for one integer and the other for the other integer and the addition operation So The end this is the code we said the placeholders that it's gonna expect integers and we have the The addition operation that is like a function of tensorflow And that's the graph and independently. There's the data We have number one is three number two that is eight And this is the session the session is something that you open and you close So we use the weave keyword and we we're gonna run The the sum operation now we're gonna feed the graph Feed with a dictionary that links each placeholders with each data So this is the output for a jupyter notebook and we see how it works Three and eight is 11. So perfect But this is kind of boring because we're not learning How can we make this thing more interesting? The next case is gonna be a regression problem and in you know, you're in a regression problems when your outputs are Not classes like CAD dogfish You have up to the there are numbers like two minus three 6.7 number pi square root of two that kind of thing and Our case is to learn how to sum so what we're gonna do is to Take two inputs and an output and we're gonna Learn the mathematical relationship Using ten thousand examples so these are the examples and We can see clearly that The first that they integrate some up to 13 So we see where we are seeing the relationship So this is kind of silly but You know in a regression problem, you always have the same philosophy. So we're now learning how to sum bad Say we are in a self-driving car The first input would be like an image taken from the camera in front of the vehicle and The second input would be the distance taken from a laser in front of the vehicle and the output is the angle You need to steer the vehicle to not crash or not Get out of the lane But we're gonna keep with a vision example So what we're gonna assume is that the relationship between the output and the input is the It's a linear function. That is an addition and a multiplication so these are the variables we're gonna learn we're gonna We're gonna be changing this variable. So it gets better and in this case, we're okay with a linear function, but if we Wanted to learn a more complex relationship. We just have to Have another linear function at another layer and if we wanted to Make it even more complex We stack another layer and if we want to make it even more complex We have non-linear functions or activation functions. So that's a neural network Okay easy Well, it's the code we said the placeholders we're expecting floats and We're expecting two numbers two integers for the inputs and one for the output and The known is because we don't know How many examples are we gonna receive? So we don't restrict the number Okay, the model is yes the two variables. We initialize it and randomly and We make the linear function with a multiplication and the addition Well, so we have the placeholders and we have the model next thing is the cash function the cash function computes the difference between the prediction and the and the target so the most intuitive thing is to make the difference and But what we're gonna do is to Get rid of negative numbers. So we square it all and then we Sum it all some all the examples all the all the arrows from all the examples and reduce it to one number Okay, so this is the code we need we Square it with make the difference a square it and reduce the sum Well, let's say that our cost function is can be plotted like this and and well the the The high of the red things that are more error and the down peak is the minimum we want to reach What we're gonna do is let's say we have an Error of 10 and we're gonna get down to the Down peak so we're gonna take the Direction of maximum steep there is a gradient and we follow that direction Again and again until we reach the minimum This is the coat and so flow gives you a model of gradient descent and there is a hyper parameter There is learning rate and that is like the module of the arrow so you could you could have a graded arrow and then you You could reach the minimum faster But maybe you pass by the minimum and you oscillate by the minimum even going unstable and if you have a An arrow that is smaller. Maybe you don't reach the minimum because it's too slow Okay, we minimize the cost and We have it all That we need the data what we're gonna do with the data is typical of machine learning that is You split the data in two one for training and one for testing and the training is what we're gonna use So I built helper functions for these so we don't have to bother off about the data. That's for another talk and The session Okay In the session we're gonna feed the graph with the training data so let's do it first thing we Start an initializer of the variables and then we run the optimizer running the optimizer. You're gonna learn and we Feed it with the training the training data and we run all the training data a lot of times that When you run the data one time you say that's an apple so we have this for loop that's gonna Train the the neural network Numbers of time Okay, that's that's the apple and we see that we have an accuracy of 95% and then the sum of five plus seven is Almost 12 but if we take a look to the weights That's not a sum a sum is yes one one and the bias zero That means that we have Overfitted the neural network to just make good summation for our data Okay, now a classification problem in a classification problem You're not gonna use numbers you're gonna use classes so We have a we have a cat. They could be a class cat We have another thing that could be a class non-cat that cat and non-cat are words We don't work with work. We don't work with words. So we yes transform it Transform in a way that a class is a component of an array in this case a cat is Like the second component of the array and the non-cat is the first component of the array This is called one holding coding and these zero one one zero is just for targets But what could be our predictions our predictions could be? probabilities and Sometimes the model is gonna be very sure that the That the input belongs to a certain class in this case We have the cat that in the model is 80 82% sure that it's a cat but sometimes we're not gonna be that sure But the summation is gonna be one Okay And well our case now it's gonna be Learn We have two integers. We're gonna sum it and we're gonna classify it if they are Greater than 10 or a lesser than 10 if they're greater We're gonna say that Belongs to the second class and they are lesser. It's gonna belong to the first class. This is a silly example But it works and it's it's good for learning. So these Relationship is more complex than the than than the before so We need all the layer and interestingly the first layer is gonna compute the sum and the second layer is gonna Classify that sum into greater than 10 or lesser than 10 and This is gonna happen always in all classification problems the first layers are gonna Extract more basic fixtures more basic information and the next layers are gonna work With these basic information to produce even more complex information So I am with we stack a softmax and Nonlinear function at the end because we want that the output Are probabilities that sum up to one? So, okay, we have build the model and in this case in the cost function We're not gonna use The cost function of before we're gonna use a cross entropy cost function And that is beyond of this talk and the optimizer we're gonna use better optimizer is Adam optimizer that Works a little better because It goes changing the learning rate. You don't so at first it's gonna be a big learning rate and then it's gonna be smaller So these are the results we have Testing accuracy of 100s. That's that's bad. We have done something bad, but but it works five plus three is the model is 89% that is lesser than 10 and 7 plus 6 it's 87% that is Sure, that is greater than 10 and the same for 10 plus 10 and We we see how in the first layer. It's like a sum Bad, it's with a negative and in the second layer It's the same number in the weight, but with a negative in one of them that that's gonna classify the output of the of the first layer so Okay, that's all bad if you want to know more I Recommend you to Follow the neural networks and deep learning book from Mike and Nielsen and they stands for CS 2 3 1 and from Andrea Karpathy You're gonna learn a lot And for tensorflow There's a lot of tutorials about tensorflow, but I thought that they missed the basics. That's why I did this talk Okay, if you like me Last year and you didn't know nothing about Data, so let's start with this and you're gonna be Improving Well, that's where It's all the code there is It's a work in progress. I'm learning Because I am a robotics engineer and my goal is to combine the robotics with artificial intelligence And so if you are in this field, just talk to me and and we'll be best friends And that my favorite combination is self-driving cars. So I hope that you could build the self-driving cars. Yes with tensorflow and Using the basics that I've give and gave you You're gonna improve and improve and build the self-driving car. Okay. Thank you Thank you, Alejandro. Are there any questions, please raise your hand Thank you. Can you show that previous slide with the repository, please? again our Previous one. Yes Anyone else I don't thank you for the nice talk How much that we actually need to do a decent training? I mean training It's really dependent on what you have on how we can build it How much that I should we feed it to provide something useful if there is any clear answer on that How much data you do I need how much of the training process would we have to do up to the point? That's actually something useful rather than just a simple algorithm So how much data do I need to make something useful? Yeah, so there is any kind line. Yeah, you're gonna need Tons of data it depends on the application Well, there's a cool graph then in which you see that machine learning machine learning algorithms works Way better than deep learning algorithms when you have a Small data and when you have tons of data like terabytes of data for images Terabytes of data for sound then deep learning is way better than machine learning and it's gonna do Impressive things Yeah, good. Thanks for the incredible talk. I wanted to ask Whether you have any comments about comparing tensorflow to Tiano for example That's one question and the next one is there are so many meta libraries Which built on top of tensorflow like Keras or something which provide people with an easier interface to do sort of do a regression Would you comment on when to use tensorflow versus such a meta library like Keras? Wait, can you please take the microphone? Not audible. Sorry. So the first one was How would you compare tensorflow to Tiano? Do you know Tiano? It was yes Well, I haven't worked with Tiano, but Well, they say that Tiano is more you can be it's more low level. So you can be more creative if it's more like Yes more low level is mouth is much for scientists Maybe let me ask you this what made you make this presentation as an introduction to tensorflow and not an introduction to Tiano What what what made this presentation an introduction to tensorflow versus an introduction to something else Like what made you choose tensorflow over the other other things? I Can understand what's the question? Nevermind. It's okay Thank you Well because it's cool It's it's from Google and and well Google maintains maintains Great. Yeah, they're projects Anybody else? question No, okay, so thank you again very much