tf.py_func

在 faster  rcnn的tensorflow 实现中看到这个函数

rois,rpn_scores=tf.py_func(proposal_layer,[rpn_cls_prob,rpn_bbox_pred,self._im_info,self.mode,self._feat_stride,self._anchors,self._num_anchors],[tf.float32,tf.float32],name="proposal")

  tensorflow 官网上的解释

py_func(
    func,
    inp,
    Tout,
    stateful=True,
    name=None
)

将python 函数包装为一个tensorflow操作符
python 函数proposal_layer 以numpy 矩阵作为输入输出,使函数变为tensorflow图中的操作符
定义一个简单的sinh函数在tensorflow图中:
def my_func(x):
  # x will be a numpy array with the contents of the placeholder below
  return np.sinh(x)
inp = tf.placeholder(tf.float32)
y = tf.py_func(my_func, [inp], tf.float32)

 

posted @ 2017-11-06 11:16  hahahaf  阅读(2786)  评论(0编辑  收藏  举报