课堂学习笔记
hello world
import os
import tensorflow as tf
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
hello = tf.constant('hello world!')
sess = tf.Session()
print(sess.run(hello))
常量/变量/矩阵输入
import os
import tensorflow as tf
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
##常量操作
a = tf.constant(2)
b = tf.constant(3)
with tf.Session() as sess:
print("a = 2, b = 3")
print("add: %i" % sess.run(a+b))
print("multiple: %i" % sess.run(a*b))
##变量操作
c = tf.placeholder(tf.int16)
d = tf.placeholder(tf.int16)
add = tf.add(c, d)
mul = tf.multiply(c, d)
with tf.Session() as sess:
print("variable: %i" % sess.run(add, feed_dict={c: 2, d: 3}))
print("variable: %i" % sess.run(mul, feed_dict={c: 2, d: 3}))
m1 = tf.constant([[3, 3]])
m2 = tf.constant([[2], [2]])
pro = tf.matmul(m1, m2)
with tf.Session() as sess:
print("result:", sess.run(pro))
writer = tf.summary.FileWriter(logdir='logs', graph=tf.get_default_graph())
writer.flush()