MIL Input Types¶
Input types supported by the Model Intermediate Language (MIL):
ClassifierConfig¶
-
class
coremltools.converters.mil.input_types.ClassifierConfig(class_labels, predicted_feature_name='classLabel', predicted_probabilities_output=None)¶ -
__init__(class_labels, predicted_feature_name='classLabel', predicted_probabilities_output=None)¶ Configuration for classifier models.
- Parameters
- class_labels: str / list of int / list of str
If a
listif given, thelistmaps the index of the output of a neural network to labels in a classifier.If a
stris given, thestrpoints 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)¶ -
__init__(shapes, default=None)¶ A shape class that is used for setting multiple valid shape in InputType.
- Parameters
- 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
shapesinstead.- 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
shapesis used.
-
ImageType¶
-
class
coremltools.converters.mil.input_types.ImageType(name=None, shape=None, scale=1.0, bias=None, color_layout='RGB', channel_first=None)¶ -
__init__(name=None, shape=None, scale=1.0, bias=None, color_layout='RGB', channel_first=None)¶ Configuration class used for image inputs in CoreML.
- Parameters
- scale: (float)
The scaling factor for all values in the image channels.
- bias: float or list of float
If
color_layoutis'G', bias would be afloat.If color_layout is
'RGB'or'BGR', bias would be a list offloat.- color_layout: string
Color layout of the image.
- Valid values:
'G': Grayscale'RGB': [Red, Green, Blue]'BGR': [Blue, Green, Red]
- channel_first: (bool) or None
Set to
Trueif 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)¶ -
__init__(lower_bound=1, upper_bound=- 1, default=None, symbol=None)¶ A class that can be used to give 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
-1if 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_boundwould 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)¶ -
__init__(shape, default=None)¶ 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
shapeis used.
-
TensorType¶
-
class
coremltools.converters.mil.input_types.TensorType(name=None, shape=None, dtype=None, default_value=None)¶ -
__init__(name=None, shape=None, dtype=None, default_value=None)¶ 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
nameis 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
shapeis optional. If omitted, the shape is inferred from TensorFlow graph’s Placeholder shape.
- For PyTorch:
The
shapeis required.
- dtype: np.generic or mil.type type
Numpy
dtype(for example,np.int32). Default isnp.float32.- default_value: np.ndarray
If provided, the input is considered optional. At runtime, if the input is not provided,
default_valueis used.- Limitations:
If
default_valueisnp.ndarray, all elements are required to have the same value.The
default_valuemay not be specified ifshapeisEnumeratedShapes.
Examples
ct.TensorType(name="input", shape=(1, 2, 3))` implies `dtype == np.float32ct.TensorType(name="input", shape=(1, 2, 3), dtype=np.int32)ct.TensorType(name="input", shape=(1, 2, 3), dtype=ct.converters.mil.types.fp32)
-