常用的tensorflow函数

在mask_rcnn常用的函数

1 Tensorflow中 tf.cast()的用法:

 2 tf.gather 实例

 3 tf.boolean_mask

1:

https://blog.csdn.net/dss875914213/article/details/86558407

tf.cast()

cast(
    x,
    dtype,
    name=None
)12345

将x的数据格式转化成dtype数据类型.例如,原来x的数据格式是bool,  
那么将其转化成float以后,就能够将其转化成0和1的序列。反之也可以

%%python2
import sys
import tensorflow as tf
print(sys.version)

a = tf.Variable([1.0,1.3,2.1,3.41,4.51])
b = tf.cast(a>3,dtype=tf.bool)
c = tf.cast(a>3,dtype=tf.int8)
e = tf.cast(a<2,dtype=tf.float32)
d = tf.cast(a,dtype=tf.int8)

sess = tf.Session()
sess.run(tf.initialize_all_variables())
print(sess.run(b))
print(sess.run(c))
print(sess.run(e))
print(sess.run(d))1234567891011121314151617

[False False False  True  True]
[0 0 0 1 1]
[1. 1. 0. 0. 0.]
[1 1 2 3 4]1234

猜你喜欢

转载自www.cnblogs.com/shuimuqingyang/p/10641960.html