MIL Builder


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.


>>> from import Builder as mb
>>> from 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: Optional[List[Placeholder]] = None, opset_version: Optional[AvailableTarget] = None, function_name: Optional[str] = 'main')[source]

The mb.program decorator creates a MIL program with a single function with name function_name.

input_specs: List[TensorSpec]

Describes the function inputs

opset_version: AvailableTarget enum

Describes the opset version of the program

function_name: str

Name of the function


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