Quick Reference

List Brief
function Return a callable function that will compute outputs.
shared Construct a Tensor initialized with numerical values.

API Reference

class dragon.vm.theano.compile.function.Function(name=None)

The Function wraps the meta graph and a defined callback.

We recommend this way to avoid a explicit GraphDef exposed.

export_to(name=None, export_dir='./')

Export the meta graph of this defined function.

Parameters:export_dir (str) – The directory to export the meta text file.
Return type:None
import_from(graph_def, explicit_inputs=False)

Import the defined function from a graph def.

Set explicit_inputs to False,

if you want to feed the inputs as workspace.FeedTensor(self.inputs)

  • meta_graph (GraphDef) – The definition of graph.
  • explicit_inputs (boolean) – Whether to enforce feeding on executing.

The self.

Return type:


dragon.vm.theano.compile.function.function(inputs=None, outputs=None, givens=None, updater=None)

Return a callable function that will compute outputs or apply updater.

Set inputs to feed inputs into this callable function.

Set givens to substitute some tensors before making the computation graph.

Set updater to make update graph, but the update targets should be generated before.

  • inputs (sequence of Tensor, optional) – The inputs to feed.
  • outputs (sequence of Tensor, optional) – The outputs to fetch.
  • givens (dict of Tensor, optional) – The substitutions to use.
  • updater (Updater, optional) – The updater to use.

The callable function.

Return type:



>>> import numpy, dragon
>>> x = dragon.Tensor('x', dtype='float32').Variable()
>>> y = x * 2
>>> f = function(outputs=y)
>>> x.set_value(numpy.ones((2, 3)))
>>> print(f())
>>> [[ 2.  2.  2.]
     [ 2.  2.  2.]]
>>> f = function(inputs=x, outputs=y)
>>> print(f(numpy.ones((2, 3)))
>>> [[ 2.  2.  2.]
     [ 2.  2.  2.]]
dragon.vm.theano.compile.sharedvalue.shared(value, name=None, **kwargs)

Construct a Tensor initialized with value.

  • value (number, sequence or numpy.ndarray) – The numerical values.
  • name (str, optional) – The optional name

The initialized tensor.

Return type: