MIL Input Types
Input types supported by the Model Intermediate Language (MIL):
InputType
- class coremltools.converters.mil.input_types.InputType(name=None, shape=None, dtype=None)[source]
- __init__(name=None, shape=None, dtype=None)[source]
The input type for inputs fed into the model.
- Parameters:
- name: (str)
The name of the input.
- shape: list, tuple, Shape object, EnumeratedShapes object, or None
The shape(s) that are valid for this input.
If set to
None
, the shape will be infered from the model itself.
ClassifierConfig
- class coremltools.converters.mil.input_types.ClassifierConfig(class_labels, 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.
- Parameters:
- class_labels: str / list of int / list of str
If a
list
is provided, thelist
maps the index of the output of a neural network to labels in a classifier.If a
str
is provided, thestr
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.
EnumeratedShapes
- class coremltools.converters.mil.input_types.EnumeratedShapes(shapes, default=None)[source]
- __init__(shapes, default=None)[source]
A shape class for setting multiple valid shapes in InputType.
- Parameters:
- shapes: list of Shape objects, or Shape-compatible lists.
The valid shapes of the inputs.
If input provided is not a Shape object, but can be converted to a 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.
ImageType
- class coremltools.converters.mil.input_types.ImageType(name=None, 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.
- Parameters:
- scale: float or list of floats
The scaling factor for all values in the image channels.
- bias: float or list of floats
If
color_layout
isct.colorlayout.GRAYSCALE
orct.colorlayout.GRAYSCALE_FLOAT16
, bias would be afloat
.If
color_layout
isct.colorlayout.RGB
orct.colorlayout.BGR
, bias would be a list offloat
.
- 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 toct.colorlayout.GRAYSCALE
)'RGB'
: [Red, Green, Blue] (maps toct.colorlayout.BGR
)'BGR'
: [Blue, Green, Red] (maps toct.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
).
RangeDim
- class coremltools.converters.mil.input_types.RangeDim(lower_bound=1, upper_bound=-1, default=None, symbol=None)[source]
- __init__(lower_bound=1, upper_bound=-1, default=None, symbol=None)[source]
A class for providing a range of accepted shapes.
- Parameters:
- 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 is no upper limit.- default: (int) or None
The default value that is used for initiating the model, and set in the 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.
Shape
- class coremltools.converters.mil.input_types.Shape(shape, default=None)[source]
- __init__(shape, default=None)[source]
The basic shape class to be set in InputType.
- Parameters:
- 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.
TensorType
- class coremltools.converters.mil.input_types.TensorType(name=None, shape=None, dtype=None, default_value=None)[source]
- __init__(name=None, shape=None, dtype=None, default_value=None)[source]
Specify a (dense) tensor input.
- Parameters:
- 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
orcoremltools.converters.mil.mil.types.fp32
- default_value: np.ndarray
If provided, the input is considered optional. At runtime, if the input is not provided,
default_value
is used.- Limitations:
If
default_value
isnp.ndarray
, all elements are required to have the same value.The
default_value
may not be specified ifshape
isEnumeratedShapes
.
Examples
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), dtype=ct.converters.mil.types.fp32)