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['y']
>>>   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
static program(input_specs=None, opset_version=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.

opset_version: AvailableTarget enum

Describes the opset version of the program

Examples

>>> import coremltools as ct
>>> @mb.program(input_specs=[mb.TensorSpec(shape=(1,2))], opset_version=ct.target.iOS16)
>>> def prog(a):
>>>     return mb.add(x=a, y=2)