首页 > 其他 > 详细

『TensorFlow』常用函数

时间:2017-05-25 21:06:36      阅读:970      评论:0      收藏:0      [点我收藏+]

张量相关:

tf.cast():bool->数字

re = tf.cast([True,False],tf.float32)
sess = tf.Session()
sess.run(re)
# Out[6]: 
# array([ 1.,  0.], dtype=float32)

tf.argmax:(list,维度)

re = tf.argmax([[0,0.5]],1)
sess.run(re)
# Out[20]: 
# array([1])

 

变量相关:

tf.Variable()                                                                         # 声明变量
tf.get_variable() # 声明变量
tf.global_variables_initializer() # 激活变量

可视化相关:

tf.summary.histogram(layer_name+‘/weights‘,Weights)                                   # 张量记录
tf.summary.scalar = (‘loss‘,cross_entropy)                                            # 标量记录
merged = tf.summary.merge_all()                                                       # 记录激活
train_writer = tf.summary.FileWriter(‘logs/train‘,sess.graph)                         # 书写器生成
train_result = sess.run(merged, feed_dict={xs: X_train, ys: y_train, keep_prob:1}) # run记录
train_writer.add_summary(train_result,i) # 书写记录

 

 

操作组操作
Maths Add, Sub, Mul, Div, Exp, Log, Greater, Less, Equal
Array Concat, Slice, Split, Constant, Rank, Shape, Shuffle
Matrix MatMul, MatrixInverse, MatrixDeterminant
Neuronal Network SoftMax, Sigmoid, ReLU, Convolution2D, MaxPool
Checkpointing Save, Restore
Queues and syncronizations Enqueue, Dequeue, MutexAcquire, MutexRelease
Flow control Merge, Switch, Enter, Leave, NextIteration

 

TensorFlow的算术操作如下:

操作描述
tf.add(x, y, name=None) 求和
tf.sub(x, y, name=None) 减法
tf.mul(x, y, name=None) 乘法
tf.div(x, y, name=None) 除法
tf.mod(x, y, name=None) 取模
tf.abs(x, name=None) 求绝对值
tf.neg(x, name=None) 取负 (y = -x).
tf.sign(x, name=None) 返回符号 y = sign(x) = -1 if x < 0; 0 if x == 0; 1 if x > 0.
tf.inv(x, name=None) 取反
tf.square(x, name=None) 计算平方 (y = x * x = x^2).
tf.round(x, name=None) 舍入最接近的整数
# ‘a’ is [0.9, 2.5, 2.3, -4.4]
tf.round(a) ==> [ 1.0, 3.0, 2.0, -4.0 ]
tf.sqrt(x, name=None) 开根号 (y = \sqrt{x} = x^{1/2}).
tf.pow(x, y, name=None) 幂次方
# tensor ‘x’ is [[2, 2], [3, 3]]
# tensor ‘y’ is [[8, 16], [2, 3]]
tf.pow(x, y) ==> [[256, 65536], [9, 27]]
tf.exp(x, name=None) 计算e的次方
tf.log(x, name=None) 计算log,一个输入计算e的ln,两输入以第二输入为底
tf.maximum(x, y, name=None) 返回最大值 (x > y ? x : y)
tf.minimum(x, y, name=None) 返回最小值 (x < y ? x : y)
tf.cos(x, name=None) 三角函数cosine
tf.sin(x, name=None) 三角函数sine
tf.tan(x, name=None) 三角函数tan
tf.atan(x, name=None) 三角函数ctan

 

  • 数据类型转换Casting

 

操作描述
tf.string_to_number
(string_tensor, out_type=None, name=None)
字符串转为数字
tf.to_double(x, name=’ToDouble’) 转为64位浮点类型–float64
tf.to_float(x, name=’ToFloat’) 转为32位浮点类型–float32
tf.to_int32(x, name=’ToInt32’) 转为32位整型–int32
tf.to_int64(x, name=’ToInt64’) 转为64位整型–int64
tf.cast(x, dtype, name=None) 将x或者x.values转换为dtype
# tensor a is [1.8, 2.2], dtype=tf.float
tf.cast(a, tf.int32) ==> [1, 2] # dtype=tf.int32

『TensorFlow』常用函数

原文:http://www.cnblogs.com/hellcat/p/6905878.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!