MIL Input Types

Input types supported by the Model Intermediate Language (MIL):


class, predicted_feature_name='classLabel', predicted_probabilities_output=None)[source]
__init__(class_labels, predicted_feature_name='classLabel', predicted_probabilities_output=None)[source]

Configuration for classifier models.

class_labels: str / list of int / list of str

If a list is given, the list maps the index of the output of a neural network to labels in a classifier.

If a str is given, the str points to a file which maps the index to labels in a classifier.

predicted_feature_name: str

Name of the output feature for the class labels exposed in the Core ML neural network classifier. Default: 'classLabel'.

predicted_probabilities_output: str

If provided, then this is the name of the neural network blob which generates the probabilities for each class label (typically the output of a softmax layer).

If not provided, then the last output layer is assumed.


class, default=None)[source]
__init__(shapes, default=None)[source]

A shape class that is used for setting multiple valid shape in InputType.

shapes: list of Shape objects, or Shape-compatible lists.

The valid shapes of the inputs.

If input provided is not Shape object, but can be converted to Shape, the Shape object would be stored in shapes instead.

default: tuple of int or None

The default shape that is used for initiating the model, and set in the metadata of the model file.

If None, then the first element in shapes is used.


class, shape=None, scale=1.0, bias=None, color_layout=ColorLayout.RGB, channel_first=None)[source]
__init__(name=None, shape=None, scale=1.0, bias=None, color_layout=ColorLayout.RGB, channel_first=None)[source]

Configuration class used for image inputs in Core ML.

scale: (float)

The scaling factor for all values in the image channels.

bias: float or list of float
  • If color_layout is ct.colorlayout.GRAYSCALE or ct.colorlayout.GRAYSCALE_FLOAT16, bias would be a float.

  • If color_layout is ct.colorlayout.RGB or ct.colorlayout.BGR, bias would be a list of float.

color_layout: string or enumeration of type ``ct.colorlayout``

Color layout of the image. Valid values are as follows:

Enumeration (recommended):
  • ct.colorlayout.RGB

  • ct.colorlayout.BGR

  • ct.colorlayout.GRAYSCALE

  • ct.colorlayout.GRAYSCALE_FLOAT16

String values (older way to specify):
  • 'G': Grayscale (maps to ct.colorlayout.GRAYSCALE)

  • 'RGB': [Red, Green, Blue] (maps to ct.colorlayout.BGR)

  • 'BGR': [Blue, Green, Red] (maps to ct.colorlayout.RGB)

channel_first: (bool) or None

Set to True if input format is channel first.

Default format:
  • For TensorFlow: channel last (channel_first=False).

  • For PyTorch: channel first (channel_first=True).


class, upper_bound=- 1, default=None, symbol=None)[source]
__init__(lower_bound=1, upper_bound=- 1, default=None, symbol=None)[source]

A class that can be used to give a range of accepted shapes.

lower_bound: (int)

The minimum valid value for the shape.

upper_bound: (int)

The maximum valid value for the shape.

Set to -1 if there’s no upper limit.

default: (int) or None

The default value that is used for initiating the model, and set in

input shape field of the model file.

If set to None, lower_bound would be used as default.

symbol: (str)

Optional symbol name for the dim. Autogenerate a symbol name if not specified.


class, default=None)[source]
__init__(shape, default=None)[source]

The basic shape class to be set in InputType.

shape: list of (int), symbolic values, RangeDim object

The valid shape of the input.

default: tuple of int or None

The default shape that is used for initiating the model, and set in the metadata of the model file.

If None, then shape is used.


class, shape=None, dtype=None, default_value=None)[source]
__init__(name=None, shape=None, dtype=None, default_value=None)[source]

Specify a (dense) tensor input.

name: str

Input name. Must match an input name in the model (usually the Placeholder name for TensorFlow or the input name for PyTorch).

The name is required except for a TensorFlow model in which there is exactly one input Placeholder.

shape: (1) list of positive int or RangeDim, or (2) EnumeratedShapes

The shape of the input.

For TensorFlow:
  • The shape is optional. If omitted, the shape is inferred from TensorFlow graph’s Placeholder shape.

For PyTorch:
  • The shape is required.

dtype: np.generic or mil.type type

For example, np.int32 or

default_value: np.ndarray

If provided, the input is considered optional. At runtime, if the input is not provided, default_value is used.

  • If default_value is np.ndarray, all elements are required to have the same value.

  • The default_value may not be specified if shape is EnumeratedShapes.


  • ct.TensorType(name="input", shape=(1, 2, 3))` implies `dtype == np.float32

  • ct.TensorType(name="input", shape=(1, 2, 3), dtype=np.int32)

  • ct.TensorType(name="input", shape=(1, 2, 3),