Thursday, July 9, 2020
TensorFlow Tutorial
TensorFlow Tutorial TensorFlow Tutorial Deep Learning Using TensorFlow Back Home Categories Online Courses Mock Interviews Webinars NEW Community Write for Us Categories Artificial Intelligence AI vs Machine Learning vs Deep LearningMachine Learning AlgorithmsArtificial Intelligence TutorialWhat is Deep LearningDeep Learning TutorialInstall TensorFlowDeep Learning with PythonBackpropagationTensorFlow TutorialConvolutional Neural Network TutorialVIEW ALL BI and Visualization What is TableauTableau TutorialTableau Interview QuestionsWhat is InformaticaInformatica Interview QuestionsPower BI TutorialPower BI Interview QuestionsOLTP vs OLAPQlikView TutorialAdvanced Excel Formulas TutorialVIEW ALL Big Data What is HadoopHadoop ArchitectureHadoop TutorialHadoop Interview QuestionsHadoop EcosystemData Science vs Big Data vs Data AnalyticsWhat is Big DataMapReduce TutorialPig TutorialSpark TutorialSpark Interview QuestionsBig Data TutorialHive TutorialVIEW ALL Blockchain Blockchain TutorialWhat is BlockchainHyperledger FabricWhat Is EthereumEthereum TutorialB lockchain ApplicationsSolidity TutorialBlockchain ProgrammingHow Blockchain WorksVIEW ALL Cloud Computing What is AWSAWS TutorialAWS CertificationAzure Interview QuestionsAzure TutorialWhat Is Cloud ComputingWhat Is SalesforceIoT TutorialSalesforce TutorialSalesforce Interview QuestionsVIEW ALL Cyber Security Cloud SecurityWhat is CryptographyNmap TutorialSQL Injection AttacksHow To Install Kali LinuxHow to become an Ethical Hacker?Footprinting in Ethical HackingNetwork Scanning for Ethical HackingARP SpoofingApplication SecurityVIEW ALL Data Science Python Pandas TutorialWhat is Machine LearningMachine Learning TutorialMachine Learning ProjectsMachine Learning Interview QuestionsWhat Is Data ScienceSAS TutorialR TutorialData Science ProjectsHow to become a data scientistData Science Interview QuestionsData Scientist SalaryVIEW ALL Data Warehousing and ETL What is Data WarehouseDimension Table in Data WarehousingData Warehousing Interview QuestionsData warehouse architectureTalend T utorialTalend ETL ToolTalend Interview QuestionsFact Table and its TypesInformatica TransformationsInformatica TutorialVIEW ALL Databases What is MySQLMySQL Data TypesSQL JoinsSQL Data TypesWhat is MongoDBMongoDB Interview QuestionsMySQL TutorialSQL Interview QuestionsSQL CommandsMySQL Interview QuestionsVIEW ALL DevOps What is DevOpsDevOps vs AgileDevOps ToolsDevOps TutorialHow To Become A DevOps EngineerDevOps Interview QuestionsWhat Is DockerDocker TutorialDocker Interview QuestionsWhat Is ChefWhat Is KubernetesKubernetes TutorialVIEW ALL Front End Web Development What is JavaScript â" All You Need To Know About JavaScriptJavaScript TutorialJavaScript Interview QuestionsJavaScript FrameworksAngular TutorialAngular Interview QuestionsWhat is REST API?React TutorialReact vs AngularjQuery TutorialNode TutorialReact Interview QuestionsVIEW ALL Mobile Development Android TutorialAndroid Interview QuestionsAndroid ArchitectureAndroid SQLite DatabaseProgramming De... TensorFlow Certif ication Training (41 Blogs) Become a Certified Professional AWS Global Infrastructure Introduction to Artificial Intelligence Artificial Intelligence â" What It Is And How Is It Useful?Artificial Intelligence Tutorial : All you need to know about AIArtificial Intelligence Algorithms: All you need to knowTypes Of Artificial Intelligence You Should KnowWhat are the Advantages and Disadvantages of Artificial Intelligence?AI Applications: Top 10 Real World Artificial Intelligence ApplicationsImplementing Artificial Intelligence In HealthcareTop 10 Benefits Of Artificial IntelligenceHow to Become an Artificial Intelligence Engineer? A Roadmap to the FutureTop 12 Artificial Intelligence Tools Frameworks you need to knowAI vs Machine Learning vs Deep LearningA Comprehensive Guide To Artificial Intelligence With Python Introduction to Deep Learning What is Deep Learning? Getting Started With Deep LearningDeep Learning with Python : Beginners Guide to Deep LearningWhat Is A Neural N etwork? Introduction To Artificial Neural NetworksDeep Learning Tutorial : Artificial Intelligence Using Deep LearningPyTorch vs TensorFlow: Which Is The Better Framework? Neural Networks Deep Learning : Perceptron Learning AlgorithmNeural Network Tutorial â" Multi Layer PerceptronBackpropagation â" Algorithm For Training A Neural Network Tensorflow A Step By Step Guide to Install TensorFlowTensorFlow Tutorial â" Deep Learning Using TensorFlowConvolutional Neural Network Tutorial (CNN) â" Developing An Image Classifier In Python Using TensorFlowCapsule Neural Networks â" Set of Nested Neural LayersObject Detection Tutorial in TensorFlow: Real-Time Object DetectionTensorFlow Image Classification : All you need to know about Building ClassifiersRecurrent Neural Networks (RNN) Tutorial | Analyzing Sequential Data Using TensorFlow In Python Dimensionality Reduction Autoencoders Tutorial : A Beginner's Guide to AutoencodersRestricted Boltzmann Machine Tutorial â" Introduction to Deep Learning Concepts Most Frequently Asked Artificial Intelligence Interview Questions Artificial Intelligence Topics CoveredMachine Learning with Mahout (7 Blogs)TensorFlow Certification Training (39 Blogs)Artificial Intelligence and Machine Learning (19 Blogs)SEE MORE TensorFlow Tutorial Deep Learning Using TensorFlow Last updated on May 22,2019 25.5K Views Ashish Bakshi Bookmark 2 / 7 Blog from Tensorflow Become a Certified Professional I have designed this TensorFlow tutorial for professionals and enthusiasts who are interested in applying Deep Learning Algorithm using TensorFlow to solve various problems.TensorFlow is an open source deep learning library that is based onthe concept of data flow graphs forbuilding models. It allows youto create large-scale neural networks with many layers. Learning the use of this library is also a fundamental part of the AI Deep Learning course curriculum.Following are the topics that will be discussed in this TensorFlow tutoria l blog:What is TensorFlowTensorFlow Code BasicsTensorFlow UseCaseWhat are Tensors?In this TensorFlow tutorial, before talking about TensorFlow, let us first understand what are tensors. Tensors are nothing but a de facto for representing the data in deep learning.As shown in the image above, tensors are just multidimensional arrays, that allows you to representdata havinghigher dimensions. In general, Deep Learning you deal with high dimensional data sets where dimensions refer to different features present in the data set. In fact, the name TensorFlow has been derived from the operations which neural networks perform on tensors. Its literally a flow of tensors. Since,you have understood what are tensors, let us move ahead in this TensorFlow tutorial and understand what is TensorFlow?What is TensorFlow?TensorFlow is a library based on Python that provides different types of functionality for implementing Deep Learning Models. As discussed earlier, the term TensorFlow ismade up of t wo terms Tensor Flow:In TensorFlow, the term tensor refers to the representation of data as multi-dimensional array whereas the term flow refers to the series of operations that one performs on tensors as shown in the above image.Now we have covered enough background about TensorFlow.Next up, in this TensorFlow tutorial we will be discussing about TensorFlow code-basics.TensorFlow Tutorial: Code BasicsBasically, the overall process of writing a TensorFlow program involves two steps:Building a Computational GraphRunning a Computational GraphLet me explain you the above two steps one by one:1. Building a Computational GraphSo, what is a computational graph? Well, a computational graph is aseries of TensorFlow operations arranged asnodes in the graph. Each nodes take 0 or more tensors as input and produces a tensor as output. Let me give you anexample of a simple computational graph which consists of three nodes a, b c as shown below:Explanation of the Above Computational Graph:Con stant nodesareused to store constant values as it takes zero input, but produces the stored values as output. In the above example, aand b are constant nodes with values 5 and 6 respectively.The node c represents the operation of multiplying constant node a withb. Therefore, executing node c will result in multiplication of const node a b.Basically, one can think of a computational graph as analternative way ofconceptualizing mathematical calculations that takes place in a TensorFlow program. The operations assigned to different nodes of a Computational Graph can be performedin parallel, thus, providing a better performance in terms of computations.Here we just describe the computation, it doesnt compute anything, it does not hold any values, it just defines the operations specified in your code.2. Running a Computational GraphLet us take the previous example of computational graph and understand how to execute it. Following is the code from previous example:Example 1: import tensorflow as tf # Build a graph a = tf.constant(5.0) b = tf.constant(6.0) c = a * b Now, in order to get the output of node c, we need to run the computational graph within asession. Sessionplaces the graph operations ontoDevices, such as CPUs or GPUs, and provides methods to execute them.A session encapsulates the control and state of the TensorFlow runtime i.e. it storesthe information about the order in which all the operations will beperformed and passes the resultof already computed operation to the next operation in the pipeline. Let me show you how to run the above computational graph within a session (Explanation of each line of code has been added as a comment): # Create the session object sess = tf.Session() #Run the graph within a session and store the output to a variable output_c = sess.run(c) #Print the output of node c print(output_c) #Close the session to free up some resources sess.close() Output: 30So, this was all about session and running a computational graph within it. Now, let us talk about variables and placeholders that we will be using extensively while building deep learning model usingTensorFlow.Constants, Placeholder and VariablesIn TensorFlow, constants, placeholders and variables are used to represent different parameters of a deep learning model. Since, Ihave already discussed constants earlier, I willstart with placeholders.Placeholder:ATensorFlow constant allows youto store a valuebut, what if, you want your nodes to take inputs on the run? For this kind of functionality, placeholders are used which allows your graph to take external inputs as parameters. Basically, a placeholder is a promise to provide a value later or during runtime. Let me give you an example to make things simpler: import tensorflow as tf # Creating placeholders a = tf. placeholder(tf.float32) b = tf. placeholder(tf.float32) # Assigning multiplication operation w.r.t. a amp;amp; b to node mul mul = a*b # Create session object sess = tf.Session() # Executing mul by passing the values [1, 3] [2, 4] for a and b respectively output = sess.run(mul, {a: [1,3], b: [2, 4]}) print('Multiplying a b:', output) Output: [2. 12.]Points to Remember about placeholders:Placeholders are not initialized and contains no data.One must provides inputs or feeds to the placeholder which are considered during runtime.Executing a placeholder without input generates an error.Now, let us move ahead and understand what are variables?VariablesIn deep learning, placeholders are used totake arbitrary inputs in your model or graph. Apart from taking input, you also needto modify the graph such thatit can produce new outputs w.r.t. same inputs. For this youwill be using variables. In a nutshell, a variable allows you to add such parameters or node to the graph that are trainable i.e. the value can be modified over the period of a time. Variables are defined by providing their initial value and type as shown below: var = tf.Variable( [0.4], dtype = tf.float32 ) Note: In case you have not provided the data type explicitly, TensorFlow will infer the type of the constant/variable from the initialized value.TensorFlow has many of its own data types liketf.float32,tf.int32etc. You may refer to all of them overhere.Constants are initialized when you call tf.constant, and their value can never change. On the contrary, variables are not initialized when you call tf.Variable. To initialize all the variables in a TensorFlow program, you must explicitly call a special operation as shown below: init = tf.global_variables_initializer() sess.run(init) Always remember that a variable must be initialized before a graph is used for the first time.Note: TensorFlow variables are in-memory buffers that contain tensors, but unlike normal tensors that are only instantiated when a graph is run and are immediately deletedafterwards, variables survive across multiple executions of a graph. Now that we have covered enough basics of TensorFlow, let us go ahead and understand how to implement a linear regression model using TensorFlow.Linear Regression Model Using TensorFlowLinear Regression Model isused for predicting the unknown value of a variable (Dependent Variable) from the known value of another variables (Independent Variable) using linear regression equation as shown below:Therefore, for creating a linear model, you need:Dependent or Output Variable (Y)Slope Variable (w)Y Intercept or Bias (b)Independent or Input Variable (X)So, let us begin building linear model using TensorFlow:Copy the code by clicking the button given below: # Creating variable for parameter slope (W) with initial value as 0.4 W = tf.Variable([.4], tf.float32) #Creating variable for parameter bias (b) with initial value as -0.4 b = tf.Variable([-0.4], tf.float32) # Creating placeholders for providing input or independent variable, denoted by x x = tf.placeholder(tf.float32) # Equation of Linear Regression linear_model = W * x + b # Initializing all the variables sess = tf.Session() init = tf.global_variables_initializer() sess.run(init) # Running regression model to calculate the output w.r.t. to provided x values print(sess.run(linear_model {x: [1, 2, 3, 4]})) Output: [ 0. 0.40000001 0.80000007 1.20000005] The above stated code just represents the basic idea behind the implementation of regression model i.e. how youfollow the equation of regression line so as to get output w.r.t. a set of input values. But, there are two more things left to be added in this model to make ita complete regression model:First, we need to provide a mechanism by which our model can train itself automatically based on givenset of inputs and respective outputs.Second thing that we need is to validate our trained model by comparing its output with the desired or target output based on given set of x values.Now let us understand how can I incorporatethe above stated functionalities into mycode for regression model.Loss Function Model ValidationA loss function measures how far apart the current output of the model is from that of the desired or target output. Ill use a most commonly usedloss functionfor my linear regression model called as Sum of Squared Error or SSE. SSE calculated w.r.t. model output (represe nt by linear_model) and desired or target output (y) as: y = tf.placeholder(tf.float32) error = linear_model - y squared_errors = tf.square(error) loss = tf.reduce_sum(squared_errors) print(sess.run(loss, {x:[1,2,3,4], y:[2, 4, 6, 8]}) Output: 90.24As you can see, we are getting a high loss value. Therefore, we need to adjust our weights (W) and bias (b) so as to reduce the error that we are receiving.tf.train API Training the ModelTensorFlow provides optimizers that slowly change each variable in order to minimize the loss function or error. The simplest optimizer is gradient descent. It modifies each variable according to the magnitude of the derivative of loss with respect to that variable. #Creating an instance of gradient descent optimizer optimizer = tf.train.GradientDescentOptimizer(0.01) train = optimizer.minimize(loss) for i in range(1000): sess.run(train, {x:[1, 2, 3, 4], y:[2, 4, 6, 8]}) print(sess.run([W, b])) Output: [array([ 1.99999964], dtype=float32), array([ 9.86305167e-07], dtype=float32)]So, this is how you create a linear model using TensorFlow and train it to get the desired output.Now that you know about Deep Learning, check out theDeep Learning with TensorFlowTrainingby Edureka,a trusted online learning companywith a network of more than250,000satisfied learnersspread acrossthe globe. The Edureka Deep Learning with TensorFlow Certification Training coursehelps learners becomeexpert in training and optimizing basic and convolutional neural networks using real time projects and assignments along with concepts such as SoftMax function, Auto-encoder Neural Networks, Restricted Boltzmann Machine (RBM).Got a question for us? Please mention it in the comments section and we will get back to you.Recommended videos for you Introduction to Mahout Watch Now Deep Learning Tutorial Deep Learning With TensorFlow Watch Now What Is Deep Learning Deep Learning Simplified Watch NowRecommended blogs fo r you Top 10 Data Scientists Myths Regarding Roles in India Read Article All You Need To Know About The Breadth First Search Algorithm Read Article What is Production System in Artificial Intelligence? Read Article What is Cognitive AI? Is It the Future? Read Article Artificial Intelligence Algorithms: All you need to know Read Article What Is A Neural Network? Introduction To Artificial Neural Networks Read Article A Comprehensive Guide To Artificial Intelligence With Python Read Article TensorFlow Image Classification : All you need to know about Building Classifiers Read Article Top 10 Machine Learning Tools You Need to Know About Read Article AI in Wimbledon: Power Highlights, Analytics and Insights Read Article An Introduction to Hill Climbing Algorithm Read Article Deep Learning : Perceptron Learning Algorithm Read Article Backpropagation Algorithm For Training A Neural Network Read Article ARTIFICIAL INTELLIGENCE : BOON or BANE? Everything You Need to Know Read Article Fuzzy K-Means Clustering in Mahout Read Article Recurrent Neural Networks (RNN) Tutorial | Analyzing Sequential Data Using TensorFlow In Python Read Article Convolutional Neural Network Tutorial (CNN) Developing An Image Classifier In Python Using TensorFlow Read Article Deep Learning Tutorial : Artificial Intelligence Using Deep Learning Read Article Most Frequently Asked Artificial Intelligence Interview Questions Read Article What is Fuzzy Logic in AI and What are its Applications? Read Article Comments 0 Comments Trending Courses in Artificial Intelligence AI Deep Learning with TensorFlow18k Enrolled LearnersWeekendLive Class Reviews 5 (7000)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.