SlideShare a Scribd company logo
1 of 13
TENSORFLOW
Building a Graph
■ Start with ops that do not need any input (source ops), Constant
import tensorflow as tf
matrix1 = tf.constant([[3,3]])
matrix2 = tf.constant([[6],[6]])
product=tf.matmul(matrix1,matrix2)
print(product) # O/pTensor("MatMul_1:0", shape=(1, 1), dtype=int32)
sess=tf.Session()
result=sess.run(product)
print(result) #O/P [[36]]
sess.close()
■ You will see difference in o/p in both the print statement. First statement just tells us about the Product
tensor property . Second statement is under a session. Graph gets executed thus the print shows the
value of the tensor.
matrix1 matrix2
OP:
MatMul
result
Tensors
■ As we have seen how a basic tensorflow works, lets dig deeper onTensors
■ n-dimensional array
■ 0-d tensor: scalar (number) ,1-d tensor: vector 2-d, tensor: matrix etc etc.
■ tf.Variable is a class, but tf.constant is an op
Graphs
■ It represents computations.
import tensorflow as tf
a = tf.add(3, 5)
■ TF automatically names the nodes when you don’t explicitly name
them.
x = 3
y = 5
■ Edge: Tensors ie data
■ Node: operators, variables, and constants
■ If we simply print(a), output will be tensor object and not 8.To
fetch the value of it in a, we need to run the session.
■ The session will look at the graph, trying to think: how can I get
the value of a, then it computes all the nodes that leads to a.
x
y
Ad
d
x
y
a
Interpret
ation
3
5
Add
Session
x
y
a
3
5
Add
8
But why only graphs?
■ Save computation (only run subgraphs that lead to the values you want to fetch)
■ Break computation into small, differential pieces to facilitates auto-differentiation
■ Facilitate distributed computation, spread the work across multiple CPUs, GPUs, or
devices
■ Many common machine learning models are commonly taught and visualized as
directed graphs already
Sessions
■ A Session object encapsulates the environment in which
Operation objects are executed, andTensor objects are
evaluated.
x = 2
y = 3
add_op = tf.add(x, y)
mul_op = tf.mul(x, y)
useless = tf.mul(x, add_op)
pow_op = tf.pow(add_op, mul_op)
with tf.Session() as sess:
z = sess.run(pow_op)
Because we only want the value of pow_op and pow_op doesn’t
depend on useless, session won’t compute value of useless → save
computation
Operations
Its very similar to numpy. In terms of data type,TensorFlow integrates seamlessly with NumPy. If the
requested fetch is aTensor , then the output of will be a NumPy ndarray. Beware when using NumPy arrays
because NumPy andTensorFlow might become not so compatible in the future!
Tensor Board
■ Help a lot when you build complicated models
■ To useTensor Board
I. Go to terminal
II. run: $ python [yourprogram].py
III. $ tensorboard --logdir="./graphs" --port 6006
IV. Then open your browser and go to:
http://localhost:6006/
Example ofTensor Board
import tensorflow as tf
matrix1 = tf.constant([[3,3]])
matrix2 = tf.constant([[6],[6]])
product=tf.matmul(matrix1,matrix2)
print(product)
sess=tf.Session()
writer = tf.summary.FileWriter("./graphs", sess.graph)
result=sess.run(product)
print(result)
sess.close()
I don’t like const, How to explicitly name
them
import tensorflow as tf
matrix1 = tf.constant([[3,3]], name="a")
matrix2 = tf.constant([[6],[6]], name="b")
product=tf.matmul(matrix1,matrix2)
print(product)
sess=tf.Session()
writer = tf.summary.FileWriter("./graphs", sess.graph)
result=sess.run(product)
print(result)
sess.close()
Key Notes
■ Graph execution is done across all available compute resources, such as CPU or GPU. If
you have GPU,TensorFlow uses your first GPU
■ TensorFlow separates definition of computations from their execution
■ Only use constants for primitive types. Constants are stored in graph’s definition.This makes
loading graphs expensive when constants are big. Use variables or readers for more data that
requires more memory.
Test yourTensor flow knowledge
Graphs Sessions Tensors Variables Nodes

More Related Content

What's hot

Tensorflowで五目並べの思考アルゴリズムを作る
Tensorflowで五目並べの思考アルゴリズムを作るTensorflowで五目並べの思考アルゴリズムを作る
Tensorflowで五目並べの思考アルゴリズムを作るjugemjugemjugem
 
Matlab plotting
Matlab plottingMatlab plotting
Matlab plottingpink1710
 
The TensorFlow dance craze
The TensorFlow dance crazeThe TensorFlow dance craze
The TensorFlow dance crazeGabriel Hamilton
 
