1.条件函数,替代 if else
在tensorflow里面不能使用if else对bool型tensor进行判断。所以需要使用tf.cond
https://blog.csdn.net/u013249853/article/details/101012523
x = tf.constant(2)
y = tf.constant(5)
def f1(): return tf.multiply(x, 17)
def f2(): return tf.add(y, 23)
r = tf.cond(tf.less(x, y), f1, f2)
# r is set to f1().
# Operations in f2 (e.g., tf.add) are not executed.
2.维度变换,expand_dims squeeze
有些tf core的op可以处理四维,(batch,weidth,height,channels),比如:tf.ResizeBilinear:https://www.tensorflow.org/api_docs/cc/class/tensorflow/ops/resize-bilinear
但是有些op你是用三维写的那就需要改变维度。
(1,512,412,23)->(512,412,23)
tf.expand_dims(feature_map,axis=0)