在 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)