Matplotlib 簡介與使用
Matplotlib 簡介與使用Matplotlib 簡介與使用
Matplotlib 簡介與使用Vic Yang
 
#OOP_D_ITS - 3rd - Pointer And References
#OOP_D_ITS - 3rd - Pointer And References#OOP_D_ITS - 3rd - Pointer And References
#OOP_D_ITS - 3rd - Pointer And ReferencesHadziq Fabroyir
 
Theano vs TensorFlow | Edureka
Theano vs TensorFlow | EdurekaTheano vs TensorFlow | Edureka
Theano vs TensorFlow | EdurekaEdureka!
 
Actividad 3 - Unidad 2 - Niveyro - Alarcon
Actividad 3 - Unidad 2 - Niveyro - AlarconActividad 3 - Unidad 2 - Niveyro - Alarcon
Actividad 3 - Unidad 2 - Niveyro - AlarconGuillermo Niveyro
 
機械学習によるデータ分析 実践編
機械学習によるデータ分析 実践編機械学習によるデータ分析 実践編
機械学習によるデータ分析 実践編Ryota Kamoshida
 
The matplotlib Library
The matplotlib LibraryThe matplotlib Library
The matplotlib LibraryHaim Michael
 
Simone Scardapane - Bring your neural networks to the browser with TF.js! - C...
Simone Scardapane - Bring your neural networks to the browser with TF.js! - C...Simone Scardapane - Bring your neural networks to the browser with TF.js! - C...
Simone Scardapane - Bring your neural networks to the browser with TF.js! - C...Codemotion
 
Malloc() and calloc() in c
Malloc() and calloc() in cMalloc() and calloc() in c
Malloc() and calloc() in cMahesh Tibrewal
 
Tensorflow windows installation
Tensorflow windows installationTensorflow windows installation
Tensorflow windows installationmarwa Ayad Mohamed
 
Introduction to programming class 11 exercises
Introduction to programming   class 11 exercisesIntroduction to programming   class 11 exercises
Introduction to programming class 11 exercisesPaul Brebner
 
computer notes - Data Structures - 38
computer notes - Data Structures - 38computer notes - Data Structures - 38
computer notes - Data Structures - 38ecomputernotes
 

What's hot (20)

Tensorflowで五目並べの思考アルゴリズムを作る
Tensorflowで五目並べの思考アルゴリズムを作るTensorflowで五目並べの思考アルゴリズムを作る
Tensorflowで五目並べの思考アルゴリズムを作る
 
Matplotlib
MatplotlibMatplotlib
Matplotlib
 
Matlab plotting
Matlab plottingMatlab plotting
Matlab plotting
 
The TensorFlow dance craze
The TensorFlow dance crazeThe TensorFlow dance craze
The TensorFlow dance craze
 
Matplotlib 簡介與使用
Matplotlib 簡介與使用Matplotlib 簡介與使用
Matplotlib 簡介與使用
 
Demo1 use numpy
Demo1 use numpyDemo1 use numpy
Demo1 use numpy
 
#OOP_D_ITS - 3rd - Pointer And References
#OOP_D_ITS - 3rd - Pointer And References#OOP_D_ITS - 3rd - Pointer And References
#OOP_D_ITS - 3rd - Pointer And References
 
Theano vs TensorFlow | Edureka
Theano vs TensorFlow | EdurekaTheano vs TensorFlow | Edureka
Theano vs TensorFlow | Edureka
 
Actividad 3 - Unidad 2 - Niveyro - Alarcon
Actividad 3 - Unidad 2 - Niveyro - AlarconActividad 3 - Unidad 2 - Niveyro - Alarcon
Actividad 3 - Unidad 2 - Niveyro - Alarcon
 
機械学習によるデータ分析 実践編
機械学習によるデータ分析 実践編機械学習によるデータ分析 実践編
機械学習によるデータ分析 実践編
 
The matplotlib Library
The matplotlib LibraryThe matplotlib Library
The matplotlib Library
 
Simone Scardapane - Bring your neural networks to the browser with TF.js! - C...
Simone Scardapane - Bring your neural networks to the browser with TF.js! - C...Simone Scardapane - Bring your neural networks to the browser with TF.js! - C...
Simone Scardapane - Bring your neural networks to the browser with TF.js! - C...
 
Malloc() and calloc() in c
Malloc() and calloc() in cMalloc() and calloc() in c
Malloc() and calloc() in c
 
Tensorflow windows installation
Tensorflow windows installationTensorflow windows installation
Tensorflow windows installation
 
