In [2]:
import sys
print(sys.executable)
print(sys.version)
print(sys.version_info)
In [2]:
import tensorflow as tf
In [4]:
#Quick hacks ...
# Simple hello world using TensorFlow
# Create a Constant op
# The op is added as a node to the default graph.
#
# The value returned by the constructor represents the output
# of the Constant op.
hello = tf.constant('Hello, TensorFlow!')
In [5]:
# Start tf session
sess = tf.Session()
In [6]:
# Run graph
print(sess.run(hello))
In [17]:
# Basic constant operations
# The value returned by the constructor represents the output
# of the Constant op.
a = tf.constant(21)
b = tf.constant(13)
#
print(type(a))
# <class 'tensorflow.python.framework.ops.Tensor'>
In [19]:
# Launch the default graph.
with tf.Session() as sess:
print("a: sess.run(a) b:_______TYPE_______",type(sess.run(b)))
print("b: sess.run(b) b:__________________",sess.run(b))
print("Addition with constants:___________",sess.run(a+b))
print("Multiplication with constants:_____",sess.run(a*b))
print("Subtraction with constants_________",sess.run(a-b))
print(type(sess)) ## <class 'tensorflow.python.client.session.Session'>
In [21]:
# Add , Divide - basic Op's
x = tf.add(a, b, name="add")
y = tf.div(a, b, name="divide")
print(type(x))
print(type(y))
# x and y are == # <class 'tensorflow.python.framework.ops.Tensor'>
# same as the - #b = tf.constant(13) ...
#
In [20]:
# Closing the session.
sess.close()
print(type(sess))
In [10]:
# Create Graphs over and above the DEFAULT Graph
graph1 = tf.Graph()
print(type(graph1))
graph2 = tf.Graph()
print(type(graph2))
In [3]:
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
import tensorflow as tf
In [4]:
my_variable = tf.get_variable("my_variable", [1, 2, 3])
print(type(my_variable))
In [6]:
#my_int_variable = tf.get_variable("my_int_variable", [1, 2, 3], dtype=tf.int32,initializer=tf.zeros_initializer)
#print(type(my_int_variable))
In [8]:
my_int_variable1 = tf.get_variable("my_int_variable1", [1, 2, 3], dtype=tf.int32,initializer=tf.zeros_initializer)
print(type(my_int_variable1))
In [9]:
other_variable = tf.get_variable("other_variable", dtype=tf.int32,initializer=tf.constant([23, 42]))
print(type(other_variable))
#<class 'tensorflow.python.ops.variables.Variable'>
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [8]:
print("EVERY TIME we run this Chunk - weights_3:0 and biases_3:0 --- increments to weights_4:0 , weights_5:0 etc etc ... Why ? ")
print(" "*90)
## Create two variables.
weights = tf.Variable(tf.random_normal([784, 200], stddev=0.35),name="weights")
biases = tf.Variable(tf.zeros([200]), name="biases")
print(type(biases))
print(biases)
print(weights)
In [ ]:
In [ ]:
In [ ]:
# from above == https://github.com/tensorflow/tensorflow/issues/14788
# Need to understand the Difference between --- dtype=int32_ref and dtype=int32
# is the _ref === REFRENCE ?
"""
In [19]: v = tf.Variable([1])
In [20]: v
Out[20]: <tf.Variable 'Variable_2:0' shape=(1,) dtype=int32_ref>
In [21]: v3 = tf.identity(v)
In [22]: v3
Out[22]: <tf.Tensor 'Identity_1:0' shape=(1,) dtype=int32>
"""
In [ ]:
In [32]:
# A VARIABLE is NOT A TENSOR --- Variables are in-memory buffers containing tensors.
#
from tensorflow.python.framework import ops
## Defining Variables ---@alextp == https://github.com/tensorflow/tensorflow/issues/14788
#
#I can see how the docstring is confusing if you think a variable is a tensor (it's not).
#A variable is a thing which can be converted to a tensor containing its current value.
#It also can be assigned to, partitioned, etc, which tensors can't
# Create three variables with some default values.
print("EVERY TIME we run this Chunk - weights_3:0 inceremnts to weights_4:0 , weights_5:0 etc etc ... Why ? ")
print(" "*90)
weights = tf.Variable(tf.random_normal([2, 3], stddev=0.1), name="weights")
print(weights)
print(type(weights))
print(" "*90)
biases = tf.Variable(tf.zeros([3]), name="biases")
print(biases)
print(type(biases))
print(" "*90)
custom_variable = tf.Variable(tf.zeros([3]), name="custom")
print(custom_variable)
print(type(custom_variable))
print(" "*90)
# Get all the variables' tensors and store them in a list.
all_variables_list = ops.get_collection(ops.GraphKeys.GLOBAL_VARIABLES)
In [26]:
# Graphs
a = tf.constant(3.0, dtype=tf.float32)
print(type(a)) ## <class 'tensorflow.python.framework.ops.Tensor'>
#b = tf.constant(4.0,66,77) # also tf.float32 implicitly
# TypeError: Cannot convert 66 to a dtype. data type not understood
b = tf.constant(66) #
print(type(b)) ## <class 'tensorflow.python.framework.ops.Tensor'>
total = a + b ## Seems we cant add Floats and INT's ??
print(a)
print(b)
print(total)
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
No comments:
Post a Comment