代码拉取完成,页面将自动刷新
import numpy as np
import tensorflow as tf
# 学习tf.constant
# string = tf.constant('hello, tensorflow.')
# c1 = np.array([1.2, 2.3], dtype=np.float32)
# c2 = np.array([3.4, 5.2], dtype=np.float32)
# t1 = tf.convert_to_tensor(c1, dtype=tf.float32)
# t2 = tf.convert_to_tensor(c2, dtype=tf.float32)
# 学习tf.placeholder
# p1 = tf.placeholder(tf.float32, shape=(3, 2))
# p2 = tf.placeholder(tf.float32, shape=(2, 3))
# add_result = tf.matmul(p1, p2)
# np_p1 = np.array([[1, 2], [3, 4], [5, 6]]).astype(np.float32)
# np_p2 = np.array([[7, 8, 9], [10, 11, 12]]).astype(np.float32)
# 学习tf.Variable
# w = tf.Variable([0.3], dtype=tf.float32)
# b = tf.Variable([-0.3], dtype=tf.float32)
# x = tf.placeholder(tf.float32)
# result = tf.add(tf.multiply(w, x), b)
# sess.run(tf.global_variables_initializer()) 可以初始化所有的变量
# 学习tf.zeros
# a = tf.zeros(100,)
# 学习tf.zeros_like
# a = tf.constant([1, 2, 3])
# b = tf.zeros_like(a)
# 学习tf.fill
# a = tf.fill([2, 3], 9)
# 学习tf.lin_space
# a = tf.lin_space(1.0, 100.0, 10)
# 学习tf.range
# a = tf.range(1.0, 100.0, 5.2)
# 学习tf.random_uniform\random_normal\truncated_normal
# a = tf.random_uniform((2, 2), minval=1.0, maxval=10.0)
# b = tf.random_normal((2, 2), mean=0.0, stddev=200)
# c = tf.truncated_normal((2, 2), mean=0.0, stddev=1)
# 学习tf.variable_scope tf.get_variable
# with tf.variable_scope(name_or_scope='layer_a'):
# w = tf.get_variable(name='w', initializer=[.3])
#
# with tf.variable_scope(name_or_scope='layer_a', reuse=False):
# b = tf.get_variable(name='w', initializer=[.5])
w = tf.Variable([0.3], dtype=tf.float32)
b = tf.Variable([-0.3], dtype=tf.float32)
x = tf.placeholder(tf.float32)
result = tf.add(tf.multiply(w, x), b)
with tf.Session() as sess:
sess.run(tf.initialize_all_variables())
writer = tf.summary.FileWriter('/home/ts/Desktop/tf_study_api/tensorboard_test', sess.graph)
w_result = sess.run(result, feed_dict={x:2.0})
print("2 :" , w_result)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。