Introduction to programming class 11 exercises
Introduction to programming   class 11 exercisesIntroduction to programming   class 11 exercises
Introduction to programming class 11 exercises
 
computer notes - Data Structures - 38
computer notes - Data Structures - 38computer notes - Data Structures - 38
computer notes - Data Structures - 38
 
Matlab integration
Matlab integrationMatlab integration
Matlab integration
 
Dft2
Dft2Dft2
Dft2
 
Lecture 1 mte 407
Lecture 1 mte 407Lecture 1 mte 407
Lecture 1 mte 407
 
Lecture 1 mte 407
Lecture 1 mte 407Lecture 1 mte 407
Lecture 1 mte 407
 

Similar to Tensorflow basics

Introduction to TensorFlow 2
Introduction to TensorFlow 2Introduction to TensorFlow 2
Introduction to TensorFlow 2Oswald Campesato
 
Introduction to TensorFlow 2 and Keras
Introduction to TensorFlow 2 and KerasIntroduction to TensorFlow 2 and Keras
Introduction to TensorFlow 2 and KerasOswald Campesato
 
Introduction To TensorFlow | Deep Learning Using TensorFlow | CloudxLab
Introduction To TensorFlow | Deep Learning Using TensorFlow | CloudxLabIntroduction To TensorFlow | Deep Learning Using TensorFlow | CloudxLab
Introduction To TensorFlow | Deep Learning Using TensorFlow | CloudxLabCloudxLab
 
Advanced Spark and TensorFlow Meetup May 26, 2016
Advanced Spark and TensorFlow Meetup May 26, 2016Advanced Spark and TensorFlow Meetup May 26, 2016
Advanced Spark and TensorFlow Meetup May 26, 2016Chris Fregly
 
Introduction to TensorFlow 2
Introduction to TensorFlow 2Introduction to TensorFlow 2
Introduction to TensorFlow 2Oswald Campesato
 
Problem solving using computers - Unit 1 - Study material
Problem solving using computers - Unit 1 - Study materialProblem solving using computers - Unit 1 - Study material
Problem solving using computers - Unit 1 - Study materialTo Sum It Up
 
Language translation with Deep Learning (RNN) with TensorFlow
Language translation with Deep Learning (RNN) with TensorFlowLanguage translation with Deep Learning (RNN) with TensorFlow
Language translation with Deep Learning (RNN) with TensorFlowS N
 
Introducton to Convolutional Nerural Network with TensorFlow
Introducton to Convolutional Nerural Network with TensorFlowIntroducton to Convolutional Nerural Network with TensorFlow
Introducton to Convolutional Nerural Network with TensorFlowEtsuji Nakai
 
Basic Computer Engineering Unit II as per RGPV Syllabus
Basic Computer Engineering Unit II as per RGPV SyllabusBasic Computer Engineering Unit II as per RGPV Syllabus
Basic Computer Engineering Unit II as per RGPV SyllabusNANDINI SHARMA
 
TensorFlow example for AI Ukraine2016
TensorFlow example  for AI Ukraine2016TensorFlow example  for AI Ukraine2016
TensorFlow example for AI Ukraine2016Andrii Babii
 
Natural language processing open seminar For Tensorflow usage
Natural language processing open seminar For Tensorflow usageNatural language processing open seminar For Tensorflow usage
Natural language processing open seminar For Tensorflow usagehyunyoung Lee
 
Working with tf.data (TF 2)
Working with tf.data (TF 2)Working with tf.data (TF 2)
Working with tf.data (TF 2)Oswald Campesato
 
matplotlib-installatin-interactive-contour-example-guide
matplotlib-installatin-interactive-contour-example-guidematplotlib-installatin-interactive-contour-example-guide
matplotlib-installatin-interactive-contour-example-guideArulalan T
 
Advance data structure & algorithm
Advance data structure & algorithmAdvance data structure & algorithm
Advance data structure & algorithmK Hari Shankar
 
Machine Learning - Introduction to Tensorflow
Machine Learning - Introduction to TensorflowMachine Learning - Introduction to Tensorflow
Machine Learning - Introduction to TensorflowAndrew Ferlitsch
 
Deep Learning, Scala, and Spark
Deep Learning, Scala, and SparkDeep Learning, Scala, and Spark
Deep Learning, Scala, and SparkOswald Campesato
 
Class 8b: Numpy & Matplotlib
Class 8b: Numpy & MatplotlibClass 8b: Numpy & Matplotlib
Class 8b: Numpy & MatplotlibMarc Gouw
 

Similar to Tensorflow basics (20)

TensorFlow Tutorial.pdf
TensorFlow Tutorial.pdfTensorFlow Tutorial.pdf
TensorFlow Tutorial.pdf
 
