- High Performance Library for Numerical Computation
- Represented as Directed Graphs
- DAG (Directed Acyclic Graphs)
- Edges - Arrays of Data
- Language independent version of representation
- Similar to JVM
- Tensorflow engine written in C++
- Tensorflow Lite - On device interference of ML Models
- Number of abstraction layers
- High Level API -> tf.estimator
- tf.layers, tf.losses, tf.metrics -> Custom NN Models
- Core Tensorflow Python
- Core Tensorflow C++
- CPU / GPU / TPU / Android
- Code
- Tensors Definition
- Creates DAG
- Run DAG in Session
- Lazy Evaluation model (minimize context switches)
- Explicit edges to represent dependencies
- Helps to partition and run parallel pieces
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import tensorflow as tf | |
#numpy | |
a = np.array([5,3,8]) | |
b = np.array([3,-1,2]) | |
c = np.add(a,b) | |
print('numpy data') | |
print(c) | |
#Tensorflow | |
#Build | |
a = tf.constant([5,3,8]) | |
b = tf.constant([3,-1,2]) | |
c = tf.add(a,b) | |
print(c) | |
#scalar | |
x = tf.constant(4) | |
#vector | |
x = tf.constant([3,5,7]) | |
#matrix | |
#2D | |
x = tf.constant([[3,5,7],[4,6,8]]) | |
#Get 0th column | |
y = x[:,0] | |
#Get the 0th row | |
z = x[0,:] | |
#get two values only | |
#start at 0, fetch two elements | |
#python range first number included last number is not | |
zz = x[0,:2] | |
#rewrite into 3x2 rows | |
yy = tf.reshape(x,[3,2]) | |
#rewrite into 6x1 rows | |
yyy = tf.reshape(x,[6,1]) | |
#3D | |
x = tf.constant([[[3,5,7],[4,6,8]]]) | |
#placeholders to feed value | |
data = tf.placeholder("float",None) | |
b = data*2 | |
#Run | |
with tf.Session() as sess: | |
result = sess.run(c) | |
print('tensor data') | |
print(result) | |
print('c evaluation') | |
print(c.eval()) | |
print(y.eval()) | |
print(z.eval()) | |
print(zz.eval()) | |
print(yy.eval()) | |
print(yyy.eval()) | |
print(sess.run(b,feed_dict={data: [1,2,3]})) | |
Happy Learning!!!
No comments:
Post a Comment