TensorFlowConverter

class webdnn.frontend.tensorflow.TensorFlowConverter(batch_size=1)[source]

Converter for TensorFlow

Parameters:session (tf.Session) – Session. As default, tf.get_default_session() is used.
convert(model, input_orders=None)[source]
Parameters:
  • inputs (list of tf.Tensor) – tensorflow input tensors
  • outputs (list of tf.Tensor) – tensorflow output tensors
  • order_hints – Order annotations which helps webdnn’s optimizer.

example

Convert TensorFlow model.

import tensorflow as tf
from webdnn.frontend.tensorflow import TensorFlowConverter

# y = x @ W + b
x = tf.placeholder(tf.float32, [None, 784])
W = tf.Variable(tf.zeros([784, 10]))
b = tf.Variable(tf.zeros([10]))
y = tf.nn.softmax(tf.matmul(x, W) + b)

graph = TensorFlowConverter().convert([x], [y])
Returns:WebDNN IR Graph
Return type:(Graph)
convert_to_constant_variable(tf_var, order)[source]

Convert tf.Tensor into ConstantVariable.

This method also registers the mapping information between TensorFlow variable and WebDNN constant variable. If specified TensorFlow variable is already registered into converter, converter checks that the shape and order is valid

This method is provided only for implementing custom converter handler.

Parameters:
  • tensor (tf.Tensor) – TensorFlow tensor
  • order – (Order) data order. As default, default order is used.
Returns:

converted variable.

Return type:

(ConstantVariable)