Introduction to TensorFlow 2
Introduction to TensorFlow 2Introduction to TensorFlow 2
Introduction to TensorFlow 2
 
Introduction to TensorFlow 2 and Keras
Introduction to TensorFlow 2 and KerasIntroduction to TensorFlow 2 and Keras
Introduction to TensorFlow 2 and Keras
 
Introduction To TensorFlow | Deep Learning Using TensorFlow | CloudxLab
Introduction To TensorFlow | Deep Learning Using TensorFlow | CloudxLabIntroduction To TensorFlow | Deep Learning Using TensorFlow | CloudxLab
Introduction To TensorFlow | Deep Learning Using TensorFlow | CloudxLab
 
Advanced Spark and TensorFlow Meetup May 26, 2016
Advanced Spark and TensorFlow Meetup May 26, 2016Advanced Spark and TensorFlow Meetup May 26, 2016
Advanced Spark and TensorFlow Meetup May 26, 2016
 
Introduction to TensorFlow 2
Introduction to TensorFlow 2Introduction to TensorFlow 2
Introduction to TensorFlow 2
 
Problem solving using computers - Unit 1 - Study material
Problem solving using computers - Unit 1 - Study materialProblem solving using computers - Unit 1 - Study material
Problem solving using computers - Unit 1 - Study material
 
Language translation with Deep Learning (RNN) with TensorFlow
Language translation with Deep Learning (RNN) with TensorFlowLanguage translation with Deep Learning (RNN) with TensorFlow
Language translation with Deep Learning (RNN) with TensorFlow
 
Introducton to Convolutional Nerural Network with TensorFlow
Introducton to Convolutional Nerural Network with TensorFlowIntroducton to Convolutional Nerural Network with TensorFlow
Introducton to Convolutional Nerural Network with TensorFlow
 
Basic Computer Engineering Unit II as per RGPV Syllabus
Basic Computer Engineering Unit II as per RGPV SyllabusBasic Computer Engineering Unit II as per RGPV Syllabus
Basic Computer Engineering Unit II as per RGPV Syllabus
 
TensorFlow example for AI Ukraine2016
TensorFlow example  for AI Ukraine2016TensorFlow example  for AI Ukraine2016
TensorFlow example for AI Ukraine2016
 
Natural language processing open seminar For Tensorflow usage
Natural language processing open seminar For Tensorflow usageNatural language processing open seminar For Tensorflow usage
Natural language processing open seminar For Tensorflow usage
 
Working with tf.data (TF 2)
Working with tf.data (TF 2)Working with tf.data (TF 2)
Working with tf.data (TF 2)
 
matplotlib-installatin-interactive-contour-example-guide
matplotlib-installatin-interactive-contour-example-guidematplotlib-installatin-interactive-contour-example-guide
matplotlib-installatin-interactive-contour-example-guide
 
Google TensorFlow Tutorial
Google TensorFlow TutorialGoogle TensorFlow Tutorial
Google TensorFlow Tutorial
 
Advance data structure & algorithm
Advance data structure & algorithmAdvance data structure & algorithm
Advance data structure & algorithm
 
Machine Learning - Introduction to Tensorflow
Machine Learning - Introduction to TensorflowMachine Learning - Introduction to Tensorflow
Machine Learning - Introduction to Tensorflow
 
Introduction to TensorFlow
Introduction to TensorFlowIntroduction to TensorFlow
Introduction to TensorFlow
 
Deep Learning, Scala, and Spark
Deep Learning, Scala, and SparkDeep Learning, Scala, and Spark
Deep Learning, Scala, and Spark
 
Class 8b: Numpy & Matplotlib
Class 8b: Numpy & MatplotlibClass 8b: Numpy & Matplotlib
Class 8b: Numpy & Matplotlib
 

Recently uploaded

Ukraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSUkraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSAishani27
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfLars Albertsson
 
Smarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxSmarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxolyaivanovalion
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfRachmat Ramadhan H
 
Edukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxEdukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxolyaivanovalion
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz1
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfLars Albertsson
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysismanisha194592
 
Carero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxCarero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxolyaivanovalion
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusTimothy Spann
 
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxStephen266013
 
Halmar dropshipping via API with DroFx
Halmar  dropshipping  via API with DroFxHalmar  dropshipping  via API with DroFx
Halmar dropshipping via API with DroFxolyaivanovalion
 
BigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxBigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxolyaivanovalion
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxolyaivanovalion
 

Recently uploaded (20)

Ukraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSUkraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICS
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdf
 
Smarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxSmarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptx
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
 
Edukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxEdukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFx
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signals
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysis
 
Sampling (random) method and Non random.ppt
Sampling (random) method and Non random.pptSampling (random) method and Non random.ppt
Sampling (random) method and Non random.ppt
 
Carero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxCarero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptx
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and Milvus
 
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docx
 
Halmar dropshipping via API with DroFx
Halmar  dropshipping  via API with DroFxHalmar  dropshipping  via API with DroFx
Halmar dropshipping via API with DroFx
 
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
 
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
 
BigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxBigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptx
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptx
 

Tensorflow basics

  • 2. Building a Graph ■ Start with ops that do not need any input (source ops), Constant import tensorflow as tf matrix1 = tf.constant([[3,3]]) matrix2 = tf.constant([[6],[6]]) product=tf.matmul(matrix1,matrix2) print(product) # O/pTensor("MatMul_1:0", shape=(1, 1), dtype=int32) sess=tf.Session() result=sess.run(product) print(result) #O/P [[36]] sess.close() ■ You will see difference in o/p in both the print statement. First statement just tells us about the Product tensor property . Second statement is under a session. Graph gets executed thus the print shows the value of the tensor. matrix1 matrix2 OP: MatMul result
  • 3. Tensors ■ As we have seen how a basic tensorflow works, lets dig deeper onTensors ■ n-dimensional array ■ 0-d tensor: scalar (number) ,1-d tensor: vector 2-d, tensor: matrix etc etc. ■ tf.Variable is a class, but tf.constant is an op
  • 4. Graphs ■ It represents computations. import tensorflow as tf a = tf.add(3, 5) ■ TF automatically names the nodes when you don’t explicitly name them. x = 3 y = 5 ■ Edge: Tensors ie data ■ Node: operators, variables, and constants ■ If we simply print(a), output will be tensor object and not 8.To fetch the value of it in a, we need to run the session. ■ The session will look at the graph, trying to think: how can I get the value of a, then it computes all the nodes that leads to a. x y Ad d x y a Interpret ation 3 5 Add Session x y a 3 5 Add 8
  • 5. But why only graphs? ■ Save computation (only run subgraphs that lead to the values you want to fetch) ■ Break computation into small, differential pieces to facilitates auto-differentiation ■ Facilitate distributed computation, spread the work across multiple CPUs, GPUs, or devices ■ Many common machine learning models are commonly taught and visualized as directed graphs already
  • 6. Sessions ■ A Session object encapsulates the environment in which Operation objects are executed, andTensor objects are evaluated. x = 2 y = 3 add_op = tf.add(x, y) mul_op = tf.mul(x, y) useless = tf.mul(x, add_op) pow_op = tf.pow(add_op, mul_op) with tf.Session() as sess: z = sess.run(pow_op) Because we only want the value of pow_op and pow_op doesn’t depend on useless, session won’t compute value of useless → save computation
  • 7. Operations Its very similar to numpy. In terms of data type,TensorFlow integrates seamlessly with NumPy. If the requested fetch is aTensor , then the output of will be a NumPy ndarray. Beware when using NumPy arrays because NumPy andTensorFlow might become not so compatible in the future!
  • 8. Tensor Board ■ Help a lot when you build complicated models ■ To useTensor Board I. Go to terminal II. run: $ python [yourprogram].py III. $ tensorboard --logdir="./graphs" --port 6006 IV. Then open your browser and go to: http://localhost:6006/
  • 9. Example ofTensor Board import tensorflow as tf matrix1 = tf.constant([[3,3]]) matrix2 = tf.constant([[6],[6]]) product=tf.matmul(matrix1,matrix2) print(product) sess=tf.Session() writer = tf.summary.FileWriter("./graphs", sess.graph) result=sess.run(product) print(result) sess.close()
  • 10. I don’t like const, How to explicitly name them import tensorflow as tf matrix1 = tf.constant([[3,3]], name="a") matrix2 = tf.constant([[6],[6]], name="b") product=tf.matmul(matrix1,matrix2) print(product) sess=tf.Session() writer = tf.summary.FileWriter("./graphs", sess.graph) result=sess.run(product) print(result) sess.close()
  • 11. Key Notes ■ Graph execution is done across all available compute resources, such as CPU or GPU. If you have GPU,TensorFlow uses your first GPU ■ TensorFlow separates definition of computations from their execution
  • 12. ■ Only use constants for primitive types. Constants are stored in graph’s definition.This makes loading graphs expensive when constants are big. Use variables or readers for more data that requires more memory.
  • 13. Test yourTensor flow knowledge Graphs Sessions Tensors Variables Nodes