Skip to content

Latest commit

 

History

History
49 lines (31 loc) · 1.18 KB

script_ops.md

File metadata and controls

49 lines (31 loc) · 1.18 KB

Wraps python functions

Note: Functions taking Tensor arguments can also take anything accepted by tf.convert_to_tensor.

[TOC]

Script Language Operators.

TensorFlow provides allows you to wrap python/numpy functions as TensorFlow operators.

Other Functions and Classes


tf.py_func(func, inp, Tout, name=None) {#py_func}

Wraps a python function and uses it as a tensorflow op.

Given a python function func, which takes numpy arrays as its inputs and returns numpy arrays as its outputs. E.g.,

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 = py_func(my_func, [inp], [tf.float32])

The above snippet constructs a tf graph which invokes a numpy sinh(x) as an op in the graph.

Args:
  • func: A python function.
  • inp: A list of Tensor.
  • Tout: A list of tensorflow data types indicating what func returns.
  • name: A name for the operation (optional).
Returns:

A list of Tensor which func computes.