1 Star 0 Fork 0

Silent_rhino/study_tensorflow

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
tensorflow_api.py 1.95 KB
一键复制 编辑 原始数据 按行查看 历史
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)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/silent_rhino/study_tensorflow.git
git@gitee.com:silent_rhino/study_tensorflow.git
silent_rhino
study_tensorflow
study_tensorflow
master

搜索帮助