Basic Of Tensorflow

#TensorFlow

!wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip
--2019-09-14 12:12:29--  https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip
Resolving bin.equinox.io (bin.equinox.io)... 52.204.136.9, 3.214.163.243, 52.54.237.49, ...
Connecting to bin.equinox.io (bin.equinox.io)|52.204.136.9|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 13607069 (13M) [application/octet-stream]
Saving to: ‘ngrok-stable-linux-amd64.zip’


          ngrok-sta   0%[                    ]       0  --.-KB/s               
         ngrok-stab  64%[===========>        ]   8.43M  41.9MB/s               
ngrok-stable-linux- 100%[===================>]  12.98M  40.9MB/s    in 0.3s    

2019-09-14 12:12:30 (40.9 MB/s) - ‘ngrok-stable-linux-amd64.zip’ saved [13607069/13607069]

!unzip ngrok-stable-linux-amd64.zip
Archive:  ngrok-stable-linux-amd64.zip
  inflating: ngrok                   
LOG_DIR = './log'
get_ipython().system_raw(
'tensorboard --logdir {} --host 0.0.0.0 --port 6006 &'
.format(LOG_DIR)
)
get_ipython().system_raw('./ngrok http 6006 &')
! curl -s http://localhost:4040/api/tunnels | python3 -c \
"import sys, json; print(json.load(sys.stdin)['tunnels'][0]['public_url'])"
https://f4e76656.ngrok.io
import tensorflow as tf
a = tf.constant(10)
b = tf.constant(10)
c = tf.add(a,b)
print(a)
print(b)
with tf.Session() as sess:
  print(sess.run(c))
Tensor("Const_6:0", shape=(), dtype=int32)
Tensor("Const_7:0", shape=(), dtype=int32)
20

a=tf.constant([2,2],name='a')
b=tf.constant([[0,1],[2,3]],name='b')
x=tf.add(a,b,name='add')
y=tf.multiply(a,b,name='mul')
with tf.Session() as sess:
 x,y=sess.run([x,y])
print(x,y)
[[2 3]
 [4 5]] [[0 2]
 [4 6]]
input_tensor = tf.constant([[0,1], [2,3] , [4,5]])
like_t = tf.ones_like(input_tensor)
my_mul = tf.multiply(like_t , input_tensor , name = "mul")

with tf.Session() as sess:
  my_mul = sess.run(my_mul)
  
print(my_mul)
[[0 1]
 [2 3]
 [4 5]]
import numpy as np

m1 = [[1 ,2] ,[3 ,4]]

m2 = np.array([[1 ,2],[3,4]] , dtype= np.float32)

m3 = tf.constant([[1,2] , [3,4]])

print(m1)
print(m2)
print("\n m3 :" ,m3)

t1 = tf.convert_to_tensor(m1 , dtype = tf.float32)
t2 = tf.convert_to_tensor(m2 , dtype = tf.float32)
t3 = tf.convert_to_tensor(m3 , dtype = tf.int32)

print(t1)
print(t2)
print(t3)
[[1, 2], [3, 4]]
[[1. 2.]
 [3. 4.]]

 m3 :
 Tensor("Const_42:0", shape=(2, 2), dtype=int32)
Tensor("Const_43:0", shape=(2, 2), dtype=float32)
Tensor("Const_44:0", shape=(2, 2), dtype=float32)
Tensor("Const_42:0", shape=(2, 2), dtype=int32)