Friday, 22 March 2019

Tensor Flow from novice to expert - Part1

https://github.com/tensorflow/nmt

# -*- coding: utf-8 -*-
"""
Created on Tue Dec 26 21:21:01 2017

@author: krishgu
"""

import tensorflow as tf
node1 = tf.constant(3.0,tf.float32)
node2 = tf.constant(4.0)
# Printing it
print("Printing node1 node2 - %s" % node1,node2)

# Performing the operations in graph using session
sess=tf.Session()
print("Printing node1 node2 values - %s" % sess.run([node1,node2]))


#sample computation with constant value
a = tf.constant(5)
b = tf.constant(2)
c = tf.constant(3)

d=tf.multiply(a,b)
e=tf.add(c,b)

f=tf.subtract(d,e)

sess=tf.Session()
outs=sess.run(f)
sess.close()

print("outs = {}".format(outs))


#performing it with dynamic value
a= tf.placeholder(tf.float32)
b= tf.placeholder(tf.float32)

adder_node = a+b
sess= tf.Session()
print(sess.run(adder_node,{a:[1,2,3,4,5],b:[1,2,3,4,5]}))


#Perfroming it with variable values
w = tf.Variable([.3],tf.float32)
b = tf.Variable([-.3],tf.float32)
x = tf.placeholder(tf.float32)

linear_model=w*x+b;
init = tf.global_variables_initializer()
print(w)
print(b)
sess = tf.Session()
sess.run(init)
print(sess.run(w))
print(sess.run(b))
print(sess.run(linear_model,{x:[1,2,3,4]}))

No comments:

Post a Comment

Custom single threaded java server

 package com.diffengine.csv; import java.io.*; import java.net.*; import java.util.Date; public class Server { public static void main(Str...