Skip to content

Commit 24969d4

Browse files
committed
Addition of Python4Delphi/Tensorflow-Demos
1 parent 80602bb commit 24969d4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+130625
-1
lines changed
Binary file not shown.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# # Tensor Types
2+
3+
import tensorflow as tf
4+
import numpy as np
5+
6+
# Define a 2x2 matrix in 3 different ways
7+
8+
m1 = [[1.0, 2.0], [3.0, 4.0]]
9+
m2 = np.array([[1.0, 2.0], [3.0, 4.0]], dtype=np.float32)
10+
m3 = tf.constant([[1.0, 2.0], [3.0, 4.0]])
11+
12+
print(type(m1))
13+
print(type(m2))
14+
print(type(m3))
15+
16+
17+
# Create tensor objects out of various types
18+
19+
t1 = tf.convert_to_tensor(m1, dtype=tf.float32)
20+
t2 = tf.convert_to_tensor(m2, dtype=tf.float32)
21+
t3 = tf.convert_to_tensor(m3, dtype=tf.float32)
22+
23+
print(type(t1))
24+
print(type(t2))
25+
print(type(t3))
Binary file not shown.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import tensorflow as tf
2+
3+
x = tf.constant([[1, 2]])
4+
neg_x = tf.negative(x)
5+
6+
print(neg_x)
7+
8+
with tf.Session() as sess:
9+
result = sess.run(neg_x)
10+
print(result)
Binary file not shown.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import tensorflow as tf
2+
sess = tf.InteractiveSession()
3+
4+
x = tf.constant([[1., 2.]])
5+
neg_op = tf.negative(x)
6+
7+
result = neg_op.eval()
8+
print(result)
9+
10+
sess.close()
Binary file not shown.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import tensorflow as tf
2+
3+
x = tf.constant([[1, 2]])
4+
neg_op = tf.negative(x)
5+
6+
with tf.Session(config=tf.ConfigProto(log_device_placement=True)) as sess:
7+
result = sess.run(neg_op)
8+
print(result)
9+
10+
Binary file not shown.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# # Using Variables in TensorFlow
2+
3+
import tensorflow as tf
4+
sess = tf.InteractiveSession()
5+
6+
# Create a boolean variable called `spike` to detect sudden a sudden increase in a series of numbers.
7+
#
8+
# Since all variables must be initialized, initialize the variable by calling `run()` on its `initializer`.
9+
raw_data = [1., 2., 8., -1., 0., 5.5, 6., 13]
10+
spike = tf.Variable(False)
11+
spike.initializer.run()
12+
13+
# Loop through the data and update the spike variable when there is a significant increase
14+
for i in range(1, len(raw_data)):
15+
if raw_data[i] - raw_data[i-1] > 5:
16+
updater = tf.assign(spike, tf.constant(True))
17+
updater.eval()
18+
else:
19+
tf.assign(spike, False).eval()
20+
print("Spike", spike.eval())
21+
22+
sess.close()

0 commit comments

Comments
 (0)