MIL Builder

class coremltools.converters.mil.mil.Builder[source]

This class is a singleton builder to construct a MIL program. For more information, see Create a MIL program.

Importing .ops triggers the installation of all MIL ops into the Builder. For details on each op, see MIL ops.

Examples

>>> from coremltools.converters.mil.mil import Builder as mb
>>> from coremltools.converters.mil.mil import Program, Function
>>> prog = Program()
>>> func_inputs = {"x": mb.placeholder(_shape=[2,3]),
>>>                "y": mb.placeholder(_shape=[2,3])}
>>> with Function(func_inputs) as ssa_fun:
>>>   x, y = ssa_fun.inputs['x'], ssa_fun.inputs['x']
>>>   res_var = mb.add(x=x, y=y) # created within ssa_fun block
>>>   ssa_fun.set_outputs([res_var])
>>> prog.add_function("main", ssa_fun)
>>> # Importing ops triggers installation of all ops into Builder.
>>> from .ops import defs as _ops
program()[source]
static program(input_specs=None)[source]

The mb.program decorator creates a MIL program with a single function (main). The input to main is a tensor.

Parameters
input_specs: TensorSpec

Describes a tensor.

Examples

>>> @mb.program(input_specs=[mb.TensorSpec(shape=(1,2))])
>>> def prog(a):
>>>     return mb.add(x=a, y=2)