MIL Ops¶
Operators supported by the Model Intermediate Language (MIL):
activation¶
-
class
coremltools.converters.mil.mil.ops.defs.activation.
clamped_relu
(**kwargs)¶ If
x >= 0
return elementwisemin(beta, x)
, otherwise returnmin(beta, alpha * x)
.- Parameters
- x: tensor<*?, T> (Required)
- alpha: const fp32 (Required)
- beta: const fp32 (Required)
- Returns
- tensor<*?, T>
A tensor of the same type and shape as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.activation.
elu
(**kwargs)¶ If
x > 0
return elementwisex
, otherwise returnalpha * (e^x - 1)
.- Parameters
- x: tensor<*?, T> (Required)
- alpha: const fp32 (Optional)
Default is
1
.
- Returns
- tensor<*?, T>
A tensor of the same shape and type as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.activation.
gelu
(**kwargs)¶ Return the elementwise Gaussian error linear unit activation function for
x
.You can use
EXACT
,TANH_APPROXIMATION
, orSIGMOID_APPROXIMATION
values based on the following formulas:EXACT
:
\[f(x) = 0.5x\left ( 1+\rm{erf}\left ( \frac{x}{\sqrt{2}} \right ) \right )\]TANH_APPROXIMATION
:
\[f(x) = 0.5x\left ( 1+\rm{tanh}\left ( \sqrt{2/\pi}\left ( x + 0.044715x^3 \right ) \right ) \right )\]SIGMOID_APPROXIMATION
:
\[f(x) = x*\rm{sigmoid}(1.702x)\]- Parameters
- x: tensor<*?, T> (Required)
- mode: const str (Optional)
Use
'EXACT'
,'TANH_APPROXIMATION'
, or'SIGMOID_APPROXIMATION'
forstr
.Default is
'EXACT'
.
- Returns
- tensor<*?, T>
A tensor of the same shape and type as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.activation.
leaky_relu
(**kwargs)¶ If
x >= 0
applyx
elementwise, otherwise applyalpha * x
elementwise.- Parameters
- x: <*?, T> (Required)
- alpha: const fp32 (Optional)
Default is
0.01
.
- Returns
- tensor<*?, fp32>
A tensor of the same shape and type as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.activation.
linear_activation
(**kwargs)¶ Apply elementwise
x * alpha + beta
.- Parameters
- x: tensor<*?, T> (Required)
- alpha: const fp32 (Required)
- beta: const fp32 (Optional)
Default is
0
.
- Returns
- tensor<*?, T>
A tensor of the same shape and type as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.activation.
prelu
(**kwargs)¶ Where
i = 1 ... C
, ifx_i > 0
, returnx_i
, otherwise returnalpha_i * x_i
.- Parameters
- x: tensor<[b, C, n, m], T> (Required)
- alpha: const tensor<[C], T>, (Required)
- Returns
- tensor<[b, C, n, m], fp32>
A tensor of the same shape as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.activation.
relu
(**kwargs)¶ Return elementwise-applied rectified linear activation:
min(x, 0)
.- Parameters
- x: tensor<*?, fp32> (Required)
- Returns
- tensor<*?, fp32>
A tensor of the same shape and type as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.activation.
relu6
(**kwargs)¶ Return elementwise-applied rectified linear activation:
max(min(x, 0), 6)
.- Parameters
- x: tensor<*?, T> (Required)
- Returns
- tensor<*?, T>
A tensor of the same shape and type as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.activation.
scaled_tanh
(**kwargs)¶ Return
alpha * tanh(beta * x)
elementwise.- Parameters
- x: tensor<*?, T> (Required)
Input range is
(-inf, inf)
.
- alpha: const fp32 (Optional)
Default is
1
.
- beta: const fp32 (Optional)
Default is
1
.
- Returns
- tensor<*?, fp32>
A tensor of the same shape and type as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.activation.
sigmoid
(**kwargs)¶ Return
sigmoid(x)
elementwise.- Parameters
- x: tensor<*?, T> (Required)
- Returns
- tensor<*?, T>
A tensor of the same shape as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.activation.
sigmoid_hard
(**kwargs)¶ Return
min( max( alpha * x + beta, 0 ), 1 )
elementwise.- Parameters
- x: tensor<*?, T> (Required)
- alpha: const fp32 (Optional)
Default is
0.2
.
- beta: const fp32 (Optional)
Default is
0.5
.
- Returns
- tensor<*?, fp32>
A tensor of the same shape and type as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.activation.
softplus
(**kwargs)¶ Return
log( 1 + e^x )
elementwise.- Parameters
- x: tensor<*?, T> (Required)
- Returns
- tensor<*?, T>
A tensor of the same shape and type as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.activation.
softplus_parametric
(**kwargs)¶ Return
alpha_i * log( 1 + e^( beta_i * x_i ) )
, wherei = 1 ... C
.- Parameters
- x: tensor<[b, C, n, m], T> (Required)
- alpha: const tensor<[C], fp32> (Required)
- beta: const tensor<[C], fp32> (Required)
- Returns
- tensor<[b, C, n, m], T>
A tensor of the same shape as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.activation.
softmax
(**kwargs)¶ Return
exp(x) / tf.reduce_sum(tf.exp(x), axis)
.- Parameters
- x: tensor<*?, T> (Required)
- axis: const i32 (Optional)
Default is
-1
.
- Returns
- tensor<*?, fp32>
A tensor of the same shape and type as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.activation.
softsign
(**kwargs)¶ Return
x / ( 1 + |x| )
applied elementwise.- Parameters
- x: tensor<*?, T> (Required)
- Returns
- tensor<*?, T>
A tensor of the same shape and type as
x
.
-
class
coremltools.converters.mil.mil.ops.defs.activation.
thresholded_relu
(**kwargs)¶ Return
x
ifx >= alpha
, otherwise return0
.- Parameters
- x: tensor<*?, T> (Required)
- alpha: const fp32 (Optional)
Default is
1
.
- Returns
- tensor<*, T>
A tensor of the same shape and type as
x
.
control_flow¶
-
class
coremltools.converters.mil.mil.ops.defs.control_flow.
cond
(**kwargs)¶ Perform a conditional execution. The return types must be identical between the true and false branches.
- Parameters
- pred: tensor<[], bool> (Required)
0-D tensor (scalar) predicate to switch between true and false branches.
- _true_fn: function (Required)
A Python function that executes if
pred
evaluates toTrue
.It must take zero input (i.e, no input), and return one or more values whose type becomes the operation’s return type.
- _false_fn: function (Required)
A Python function that executes if
pred
evaluates toFalse
.It must take zero input (i.e. no input), and have return types that match those of the
if
branch.
- Returns
- tuple
Python tuple of
Variables
from one of the branches.
-
class
coremltools.converters.mil.mil.ops.defs.control_flow.
const
(**kwargs)¶ Return constant values.
- Parameters
- mode: immediate_value, file_value (Optional)
Determines how the constant value is stored in the internal MIL format.
For large constants such as convolution weights, use
file_value
.For smaller-size constants such as values of a stride, use
immediate_value
.
- val: const<*,T> (Required)
- Returns
- const<*,T>
- Attributes
- T: fp32, i32, str
-
class
coremltools.converters.mil.mil.ops.defs.control_flow.
select
(**kwargs)¶ Return the elements selected from either
a
orb
depending on thecond
.The shape of
cond
,a
, andb
must be broadcastable. You must providea
andb
together, or provide neither. If you provide neither, the operation returns the indices ofcond
that areTrue
.- Parameters
- cond: tensor<[*D1], T> (Required)
Tensor. When
True
(non-zero), select element fromx
, otherwise,y
.
- a: tensor<[*D2], T> (Optional)
Values selected at indices where
cond
isTrue
.Default is
None
.
- b: tensor<[*D3], T> (Optional)
Values selected at indices where
cond
isFalse
.Default is
None
.
- Returns
- tensor<[*D_out], T> or tensor<[n, len(D1)], int32>
If
a, b
are both provided, the return shape is based on broadcast rules fromcond, a, b
.If
a, b
areNone
, the return shape is 2-D, where the first dimensionn
is the number of matching indices incond
, andlen(D1)
is the rank ofcond
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.control_flow.
while_loop
(**kwargs)¶ Perform the body repeatedly while the condition
cond
is true.- Parameters
- _cond: function (Required)
A Python function that takes
loop_vars
as positional arguments.The function must return a
bool
Var
.
- _body: function (Required)
A Python function that takes
loop_vars
as positional arguments.The function must return the same number of output vars as
loop_var
with the same types.
- loop_vars: tuple (Required)
Python tuple of
Variables
.
- Returns
- tuple
Python tuple (same type as
loop_vars
).
-
class
coremltools.converters.mil.mil.ops.defs.control_flow.
make_list
(**kwargs)¶ Create a list of tensor elements. The elements should have the same shape. The list is similar to an auto-resizing array.
- Parameters
- init_length: <i32> (Optional)
Initial length for the list. If
dynamic_length
isFalse
,init_length
is the fixed length of the list throughout runtime.Default is
1
.
- dynamic_length: <bool> (Optional)
Initial length for the list. If
dynamic_length
isFalse
,init_length
is the fixed length of the list throughout runtime.Default is
True
.
- elem_shape: <K,i32> (Required)
Non-symbolic 1-D tensor denoting the shape of elements.
If not provided, the resulting
List
won’t have the elementary shape info, which may cause backend errors. Remedy this with SSA passes.
- dtype: const<str> (Optional)
Element tensor’s
dtype
.Default is
fp32
.
- Returns
- List[*]
-
class
coremltools.converters.mil.mil.ops.defs.control_flow.
list_length
(**kwargs)¶ Return the length of
ls
.- Parameters
- ls: List[*] (Required)
- Returns
- <i32>
Length of
ls
.
-
class
coremltools.converters.mil.mil.ops.defs.control_flow.
list_write
(**kwargs)¶ Write a value into index
index
ofls
.- Parameters
- ls: List (Required)
- index: <i32> (Required)
Size of the list.
- value: <*,T> (Optional)
Element value to write, which must match the element shape of
ls
.Default is
None
.
- Returns
- List[*]
- Attributes
- T: fp32, i32, bool
-
class
coremltools.converters.mil.mil.ops.defs.control_flow.
list_read
(**kwargs)¶ Read the value at location
index
ofls
.- Parameters
- ls: List[*] (Required)
- index: <i32> (Required)
Size of the list.
- Returns
- <*,T>
The element’s value.
- Attributes
- T: fp32, i32, bool
-
class
coremltools.converters.mil.mil.ops.defs.control_flow.
list_gather
(**kwargs)¶ Return selected values in
ls
as a packedTensor
.- Parameters
- ls: List[*] (Required)
- indices: <K,i32> (Required)
Gather from indices, whose element must be in
[0, ls.length)
at runtime.
- Returns
- <*K,T>
Selected tensors packed into a
len(ls.elem_shape)+1
rank tensor.K[0] == len(indices)
.
- Attributes
- T: fp32, i32, bool
-
class
coremltools.converters.mil.mil.ops.defs.control_flow.
list_scatter
(**kwargs)¶ Scatter
values
tols
at locationsindices
.- Parameters
- ls: List[*] (Required)
- indices: tensor<num_updates, i32> (Required)
Indices of
ls
to scatter to.Elements of
indices
must be in[0, ls.length)
at runtime.If indices are greater than or equal to the list length, the list is dynamically resized.
- value: <*,T> (Optional)
Element value to write, which must match the element shape of
ls
.Default is
None
.
- Returns
- List[*]
Updated list.
- Attributes
- T: fp32, i32, bool
conv¶
-
class
coremltools.converters.mil.mil.ops.defs.conv.
conv
(**kwargs)¶ Perform convolution over input. Currently supports only 1-D and 2-D convolution.
- Parameters
- x: tensor<[n, C_in, *d_in], T> (Required)
d_in
are (possibly runtime-determined) spatial dimensions. For example,d_in = [224, 224]
for 2D convolution.1 <= len(d_in) <= 2
: Only 1-D and 2-D convolution.C_in
is the number of input channels or depth dimensions.n
is the batch dimension.
- weight: tensor<[C_out, C_in/groups, *K], T> (Required)
Filter weights.
C_in
is the number of input channels.C_in
must be divisible bygroups
.K
are kernel sizes. For example,K = [KH, KW]
for 2-D conv.When
dilations
is not all1
,weight
has to beconst
at compile time
- strides: const tensor<[S], i32> (Optional)
Default to one vector of length equal to the number of spatial dimensions.
Strides along each of the spatial dimensions.
S == len(d_in)
.
- pad_type: const str (Required)
Must be one of the following:
valid
: No padding. This is equivalent to custom pad withpad[2*i] == pad[2*i+1] == 0, for i=0,...,len(d_in)-1
.custom
: Specify custom padding in the parameterpad
.same
: input is padded such that out spatial shapes ared_out[i] = ceil(d_in[i] / strides[i])
.
Specifically, for
i = 0,..,,len(d_in)-1
, the equivalent paddings are as follows, when dilated kernel is even (for example,(K[i]-1)*dilations[i]+1)
):pad[2*i] = ceil[((K[i]-1)*dilations[i]+1)/2]
.pad[2*i+1] = floor[((K[i]-1)*dilations[i]+1)/2]
.
Otherwise,
pad[2*i] = pad[2*i+1] = (K[i]-1) * dilations[i] / 2
.- pad: const tensor<[P], i32> (Optional. Default to all zeros)
len(P) = 2 * len(d_in)
pad
should be specified if and only ifpad_type == custom
, otherwise errors occur.pad
represents the number of elements to pad before and after each dimension. Specifically,pad[0], pad[1]
are the pad size before / after spatial dimension 0,pad[2], pad[3]
are the pad size before / after spatial dimension 1, etc.
- dilations: const tensor<[S], i32> (Optional. Default to all 1s)
Dilation value along each spatial dimension in
d_in
. See visualization.S == len(d_in)
.
- groups: const tensor<[], i32> (Optional, default to 1)
Input and output channels are split by
groups
.C_in
must be divisible bygroups
.Maximum value for group is
C_in
, in which case it is a depthwise convolution.
For examples (assuming
C_in = 16, C_out = 32
):groups == 1
,weight
has shape[32, 16, KH, KW]
: All input channels are convolved with theweight
kernel to produce all output channels.groups == 2
,weight
has shape[32, 8, KH, KW]
: Input channels 0~7 are convolved with half of theweight
kernel to produce output channels 0~15. Similarly, input channels 8~15 are convolved with the other half ofweight
to product output channels 16~31.groups == C_in
,weight
has shape[32, 1, KH, KW]
: Each input channel is convolved with its own set of filters and each produceC_out / C_in = 2
channels. This is equivalent to depthwise convolution.
- bias: const tensor<[C_out],T> (Optional, default to all 0)
Bias along output channels.
- Returns
- tensor<[n, C_out, *d_out], T>
Output activation has the same rank and spatial dimension as the input. That is,
len(d_out) == len(d_in)
.For
i=0,..,len(d_in)-1, d_out[i] = floor [(D_in[i] + pad[2*i] + pad[2*i+1] - (K[i]-1)*dilations[i] - 1) / strides[i] ] + 1
See also
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.conv.
conv_transpose
(**kwargs)¶ Perform transposed convolution (also known as deconvolution and fractionally stride convolution) over input.
conv_transpose
can also be used to compute the gradient of conv. Currently supports only 1-D and 2-D.- Parameters
- x: tensor<[n,C_in,*D_in],T> (Required)
Input data.
D_in
are spatial dimensions.1 <= len(D_in) <= 2
.C_in
is the number of input channels.
- weight: const tensor<[C_out,C_in/groups,*D_in], T> (Required)
Filter weights.
C_in, C_out
are the number of input and output channels respectively.D_in
are spatial dimensions.1 <= len(D_in) <= 2
.
- bias: const tensor<[C_out],T> (Optional, default to all 0)
Bias added along output channels.
- pad: const tensor<[P],i32> (Optional, default to all 0s)
Number of elements to pad before and after each dimension.
P == 2 * len(D_in)
.pad[2*i], pad[2*i+1]
are pad sizes before and after dimensioni
, where0 <= i < len(D_in)
.
- output_shape: const tensor<[P],i32> (Optional, default None)
Expected output shape. The first two dim must be
[n, C_out]
.The output shape of conv_transpose is underdetermined in general,
because conv can map multiple input shape to a single output shape. For example, for ‘same’ padding mode, conv_out = ceil(conv_in/stride). Hence we need output_shape when this occurs.
- pad_type: const tensor<[P],i32> (Optional, default valid)
One of
same
,valid
, orcustom
.
- strides: const tensor<[S],i32> (Optional. Default to all 1s)
Stride along each of the spatial dimensions.
S == len(D_in)
.
- dilations: const tensor<[S],i32> (Optional. Default to all 1s)
Dilation value along each spatial dimension in
d_in
. Seeconv
.S == len(D_in)
.
- groups: const tensor<[], i32> (Optional. Default to 1)
Input and output channels are separated into
groups
.C_in
andC_out
must be divisible by the number of groups. Seeconv
for examples.
- Returns
- tensor<[n,C_out,*D_out],T>
D_out[i] = (D_in[i]-1) * strides[i] + pad[2*i] + pad[2*i+1] - (K[i] - 1) * dilations[i] + 1)] for i = 0, 1
.
See also
- Attributes
- T: fp32
elementwise_binary¶
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_binary.
add
(**kwargs)¶ Return
x + y
element-wise with broadcasting.- Parameters
- x: <*,T> (Required)
Shape must be compatible with
y
in broadcast.
- y: <*,T> (Required)
Shape must be compatible with
x
in broadcast.
- Returns
- <*,T>
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_binary.
equal
(**kwargs)¶ Return the truth value of
x == y
element-wise with broadcasting (1
for true,0
for false in numeric domain).- Parameters
- x: <*,T> (Required)
Shape must be compatible with
y
in broadcast.
- y: <*,T> (Required)
Shape must be compatible with
x
in broadcast.
- Returns
- <*, bool>
A boolean tensor with the same shape as the inputs.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_binary.
floor_div
(**kwargs)¶ Return
x / y
element-wise with broadcasting, rounded towards negative infinity.- Parameters
- x: tensor<*, T> (Required)
Shape must be compatible with
y
in broadcast.
- y: tensor<*, T> (Required)
Shape must be compatible with
x
in broadcast.
- Returns
- tensor<*, T>
A tensor of the same type and shape as the inputs.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_binary.
greater
(**kwargs)¶ Return the truth value of
x > y
element-wise with broadcasting (1
for true,0
for false in numeric domain).- Parameters
- x: tensor<*, T> (Required)
Shape must be compatible with
y
in broadcast.
- y: tensor<*, T> (Required)
Shape must be compatible with
x
in broadcast.
- Returns
- tensor<*, bool>
A boolean tensor with the same shape as the inputs.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_binary.
greater_equal
(**kwargs)¶ Return the truth value of
x >= y
element-wise with broadcasting (1
for true,0
for false in numeric domain).- Parameters
- x: tensor<*, T> (Required)
Shape must be compatible with
y
in broadcast.
- y: tensor<*, T> (Required)
Shape must be compatible with
x
in broadcast.
- Returns
- tensor<*?, bool>
A boolean tensor with the same shape as the inputs.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_binary.
less
(**kwargs)¶ Return the truth value of
x < y
element-wise with broadcasting (1
for true,0
for false in numeric domain).- Parameters
- x: tensor<*, T> (Required)
Shape must be compatible with
y
in broadcast.
- y: tensor<*, T> (Required)
Shape must be compatible with
x
in broadcast.
- Returns
- tensor<*?, bool>
A boolean tensor with the same shape as the inputs.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_binary.
less_equal
(**kwargs)¶ Return the truth value of
x <= y
element-wise with broadcasting (1
for true,0
for false in numeric domain).- Parameters
- x: tensor<*, T> (Required)
Shape must be compatible with
y
in broadcast.
- y: tensor<*, T> (Required)
Shape must be compatible with
x
in broadcast.
- Returns
- tensor<*?, bool>
A boolean tensor with the same shape as the inputs.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_binary.
logical_and
(**kwargs)¶ Return the truth value of
x AND y
element-wise with broadcasting (1
for true,0
for false in numeric domain). A numeric valuet
is evaluated to true ift != 0
.- Parameters
- x: tensor<*, T> (Required)
Shape must be compatible with
y
in broadcast.
- y: tensor<*, T> (Required)
Shape must be compatible with
x
in broadcast.
- Returns
- tensor<*?, bool>
A boolean tensor with the same shape as the inputs.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_binary.
logical_or
(**kwargs)¶ Return the truth value of
x OR y
element-wise with broadcasting (1
for true,0
for false in numeric domain). A numeric valuet
is evaluated to true ift != 0
.- Parameters
- x: tensor<*, T> (Required)
Shape must be compatible with
y
in broadcast.
- y: tensor<*, T> (Required)
Shape must be compatible with
x
in broadcast.
- Returns
- tensor<*?, bool>
A boolean tensor with the same shape as the inputs.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_binary.
logical_xor
(**kwargs)¶ Return the truth value of
x XOR y
element-wise with broadcasting (1
for true,0
for false in numeric domain). A numeric valuet
is evaluated to true ift != 0
.- Parameters
- x: tensor<*, T> (Required)
Shape must be compatible with
y
in broadcast.
- y: tensor<*, T> (Required)
Shape must be compatible with
x
in broadcast.
- Returns
- tensor<*?, bool>
A boolean tensor with the same shape as the inputs.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_binary.
maximum
(**kwargs)¶ Return
x > y ? x : y
element-wise with broadcasting.- Parameters
- x: tensor<*, T> (Required)
Shape must be compatible with
y
in broadcast.
- y: tensor<*, T> (Required)
Shape must be compatible with
x
in broadcast.
- Returns
- tensor<*?, bool>
A boolean tensor with the same shape as the inputs.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_binary.
minimum
(**kwargs)¶ Return
x > y ? y : x
element-wise with broadcasting.- Parameters
- x: tensor<*, T> (Required)
Shape must be compatible with
y
in broadcast.
- y: tensor<*, T> (Required)
Shape must be compatible with
x
in broadcast.
- Returns
- tensor<*?, bool>
A boolean tensor with the same shape as the inputs.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_binary.
mod
(**kwargs)¶ Return
x % y
element-wise with broadcasting.- Parameters
- x: tensor<*, T> (Required)
Shape must be compatible with
y
in broadcast.
- y: tensor<*, T> (Required)
Shape must be compatible with
x
in broadcast.
- Returns
- tensor<*?, bool>
A boolean tensor with the same shape as the inputs.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_binary.
mul
(**kwargs)¶ Return
x * y
element-wise with broadcasting.- Parameters
- x: tensor<*, T> (Required)
Shape must be compatible with
y
in broadcast.
- y: tensor<*, T> (Required)
Shape must be compatible with
x
in broadcast.
- Returns
- tensor<*?, bool>
A boolean tensor with the same shape as the inputs.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_binary.
not_equal
(**kwargs)¶ Return the truth value of
x != y
element-wise with broadcasting (1
for true,0
for false in numeric domain).- Parameters
- x: tensor<*, T> (Required)
Shape must be compatible with
y
in broadcast.
- y: tensor<*, T> (Required)
Shape must be compatible with
x
in broadcast.
- Returns
- tensor<*?, bool>
A boolean tensor with the same shape as the inputs.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_binary.
real_div
(**kwargs)¶ Return
x / y
element-wise with broadcasting.- Parameters
- x: tensor<*, T> (Required)
Shape must be compatible with
y
in broadcast.
- y: tensor<*, T> (Required)
Shape must be compatible with
x
in broadcast.
- Returns
- tensor<*?, bool>
A boolean tensor with the same shape as the inputs.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_binary.
pow
(**kwargs)¶ Return
x ^ y
element-wise with broadcasting.- Parameters
- x: tensor<*, T> (Required)
Shape must be compatible with
y
in broadcast.
- y: tensor<*, T> (Required)
Shape must be compatible with
x
in broadcast.
- Returns
- tensor<*?, bool>
A boolean tensor with the same shape as the inputs.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_binary.
sub
(**kwargs)¶ Return
x - y
element-wise with broadcasting.- Parameters
- x: tensor<*, T> (Required)
Shape must be compatible with
y
in broadcast.
- y: tensor<*, T> (Required)
Shape must be compatible with
x
in broadcast.
- Returns
- tensor<*?, bool>
A boolean tensor with the same shape as the inputs.
- Attributes
- T: fp32
elementwise_unary¶
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_unary.
abs
(**kwargs)¶ Return the absolute values of the input
x
, element-wise.- Parameters
- x: tensor<[*d], T> (Required)
- Returns
- tensor<[*d], f32>
A tensor of the same shape as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_unary.
acos
(**kwargs)¶ Return the inverse cosine values of the input
x
, element-wise.- Parameters
- x: tensor<[*d], T> (Required)
- Returns
- tensor<[*d], f32>
A tensor of the same shape as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_unary.
asin
(**kwargs)¶ Return the inverse sine of the input
x
, element-wise.- Parameters
- x: tensor<[*d], T> (Required)
- Returns
- tensor<[*d], f32>
A tensor of the same shape as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_unary.
atan
(**kwargs)¶ Return the inverse tangent of the input
x
, element-wise.- Parameters
- x: tensor<[*d], T> (Required)
- Returns
- tensor<[*d], f32>
A tensor of the same shape as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_unary.
atanh
(**kwargs)¶ Return the inverse hyperbolic tangent values of the input
x
, element-wise.- Parameters
- x: tensor<[*d], T> (Required)
- Returns
- tensor<[*d], f32>
A tensor of the same shape as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_unary.
ceil
(**kwargs)¶ Return the ceil values of the input
x
, element-wise.- Parameters
- x: tensor<[*d], T> (Required)
- Returns
- tensor<[*d], f32>
A tensor of the same shape as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_unary.
clip
(**kwargs)¶ Clip the values in the input
x
to[alpha, beta]
, element-wise. Any values less thanalpha
are set toalpha
, and any values greater thanbeta
are set tobeta
.- Parameters
- x: tensor<[*d], T> (Required)
- alpha: const f32 (Required)
- beta: const f32 (Required)
- Returns
- tensor<[*d], f32>
A tensor of the same shape as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_unary.
cos
(**kwargs)¶ Return cosine of
x
element-wise. Input domain is(-inf, inf)
and output range is[-1,1]
.- Parameters
- x: tensor<[*d], T> (Required)
- Returns
- tensor<[*d], T>
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_unary.
cosh
(**kwargs)¶ Return hyperbolic cosine of the input
x
, element-wise.- Parameters
- x: tensor<[*d], T> (Required)
- Returns
- tensor<[*d], T>
A tensor of the same shape as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_unary.
erf
(**kwargs)¶ Return the gauss error function of the input
x
, element-wise.- Parameters
- x: tensor<[*d], T> (Required)
- Returns
- tensor<[*d], f32>
A tensor of the same shape as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_unary.
exp
(**kwargs)¶ Return the exponential values of the input
x
, element-wise.- Parameters
- x: tensor<[*d], T> (Required)
- Returns
- tensor<[*d], f32>
A tensor of the same shape as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_unary.
exp2
(**kwargs)¶ Return the exponential values of the input
x
, element-wise.- Parameters
- x: tensor<[*d], T> (Required)
- Returns
- tensor<[*d], f32>
A tensor of the same shape as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_unary.
floor
(**kwargs)¶ Return the floor of the input
x
, element-wise, the same as rounding towards negative infinity.- Parameters
- x: tensor<[*d], T> (Required)
- Returns
- tensor<[*d], f32>
A tensor of the same shape as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_unary.
inverse
(**kwargs)¶ Return the reciprocal value of the input
x
, element-wise.- Parameters
- x: tensor<[*d], T> (Required)
- epsilon: const fp32 (Optional, default=1e-4)
This is a small constant that is added to the input, before taking its inverse, for stability.
y = 1 / (x + epsilon)
.
- Returns
- tensor<[*d], f32>
A tensor of the same shape as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_unary.
log
(**kwargs)¶ Return the natural logarithm value of the input
x
, element-wise.- Parameters
- x: tensor<[*d], T> (Required)
- epsilon: const fp32 (Optional, default=1e-45)
This is a small constant that is added to the input, before taking log.
y = log(x + epsilon)
.
- Returns
- tensor<[*d], f32>
A tensor of the same shape as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_unary.
logical_not
(**kwargs)¶ Return the value of NOT the input
x
, element-wise. (1
for true,0
for false in numeric domain.) A numeric valuet
is evaluated to trueiff t != 0
.- Parameters
- x: tensor<[*d], T> (Required)
- Returns
- tensor<[*d], f32>
A tensor of the same shape as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_unary.
round
(**kwargs)¶ Return the round value of the input
x
, element-wise.- Parameters
- x: tensor<[*d], T> (Required)
- Returns
- tensor<[*d], f32>
A tensor of the same shape as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_unary.
rsqrt
(**kwargs)¶ Return the reciprocal value of the square root of the input
x
, element-wise.- Parameters
- x: tensor<[*d], T> (Required)
- epsilon: const fp32 (Optional, default=1e-12)
This is a small constant that is added to the input, before applying the
rsqrt
function, for stability.y = 1 / sqrt(x + epsilon)
.
- Returns
- tensor<[*d], f32>
A tensor of the same shape as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_unary.
sign
(**kwargs)¶ Return the sign value of the input
x
, element-wise.- Parameters
- x: tensor<[*d], T> (Required)
- Returns
- tensor<[*d], f32>
A tensor of the same shape as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_unary.
sin
(**kwargs)¶ Return the sine value of the input
x
, element-wise.- Parameters
- x: tensor<[*d], T> (Required)
- Returns
- tensor<[*d], f32>
A tensor of the same shape as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_unary.
sinh
(**kwargs)¶ Return the hyperbolic sine value of the input
x
, element-wise.- Parameters
- x: tensor<[*d], T> (Required)
- Returns
- tensor<[*d], f32>
A tensor of the same shape as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_unary.
sqrt
(**kwargs)¶ Returns the square root value of the input
x
, element-wise.- Parameters
- x: tensor<[*d], T> (Required)
- Returns
- tensor<[*d], f32>
A tensor of the same shape as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_unary.
square
(**kwargs)¶ Return the square value of the input
x
, element-wise.- Parameters
- x: tensor<[*d], T> (Required)
- Returns
- tensor<[*d], f32>
A tensor of the same shape as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_unary.
tan
(**kwargs)¶ Return the tangent value of the input
x
, element-wise. Both input and output ranges are(-inf, inf)
.- Parameters
- x: tensor<[*d], T> (Required)
- Returns
- tensor<[*d], f32>
A tensor of the same shape as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_unary.
tanh
(**kwargs)¶ Return the hyperbolic tangent value of the input
x
, element-wise. Both input and output ranges are(-inf, inf)
while output range is[-1, 1]
.- Parameters
- x: tensor<[*d], T> (Required)
- Returns
- tensor<[*d], f32>
A tensor of the same shape as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_unary.
threshold
(**kwargs)¶ Set a lower bound
alpha
to the values in the inputx
, element-wise. Any values less thanalpha
are set toalpha
.- Parameters
- x: tensor<[*d], T> (Required)
- alpha: const fp32 (Required)
- Returns
- tensor<[*d], f32>
A tensor of the same shape as
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.elementwise_unary.
cast
(**kwargs)¶ Cast the input
x
to the new typedtype
.- Parameters
- x: tensor<[*d], T> (Required)
- dtype: const str (Required)
Can be one of the following types:
int32
,int64
,fp32
,fp64
.
- Returns
- tensor<[*d], dtype>
A tensor of the same shape as
x
, with typedtype
.
- Attributes
- T: i32, i64, fp32, fp64, bool.
image_resizing¶
-
class
coremltools.converters.mil.mil.ops.defs.image_resizing.
upsample_nearest_neighbor
(**kwargs)¶ Upsample the spatial dimensions (last two dimensions) of the input by integer scale factors using nearest-neighbor interpolation.
- Parameters
- x: tensor<[*D, H1, W1],T> (Required)
Must be at least rank
3
.
- scale_factor_height: const<i32> or const<fp32> (Optional, default=1)
Scale factor for the height dimension (
axis=-2
).Can be either an integer or fractional.
- scale_factor_width: const<i32> or const<fp32> (Optional, default=1)
Scale factor for the width dimension (
axis=-1
).Can be either an integer or fractional.
- Returns
- tensor<[*D, H2, W2],T>
Tensor with same type as the input.
H2
= floor(H1
*scale_factor_height
).W2
= floor(W1
*scale_factor_width
).
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.image_resizing.
upsample_bilinear
(**kwargs)¶ Upsample the spatial dimensions (last two dimensions) of the input by scale factors using bilinear interpolation.
- Parameters
- x: tensor<[*D, H1, W1],T> (Required)
Must be at least rank
3
.
- scale_factor_height: const<T2> (Optional, default=1)
Scale factor for the height dimension (
axis=-2
).
- scale_factor_width: const<T2> (Optional, default=1)
Scale factor for the width dimension (
axis=-1
).
- align_corners: const<bool> (Optional, default=True)
This parameter determines how samples are chosen for bilinear interpolation. For details, see the Notes section.
- Returns
- tensor<[*D, H2, W2],T>
Tensor with same type as the input.
H2
= floor(H1
*scale_factor_height
).W2
= floor(W1
*scale_factor_width
).
Notes
To understand the
align_corners
parameter, consider the 1-D case. You need to sample a grid of pixels whose values are computed using linear interpolation. This parameter controls how the grid is sampled. If the input grid is[0, Xin-1]
(corresponding to an input size ofXin
), and if the output size isXout
, then the grid points are sampled in the following manner:# If align_corners == True: spacing = (Xin - 1) / (Xout - 1) grid_point[i] = min(Xin - 1, max(0, i*spacing)), for i=0,1,...,Xout-1 # If align_corners == False: spacing = Xin / Xout grid_point[i] = min(Xin - 1, max(0, i*spacing + 0.5*spacing - 0.5)), ... for i=0,1,...,Xout-1
For example:
Xin = 2 input_interval = [0,1]
Grid points:
[0., 0.1, 0.5, 0.9, 1.] (Xout = 5, align_corners=False) [0., 0.25, 0.5, 0.75, 1.] (Xout = 5, align_corners=True) [0., 0., 0.33, 0.67, 1., 1.] (Xout = 6, align_corners=False) [0., 0.2, 0.4, 0.6, 0.8, 1.] (Xout = 6, align_corners=True)
Note the following similarities:
align_corners=False
is the same astf.raw_ops.ResizeBilinear(align_corners=False, half_pixel_centers=True)
.align_corners=True
is the same astf.raw_ops.ResizeBilinear(align_corners=True, half_pixel_centers=False)
.
- Attributes
- T: fp32
- T2fp32 or int32
-
class
coremltools.converters.mil.mil.ops.defs.image_resizing.
resize_bilinear
(**kwargs)¶ Resize the spatial (last two) dimensions to the specified target size using bilinear interpolation. Although this op is similar to
upsample_bilinear
,resize_bilinear
works with a target size rather than with scale factors.- Parameters
- x: tensor<[*D, H1, W1],T> (Required)
Must be at least rank
3
.
- target_size_height: const<int32> (Optional, default=1)
Target spatial size for the height dimension (
axis=-2
).
- target_size_width: const<int32> (Optional, default=1)
Target spatial size for the width dimension (
axis=-1
).
- sampling_mode: const<str> (Optional, default=”DEFAULT”)
This parameter can take
"STRICT_ALIGN_CORNERS”
,"ALIGN_CORNERS"
,"DEFAULT"
,"OFFSET_CORNERS"
orUNALIGN_CORNERS
as values. For details, see the Notes section.
- Returns
- tensor<[*D, H2, W2],T>
Tensor with same type as the input.
H2
=target_size_height
.W2
=target_size_width
.
Notes
To understand the
sampling_mode
parameter, consider the 1-D case. You need to sample a grid of pixels whose values are computed using linear interpolation. This parameter controls how the grid is sampled. If the input grid is[0, Xin-1]
(corresponding to an input size ofXin
), and if the output size isXout
, then the grid points are sampled in the following manner:# "STRICT_ALIGN_CORNERS": spacing = (Xin - 1) / (Xout - 1) grid_point[i] = min(Xin-1, max(0, i*spacing)), for i=0,1,...,Xout-1 # "ALIGN_CORNERS": Same as "STRICT_ALIGN_CORNERS" unless Xout=1, # in which case: grid_point[0] = (Xin-1) / 2, if Xout==1 # "DEFAULT": spacing = (Xin - Xin/Xout) / (Xout - 1) grid_point[i] = min(Xin-1, max(0, i*spacing)), for i=0,1,...,Xout-1 # "OFFSET_CORNERS": delta = max(1, Xin - 1) / Xout spacing = ((Xout - 1) * delta) / (Xout - 1) grid_point[i] = min(Xin-1, max(0, 0.5*delta + i*spacing)), for ... i=0,1,...,Xout-1 # "UNALIGN_CORNERS": spacing = Xin / Xout grid_point[i] = min(Xin - 1, max(0, i*spacing + 0.5*spacing - 0.5)), for i=0,1,...,Xout-1
For example:
Xin = 2 input_interval = [0,1]
Grid points:
[0., 0.1, 0.5, 0.9, 1.] (Xout = 5, UNALIGN_CORNERS) [0., 0.25, 0.5, 0.75, 1.] (Xout = 5, "STRICT_ALIGN_CORNERS" / "ALIGN_CORNERS") [0., 0.4, 0.8, 1., 1.] (Xout = 5, "DEFAULT") [0.1, 0.3, 0.5, 0.7, 0.9] (Xout = 5, "OFFSET_CORNERS") [0., 0., 0.33, 0.67, 1., 1.] (Xout = 6, UNALIGN_CORNERS) [0., 0.2, 0.4, 0.6, 0.8, 1.] (Xout = 6, "STRICT_ALIGN_CORNERS" / "ALIGN_CORNERS") [0., 0.33, 0.67, 1., 1., 1.] (Xout = 6, "DEFAULT") [0.08, 0.25, 0.42, 0.58, 0.75, 0.92] (Xout = 6, "OFFSET_CORNERS")
Note the following similarities:
"DEFAULT"
is same astf.raw_ops.ResizeBilinear(align_corners=False, half_pixel_centers=False)
."STRICT_ALIGN_CORNERS"
is same astf.raw_ops.ResizeBilinear(align_corners=True, half_pixel_centers=False)
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.image_resizing.
crop_resize
(**kwargs)¶ Resize the spatial dimensions (last two dimensions) of the first input according to the bounding boxes specified in the second input, using bilinear interpolation.
- Parameters
- x: tensor<[B, C, H, W],T> (Required)
The input, from which patches (regions of interest) are extracted and resized using bilinear interpolation.
Rank
4
.
- roi: tensor<[N,1,4,1,1], T> or tensor<[N,1,5,1,1], T> (Required)
Regions of interest, or coordinates of the boxes. The above input represents coordinates of
N
boxes.The convention to express coordinates depends on the value of the input
box_coordinate_mode
.Rank
5
.If
tensor<[N,1,4,1,1], T>
: Resized images are computed for allB
input images.If
tensor<[N,1,5,1,1], T>
: The first element fromaxis=-3
to be resized is an index. It must be within range[0, B)
.
- target_height: const<i32> (Optional, Default=1)
Target height for resizing each patch.
- target_width: const<i32> (Optional, Default=1)
Target width for resizing each patch.
- normalized_coordinatesconst<bool> (Optional, default=False)
If true, the bounding box coordinates must be in the interval
[0, 1]
. Scaling is based on the input spatial dimensions:(H_in - 1)
for height and(W_in - 1)
for width.If false, the bounding box coordinates must be in the interval
[0, H_in - 1]
for height dimensions and[0, W_in - 1]
for width dimensions.
- spatial_scaleconst<fp32> (Optional, default=1.0)
Additional spatial scale that multiplies the bounding box coordinates. You would use this to implement the RoI Align layer, which typically uses unnormalized RoI coordinates along with a spatial scale that is less than or equal to 1.
- box_coordinate_mode: const<str> (Optional, default=”CORNERS_HEIGHT_FIRST”)
Specifies the convention for specifying the four bounding box coordinates for an image of size
(Height, Width)
. The(0,0)
coordinate corresponds to the top-left corner of the image.This parameter can take one of four values:
“CORNERS_HEIGHT_FIRST”:
[h_start, w_start, h_end, w_end]
“CORNERS_WIDTH_FIRST”:
[w_start, h_start, w_end, h_end]
“CENTER_SIZE_HEIGHT_FIRST”:
[h_center, w_center, box_height, box_width]
“CENTER_SIZE_WIDTH_FIRST”:
[w_center, h_center, box_width, box_height]
- sampling_modeconst<str> (Optional, default=”DEFAULT”)
This parameter can take
"STRICT_ALIGN_CORNERS"
,"ALIGN_CORNERS"
,"DEFAULT"
,"OFFSET_CORNERS"
orUNALIGN_CORNERS
as values.This same convention is used by the
resize_bilinear
op (see that op for details).
- Returns
- tensor<[N, B, C, target_height, target_width],T> or tensor<[N, 1, C, target_height, target_width],T>
Tensor with same type as the input.
If
roi : tensor<[N,1,4,1,1], T>
, the output istensor<[N, B, C, target_height, target_width],T>
. Total crops =N*B
; that is,N
crops for each input in the batch.If
roi : tensor<[N,1,5,1,1], T>
, the output istensor<[N, 1, C, target_height, target_width],T>
. Total crops =N
; that is, 1 crop for given input image index in the batch.
See also
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.image_resizing.
crop
(**kwargs)¶ Crop the spatial dimensions (last two dimensions) of the input by the specified amounts.
- Parameters
- x: tensor<[*D, H1, W1],T> (Required)
Must be at least rank
3
.
- crop_height: const<2, i32> (Required)
Amount to be cropped from the top and bottom of the height dimension (
axis=-2
).
- crop_width: const<2, i32> (Required)
Amount to be cropped from the left and right sides of the width dimension (
axis=-1
).
- Returns
- tensor<[*D, H2, W2],T>
Tensor with same type as the input.
H2
=H1
- crop_height[0] - crop_height[1].W2
=W1
- crop_width[0] - crop_width[1].
- Attributes
- T: fp32
linear¶
-
class
coremltools.converters.mil.mil.ops.defs.linear.
linear
(**kwargs)¶ Perform
x * weight.T + bias
whereweight
andbias
are constant at compile time.- Parameters
- x: tensor<[*D,D_in], T> (Required)
1 <= rank <= 3
.0 <= rank(*D) <= 2
.
- weight: const tensor<[D_out,D_in], T> (Required)
- bias: const tensor<[D_out],T> (Optional)
Default to
0
.
- Returns
- tensor<[*D,D_out], T>
Same rank as the input
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.linear.
matmul
(**kwargs)¶ Perform N-D batch matrix multiplication with NumPy-style broadcasting based on the following rules:
Rule 1. If both
x, y
are 1-D, return the scalar from the dot product.Rule 2. If both
x, y
are 2-D or higher, perform a broadcast on the batch dimensions (all dimensions except the last2
).For example:
x.shape == (10, 4, 3)
y.shape == (5, 10, 3, 2)
matmul(x, y).shape == (5, 10, 4, 2)
Conventional matrix multiplication is a special case where both
x, y
are exactly 2-D. For example:x.shape == (4, 3)
y.shape == (3, 2)
matmul(x, y).shape == (4, 2)
If
x
is 1-D, andy
is N-D whereN >= 2
,x
is first promoted to matrixxm
by prepending a1
to its dimension, and the resultingxm
is broadcast toy
following Rule 2 above. After this, remove the inserted dimension. For example:x.shape == (4)
y.shape == (10, 4, 3)
xm.shape == (1, 4)
matmul(xm, y).shape == (10, 1, 3)
Removing the inserted dimension results in
matmul(x, y).shape == (10, 3)
.Note:
xm
andmatmul(xm, y)
are for illustration only.
If
x
is N-D whereN >= 2
, andy
is 1-D,y
is first promoted to matrixym
by appending a1
to its dimension, and the resultingym
is broadcast tox
following Rule 2 above. After this, remove the inserted dimension. For example:x.shape == (10, 3, 4)
y.shape == (4,)
ym.shape == (4, 1)
matmul(x, ym).shape == (10, 3, 1)
Removing the inserted dimension results in
matmul(x, y).shape == (10, 3)
.Note:
xm
andmatmul(xm, y)
are for illustration only.
- Parameters
- x: tensor<[*,K1], T> (Required)
x
must be 1-D or higher.
- y: tensor<[*,K2], T> (Required)
y
must be 1-D or higher.
- transpose_x: const bool (Optional)
Default to
False
.Use
True
to transpose the last two dimensions ofx
before multiplication. It has no effect whenx
is 1-D.
- transpose_y: const bool (Optional)
Default to
False
.Use
True
to transpose the last two dimensions ofy
before multiplication. It has no effect wheny
is 1-D.
- Returns
- tensor<*, T>
Scalar or tensor output.
- Attributes
- T: fp32
normalization¶
-
class
coremltools.converters.mil.mil.ops.defs.normalization.
batch_norm
(**kwargs)¶ Normalize input tensor
x
bymean
andvariance
, and optionally apply a scalegamma
and an offsetbeta
:\[y_i = \gamma_i \dfrac{ (x_i - mean_i)}{\sqrt{variance_i + epsilon}} + beta_i \;,\;i=1,....,C\]The
mean
,variance
,gamma
, andbeta
must be 1-D tensors whose lengths are equal to the second axis (the “depth” or “channel” dimension) ofx
.- Parameters
- x: tensor<[n,C,*D], T> (Required)
3 <= rank <= 4
.*D
refers to the spatial dimensions,1 <= rank(*D) <= 2
.n
is the batch dimension.
- mean: const tensor<[C], T> (Required)
- variance: const tensor<[C], T> (Required)
- gamma: const tensor<[C], T> (Optional)
Optional scale applied to normalized tensor.
Default is all ones.
- beta: const tensor<[C], T> (Optional)
Optional offset applied to normalized tensor.
Default is all zeros.
- epsilon: const fp32 (Optional)
Default is
1e-5
.
- Returns
- tensor<[n,C,*D], T>
Output tensor has the same shape and type as the input
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.normalization.
instance_norm
(**kwargs)¶ Apply instance normalization to the n-dimensional input tensor.
- Parameters
- x: tensor<[n,C,*D], T> (Required)
3 <= rank(x) <= 4
.*D
refers to the spatial dimensions,1 <= rank(*D) <= 2
.n
is the batch dimension.
- gamma: const tensor<[C], T> (Optional)
Optional scale applied to normalized tensor.
Default to all ones.
- beta: const tensor<[C], T> (Optional)
Optional offset applied to normalized tensor.
Default to all zeros.
- epsilon: const f32 (Optional)
Default to
1e-5
.
- Returns
- tensor<[n,C,*D], T>
Output tensor has the same shape and type as the input
x
.
-
class
coremltools.converters.mil.mil.ops.defs.normalization.
l2_norm
(**kwargs)¶ Apply L2 normalization to the n-dimensional input tensor. That is, divide the input tensor by the square root of the sum of squares of all elements of the input.
\[x_i \leftarrow \dfrac{x_i}{\sqrt{\sum{x_i^2} + \epsilon}}\]- Parameters
- x: tensor<[*D,C,H,W], T> (Required)
Input tensor,
rank(x) >= 3
.*D
refers to the spatial dimensions,rank(*D) >= 0
.n
is the batch dimension.For ranks greater than 3, the leading dimensions, starting from
0
to-4
(inclusive), are all treated as batch.
- epsilon: const fp32 (Optional)
Small constant to avoid division by
0
.Optional, defaults to
1e-6
.
- Returns
- tensor<[*D,C,H,W], T>
Same type and shape as the input tensor
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.normalization.
layer_norm
(**kwargs)¶ Apply layer normalization to the n-dimensional input tensor:
\[out = gamma * (input - E[x]) / sqrt(Var[x] + epsilon) + beta\]- Parameters
- x: tensor<*?, T> (Required)
Input tensor.
- axes: const<[K], i32> (Optional)
Dimensions to perform layer normalization.
Default is
None
(all dimensions).
- gamma: const tensor<[K], T> (Optional)
if provided, the shape must be be
x.shape[axes]
. For instance, if inputx
with shape(3,4,5,6)
andaxes = [2,3]
, gamma must have shape(5,6)
.Default is all ones.
- beta: const tensor<[K], T> (Optional)
Same shape as gamma.
Default is all zeros.
- epsilon: const fp32 (Optional)
Small constant to avoid division by
0
.Default is
1e-5
.
- Returns
- tensor<*?, T>:
Tensor with same shape and type as the input tensor
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.normalization.
local_response_norm
(**kwargs)¶ Apply local response normalization to the n-dimensional input tensor:
\[x_i \leftarrow \dfrac{x_i}{\left ( k + \dfrac{\alpha}{ ext{size}} \sum_j x_j^2 \right )^\beta}\]- Parameters
- x: tensor<[n,C,*D], T> (Required)
Input tensor,
3 <= rank(x) <= 4
.*D
refers to the spatial dimensions,1 <= rank(*D) <= 2
.n
is the batch dimension.
- size: const i32 (Required)
Amount of neighboring channels to normalize.
- alpha: const fp32 (Optional)
Scale factor.
Default is
1e-4
.
- beta: const fp32 (Optional)
An exponent.
Default is
0.75
.
- k: const fp32 (Optional)
Additive factor.
Default is
1.0
.
- Returns
- tensor<[n,C,*D], T>
Same type and shape as the input tensor
x
.
- Attributes
- T: fp32
pool¶
-
class
coremltools.converters.mil.mil.ops.defs.pool.
avg_pool
(**kwargs)¶ Perform average pooling. Currently defined only for spatial 1-D and 2-D cases. (Can be extended to the 3-D case easily.)
- Parameters
- x: tensor<[n,C_in,*D_in],T> (Required)
3 <= rank <= 5
.D_in
are spatial dimensions,1 <= len(D_in) <= 2
.C_in
is the number of input channels or depth dimensions.n
is the batch dimension.
- kernel_sizes: const tensor<[K],T> (Required)
The size of the window for each spatial dimension
D_in
of the input tensor.K == len(D_in)
- strides: const tensor<[S],i32> (Optional, default to all 1s)
Stride along each of the spatial dimensions.
S == len(D_in)
.
- pad_type: const str (Required)
Must be one of the following:
valid
: No padding. This is equivalent to custom pad withpad[i] = 0, for all i
.custom
: Specify custom padding in the parameter pad. note that “same” padding is equivalent to custom padding withpad[2*i] + pad[2*i+1] = kernel_size[i]
.
- pad: const<[P],i32> (Optional. Default to all 0s)
pad
represents the number of elements to pad before and after each dimension: pad[2*i], pad[2*i+1] are the pad size before and after spatial dimensioni
.P = 2 * len(D_in)
.pad
should be specified if and only ifpad_type == custom
- exclude_padding_from_average: const tensor<[], bool> (Optional, default to False)
If ‘’True’’, padded values (0s) are excluded from the denominator count when computing the average over the kernel window.
- Returns
- tensor<[n, C_out,*D_out],T>
Same rank as
x
.D_out[i] = floor[(D_in[i] + pad[2*i] + pad[2*i+1] - kernel_sizes[i]) / strides[i]] +1, for i = 0, .., len(D_in) - 1
is mathematically the same as (when all parameters involved are integers):D_out[i] = ceil [(D_in[i] + pad[2*i] + pad[2*i+1] - kernel_size[i] - 1) / stride[i]], for i = 0, .., len(D_in) - 1
.*D_out
is all 1s ifglobal_pooling
istrue
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.pool.
l2_pool
(**kwargs)¶ Perform L2 pooling. Currently supports only 1-D and 2-D.
- Parameters
- x: tensor<[n,C_in,*D_in],T> (Required)
See
avg_pool
.
- kernel_sizes: const tensor<[K],T> (Required)
See
avg_pool
.
- strides: const tensor<[S],i32> (Optional, default to all 1s)
See
avg_pool
.
- pad_type: const str (Required)
See
avg_pool
.
- pad: const<[P],i32> (Optional, default to all 0s)
See
avg_pool
.
- Returns
- tensor<[n, C_out,*D_out],T>
See
avg_pool
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.pool.
max_pool
(**kwargs)¶ Perform max pooling. Currently supports only 1-D and 2-D.
- Parameters
- x: tensor<[n,C_in,*D_in],T> (Required)
See
avg_pool
.
- kernel_sizes: const tensor<[K],T> (Required)
See
avg_pool
.
- strides: const tensor<[S],i32> (Optional, default to all 1s)
See
avg_pool
.
- pad_type: const str (Required)
See
avg_pool
.
- pad: const<[P],i32> (Optional, default to all 0s)
See
avg_pool
.
- Returns
- tensor<[n, C_out,*D_out],T>
See
avg_pool
.
- Attributes
- T: fp32
random¶
-
class
coremltools.converters.mil.mil.ops.defs.random.
random_bernoulli
(**kwargs)¶ Returns a tensor with the specified shape, with random values from a Bernoulli distribution.
\[\begin{split}f(k) = \begin{cases}1-p &\text{if } k = 0\\ p &\text{if } k = 1\end{cases}\end{split}\]for \(k\) in \(\{0, 1\}\).
- Parameters
- shape: <K, i32> (Required)
Target output tensor shape.
K
is the rank of the output tensor.shape[k] > 0
fork = 0,..., K-1
.
- prob: const<f32> (Optional)
The probability of sampling
1
. Defaults to0.5
.
- seed: const<i32> (Optional)
Seed to create a reproducible sequence of values across multiple invokes.
- Returns
- <*, T>
A tensor of the given target output shape filled with random values.
See also
-
class
coremltools.converters.mil.mil.ops.defs.random.
random_categorical
(**kwargs)¶ Returns random values from a categorical distribution.
- Parameters
- shape: <*D_in, T>
N-dimensional tensor, one of
logits
(event log-probabilities) orprobs
(event probabilities). The firstN - 1
dimensions specifies distributions, and the last dimension represents a vector of probabilities.
- mode: const<str> (Optional)
One of
['logits', 'probs']
. Defaults tologits
.- size: const<i32> (Optional)
Number of samples to draw. Defaults to
1
.- seed: const<i32> (Optional)
Seed to create a reproducible sequence of values across multiple invokes.
- Returns
- <*D_in[:-1] + [size], T>
A tensor of the given target output shape filled with random values.
See also
-
class
coremltools.converters.mil.mil.ops.defs.random.
random_normal
(**kwargs)¶ Returns a tensor with the specified shape, with random values from a normal distribution.
- Parameters
- shape: <K, i32> (Required)
Target output tensor shape.
K
is the rank of the output tensor.shape[k] > 0
fork = 0,..., K-1
.
- mean: const<f32> (Optional)
The mean (center) of the normal distribution. Defaults to 0.0.
- stddev: const<f32> (Optional)
The standard deviation (width) of the normal distribution. Defaults to
1.0
.- seed: const<i32> (Optional)
Seed to create a reproducible sequence of values across multiple invokes.
- Returns
- <*, T>
A tensor of the given target output shape filled with random values.
See also
-
class
coremltools.converters.mil.mil.ops.defs.random.
random_uniform
(**kwargs)¶ Returns a tensor with the specified shape with random values from a uniform distribution. Samples are uniformly distributed over the half-open interval
[low, high)
(includes low, but excludes high).\[p(x) = \frac{1}{high - low}\]For a real number \(x\).
When
high == low
, values oflow
will be returned. Ifhigh < low
, the results are officially undefined and may eventually raise an error.- Parameters
- shape: <K, i32> (Required)
Target output tensor shape.
K
is the rank of the output tensor.shape[k] > 0
fork = 0,..., K-1
.
- low: const<f32> (Optional)
Lower boundary of the output interval (inclusive). Defaults to
0.0
.
- high: const<f32> (Optional)
Upper boundary of the output interval (exclusive). Defaults to
1.0
.
- seed: const<i32> (Optional)
Seed to create a reproducible sequence of values across multiple invokes.
- Returns
- <*, T>
A tensor of the given target output shape filled with random values.
See also
recurrent¶
-
class
coremltools.converters.mil.mil.ops.defs.recurrent.
gru
(**kwargs)¶ Gated recurrent unit (GRU).
\[r_t = \rm{recurrent\_activation}(W_{ir} x_t + b_{ir} + W_{hr} h_{t-1} + b_{hr})\]\[z_t = \rm{recurrent\_activation}(W_{iz} x_t + b_{iz} + W_{hz} h_(t−1) + b_{hz})\]\[o_t = activation(W_{io} x_t + b_{io} + r_t * (W_{ho} h_(t−1) + b_{ho}))\]\[h_t = (1 − z_t) * o_t + z_t * h_{(t−1)}\]Where:
W_{ir}
,W_{iz}
, and `` W_{io}`` state input-hidden weight for reset, update and output gate, respectively.Similar to the above,
W_{h[r/z/o]}
states hidden-hidden / recurrent weights.h_t
is the hidden state at timet
.x_t
is the input at timet
.h_(t-1)
is the hidden state of the layer at timet-1
or the initial hidden state at time0
.r_t
,z_t
, ando_t
are the reset, update, and new gates, respectively.*
is elementwise product.
- Parameters
- x: <s, b, I, T> (Required)
s
is the sequence length,b
is the batch size, andI
is the input dimension.
- initial_h: <b, H, T> (Required)
H
denotes hidden size.
- weight: const<I+H, 3*H, T> (Required) - Weight matrix
weight[:I] = [W_{iz} | W_{ir} | W_{io}]
where[a|b]
denotes column concatenation and[a, b]
denotes row concatenation.W_{iz}
,W_{ir}
, andW_{io}
have shape(I, H)
.weight[I:] = [W_{hz} | W_{hr} | W_{hn}]
:W_{hz}
,W_{hr}
, andW_{hn}
have shape(H, H)
.
- bias: const<2, 3*H, T> (Optional) [Default all 0s]
bias[0]
andbias[1]
are input-hidden and hidden-hidden bias, respectively.3*H
are biases for[b_{ir} + b_{hr}, b_{iz} + b_{hz}, b_{io} + b_{ho}]
.
- direction: const<str> (Optional) [Default=forward]
Either
forward
orreverse
.
- output_sequence: const<bool> (Optional) [Default=False]
Outputs every step if
True
.
- recurrent_activation: const<str> (Optional) [Default=sigmoid]
Activation applied on update and reset gate.
- activation: const<str> (Optional) [Default=tanh]
Activation applied on output gate.
- Returns
- <s, b, H, T> or <1, b, H, T>
If
output_sequence == True
(hidden states from every step):<s, b, H, T>
.Else
<1, b, H, T>
(hidden states of the final step).
- <b, H, T>
Hidden states of the final step.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.recurrent.
lstm
(**kwargs)¶ Single long short-term memory (LSTM) sequence.
\[i_t = \rm{recurrent\_activation}(W_{ii} x_t + B_{ii} + W_{hi} h_(t-1) + B_{hi})\]\[f_t = \rm{recurrent\_activation}(W_{if} x_t + B_{if} + W_{hf} h_(t-1) + B_{hf})\]\[z_t = cell_activation(W_{iz} x_t + B_{iz} + W_{hz} h_(t-1) + B_{hz})\]\[o_t = \rm{recurrent\_activation}(W_{io} x_t + B_{io} + W_{ho} h_(t-1) + B_{ho})\]\[c_t = f_t * c_(t-1) + i_t * z_t\]\[h_t = o_t * activation(c_t)\]Where:
i_t
,f_t
,o_t
, andz_t
are input, forget, output, and cell gates, respectively, at timet
.c_t
is cell state at timet
.h_t
is the hidden state at timet
.W_{ii}
,W_{if}
,W_{io}
, andW_{iz}
are input weights for input, forget, output and cell gate, respectively.W_{hi}
,W_{hf}
,W_{ho}
, andW_{hz}
are recurrent weights for input, forget, output and cell gate, respectively.
- Parameters
- x: <s, b, I, T> (Required)
s
is the sequence length,b
is the batch size, andI
is the input dimension.
- initial_h: <b, DIRECTION*H, T> (Required)
Initial hidden state.
DIRECTION = 1
for uni-directional,2
for bi-directional LSTM.H
denotes hidden size.[b, :H]
and[b, H:]
represents forward and reverse direction values, respectively.
- initial_c: <b, DIRECTION*H, T> (Required)
Initial cell state.
Format is same as
initial_h
.
- weight: const<I+H, 4*DIRECTION*H, T> (Required) - Weight matrix
Weight tensor should be in order of
[input_gate, forget_gate, output_gate, cell_gate]
.[I+H, :4*H]
and[I+H, 4*H:]
represent forward and reverse direction values, respectively.
- bias: const<2, 4*DIRECTION*H, T> (Optional) [Default all 0s]
bias[0]
andbias[1]
are input-hidden and hidden-hidden bias, respectively.
- direction: const<str> (Optional) [Default=forward]
One of the following:
forward
,reverse
, orbidirectional
.Must match
DIRECTIONAL
in initial states and weight parameters.
- output_sequence: const<bool> (Optional) [Default=False]
Outputs every step if
True
.
- recurrent_activation: const<str> (Optional) [Default=sigmoid]
Activation applied on input, forget, and output gates.
- cell_activation: const<str> (Optional) [Default=tang]
Activation applied on cell gate.
- activation: const<str> (Optional) [Default=tanh]
Activation applied on output gate.
- peephole: const<3*DIRECTION*H, T> (Optional, default to 0)
Weight tensor for peephole.
Order is
[input_gate, forget_gate, output_gate]
.Shape of each peephole vector is
(H,)
(H
is hidden size).
- clip: const<fp32> (optional) [Default=None]
Cell gate is clipped to
[-clip, +clip]
.
- Returns
- <s, b, DIRECTION*H, T> or <1, b, DIRECTION*H, T>
If
output_sequence == True
(hidden states from every step):<s, b, DIRECTION*H, T>
.Else
<1, b, DIRECTION*H, T>
(hidden states of the final step).
- <b, DIRECTION*H, T>
Hidden states of the final step.
- <b, DIRECTION*H, T>
Memory state of the final step.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.recurrent.
rnn
(**kwargs)¶ Recurrent neural network (RNN).
\[h_t = activation(W_{ih} x_t + b_{ih} + W_{hh} h_(t−1) + b_{hh})\]Where:
W_{ih}
is input weight.W_{hh}
is hidden/recurrent weight.h_t
is the hidden state at timet
.x_t
is the input at timet
.h_(t-1)
is the hidden state of the layer at timet-1
or the initial hidden state at time0
.
- Parameters
- x: <s, b, I, T> (Required)
s
is the sequence length,b
is the batch size, andI
is the input dimension.
- initial_h: <b, H, T> (Required)
H
denotes hidden size.
- weight: const<I+H, 3*H, T> (Required) - Weight matrix
- bias: const<2, H, T> (Optional) [Default all 0s]
bias[0]
andbias[1]
are input-hidden and hidden-hidden bias, respectively.
- direction: const<str> (Optional) [Default=forward]
Either
forward
orreverse
.
- output_sequence: const<bool> (Optional) [Default=False]
Outputs every step if
True
.
- activation: const<str> (Optional) [Default=tanh]
Supported activation functions:
relu
,tanh
,sigmoid
,sigmoid_hard
,scaled_tanh
, andlinear
.
- Returns
- <s, b, H, T> or <1, b, H, T>
If
output_sequence == True
(hidden states from every step):<s, b, H, T>
.Else
<1, b, H, T>
(hidden states of the final step).
- <b, H, T>
Hidden states of the final step.
- Attributes
- T: fp32
reduction¶
-
class
coremltools.converters.mil.mil.ops.defs.reduction.
reduce_arg
(**kwargs)¶
-
class
coremltools.converters.mil.mil.ops.defs.reduction.
reduce_argmax
(**kwargs)¶ Computes the indices of the maximum value across dimensions of a tensor. In case of ties, the identity of the return value is not guaranteed.
- Parameters
- x: <*,T> (Required)
Must be 1-dimensional or higher.
- axis: const<i32> (Optional)
The dimension to reduce. Default is
-1
.
- keep_dims: const<bool> (Optional, default=False)
If
False
, the rank is reduced by1
by removing the dimension specified inaxis
. IfTrue
, retain reduced axis with length1
.
- Returns
- <*, int32>
References
See tf.math.argmax.
- Attributes
- T: f32, int32
-
class
coremltools.converters.mil.mil.ops.defs.reduction.
reduce_argmin
(**kwargs)¶ Computes the indices of the minimum value across dimensions of a tensor. In case of ties, the identity of the return value is not guaranteed.
- Parameters
- x: <*,T> (Required)
Must be 1-dimensional or higher.
- axis: const<i32> (Optional)
The dimension to reduce. Default is
-1
.
- keep_dims: const<bool> (Optional, default=False)
If
False
, the rank is reduced by1
by removing the dimension specified inaxis
, otherwise retain reduced axis with length1
.
- Returns
- <*, int32>
References
See tf.math.argmin.
- Attributes
- T: f32, int32
-
class
coremltools.converters.mil.mil.ops.defs.reduction.
reduce_l1_norm
(**kwargs)¶ Computes the L1 normalization of elements across given dimensions of the input tensor.
- Parameters
- x: <*,T> (Required)
Must be 1-dimensional or higher.
- axes: const<K,i32> (Optional, default=”None”, reduce on all axes.)
The dimensions to reduce.
- keep_dims: const<bool> (Optional, default=False)
If
False
, the rank is reduced by1
for each entry inaxes
, otherwise retain reduced axes with length1
.
- Returns
- <*,T>
Scalar or tensor: The reduced tensor.
References
See reduce_mean.
- Attributes
- T: f32, int32
-
class
coremltools.converters.mil.mil.ops.defs.reduction.
reduce_l2_norm
(**kwargs)¶ Computes the L2 normalization of elements across given dimensions of the input tensor.
- Parameters
- x: <*,T> (Required)
Must be 1-dimensional or higher.
- axes: const<K,i32> (Optional, default=”None”, reduce on all axes.)
The dimensions to reduce.
- keep_dims: const<bool> (Optional, default=False)
If
False
, the rank is reduced by1
for each entry inaxes
, otherwise retain reduced axes with length1
.
- Returns
- <*,T>
Scalar or tensor: The reduced tensor.
- Attributes
- T: f32, int32
-
class
coremltools.converters.mil.mil.ops.defs.reduction.
reduce_log_sum
(**kwargs)¶ Computes the natural logarithm of the sum of all the elements across given dimensions of the input tensor.
- Parameters
- x: <*,T> (Required)
Must be 1-dimensional or higher.
- axes: const<K,i32> (Optional, default=”None”, reduce on all axes.)
The dimensions to reduce.
- keep_dims: const<bool> (Optional, default=False)
If
False
, the rank is reduced by1
for each entry inaxes
, otherwise retain reduced axes with length1
.
- Returns
- <*,T>
Scalar or tensor: The reduced tensor.
- Attributes
- T: f32, int32
-
class
coremltools.converters.mil.mil.ops.defs.reduction.
reduce_log_sum_exp
(**kwargs)¶ Computes the natural logarithm of the sum of the exponentials of the elements across given dimensions of the input tensor. It is a smooth approximation of the maximum function, more numerically stable than
log(sum(exp(input)))
. It avoids overflows caused by taking theexp
of large inputs and underflows caused by taking thelog
of small inputs.- Parameters
- x: <*,T> (Required)
Must be 1-dimensional or higher.
- axes: const<K,i32> (Optional, default=”None”, reduce on all axes.)
The dimensions to reduce.
- keep_dims: const<bool> (Optional, default=False)
If
False
, the rank is reduced by1
for each entry inaxes
, otherwise retain reduced axes with length1
.
- Returns
- <*,T>
Scalar or tensor: The reduced tensor.
References
- Attributes
- T: f32, int32
-
class
coremltools.converters.mil.mil.ops.defs.reduction.
reduce_max
(**kwargs)¶ Computes the maximum of elements across given dimensions of the input tensor.
- Parameters
- x: <*,T> (Required)
Must be 1-dimensional or higher.
- axes: const<K,i32> (Optional, default=”None”, reduce on all axes.)
The dimensions to reduce.
- keep_dims: const<bool> (Optional, default=False)
If
False
, the rank is reduced by1
for each entry inaxes
, otherwise retain reduced axes with length1
.
- Returns
- <*,T>
Scalar or tensor: The reduced tensor.
- Attributes
- T: f32, int32
-
class
coremltools.converters.mil.mil.ops.defs.reduction.
reduce_mean
(**kwargs)¶ Computes the mean of elements across given dimensions of the input tensor.
- Parameters
- x: <*,T> (Required)
Must be 1-dimensional or higher.
- axes: const<K,i32> (Optional, default=”None”, reduce on all axes.)
The dimensions to reduce.
- keep_dims: const<bool> (Optional, default=False)
If
False
, the rank is reduced by1
for each entry inaxes
, otherwise retain reduced axes with length1
.
- Returns
- <*,T>
Scalar or tensor: The reduced tensor.
References
For an example, see tf.math.reduce_mean.
- Attributes
- T: f32, int32
-
class
coremltools.converters.mil.mil.ops.defs.reduction.
reduce_min
(**kwargs)¶ Computes the minimum of elements across given dimensions of the input tensor.
- Parameters
- x: <*,T> (Required)
Must be 1-dimensional or higher.
- axes: const<K,i32> (Optional, default=”None”, reduce on all axes.)
The dimensions to reduce.
- keep_dims: const<bool> (Optional, default=False)
If
False
, the rank is reduced by1
for each entry inaxes
, otherwise retain reduced axes with length1
.
- Returns
- <*,T>
Scalar or tensor: The reduced tensor.
- Attributes
- T: f32, int32
-
class
coremltools.converters.mil.mil.ops.defs.reduction.
reduce_prod
(**kwargs)¶ Computes the product of elements across given dimensions of the input tensor.
- Parameters
- x: <*,T> (Required)
Must be 1-dimensional or higher.
- axes: const<K,i32> (Optional, default=”None”, reduce on all axes.)
The dimensions to reduce.
- keep_dims: const<bool> (Optional, default=False)
If
False
, the rank is reduced by1
for each entry inaxes
, otherwise retain reduced axes with length1
.
- Returns
- <*,T>
Scalar or tensor: The reduced tensor.
- Attributes
- T: f32, int32
-
class
coremltools.converters.mil.mil.ops.defs.reduction.
reduce_sum
(**kwargs)¶ Computes the sum of elements across given dimensions of the input tensor.
- Parameters
- x: <*,T> (Required)
Must be 1-dimensional or higher.
- axes: const<K,i32> (Optional, default=”None”, reduce on all axes.)
The dimensions to reduce.
- keep_dims: const<bool> (Optional, default=False)
If
False
, the rank is reduced by1
for each entry inaxes
, otherwise retain reduced axes with length1
.
- Returns
- <*,T>
Scalar or tensor: The reduced tensor.
- Attributes
- T: f32, int32
-
class
coremltools.converters.mil.mil.ops.defs.reduction.
reduce_sum_square
(**kwargs)¶ Computes the sum of squares of elements across given dimensions of the input tensor.
- Parameters
- x: <*,T> (Required)
Must be 1-dimensional or higher.
- axes: const<K,i32> (Optional, default=”None”, reduce on all axes.)
The dimensions to reduce.
- keep_dims: const<bool> (Optional, default=False)
If
False
, the rank is reduced by1
for each entry inaxes
, otherwise retain reduced axes with length1
.
- Returns
- <*,T>
Scalar or tensor: The reduced tensor.
- Attributes
- T: f32, int32
scatter_gather¶
-
class
coremltools.converters.mil.mil.ops.defs.scatter_gather.
gather
(**kwargs)¶ Gather slices from input
x
along dimensionaxis
according toindices
, similar to tf.gather.If
indices
is scalar (0-D):
\[output[p_0, ..., p_{axis-1}, ~~~~~~~~~~~~~~~~~~~~~~~~ p_{axis+1}, ..., p_{rank(x)-1}] =\]\[x[p_0, ..., p_{axis-1}, ~~~~~~~~~ indices, ~~~~~~~~ p_{axis+1}, ..., p_{rank(x)-1}]\]Where
rank(x)
is the rank ofx
. Theoutput
has rankrank(x) - 1
.If
indices
is 1-D tensor:
\[output[p_0, ..., p_{axis-1}, ~~~~~~~~~~~~~ i, ~~~~~~~~~~~~~ p_{axis+1}, ..., p_{rank(*D)-1}] =\]\[x[p_0, ..., p_{axis-1}, ~~~~~~~~ indices[i], ~~~~~~~~ p_{axis+1}, ..., p_{rank(*D)-1}]\]The output has rank
rank(x)
.In general:
\[output[p_0, ..., p_{axis-1}, ~~~~~~~~ i_0, ..., i_{M-1}, ~~~~~~~~ p_{axis+1}, ..., p_{rank(x)-1}] =\]\[x[p_0, ..., p_{axis-1}, ~~~~~~~ indices[i_0, ..., i_{M-1}], ~~~~~~~ p_{axis+1}, ..., p_{rank(x)-1}]\]Where
M = rank(x)
.- Parameters
- x: tensor<*D,T> (Required)
- indices: tensor<*N,i32> (Required)
Indices values may be negative. More precisely,
-D[axis]<= v < D[axis]
forv
inindices
.
- axis: const i32 (Optional. Default=``0``)
Negative axis is supported.
- Returns
- tensor<*K,T>
Where
K = D[:axis] + N + D[axis+1:]
.
References
See tf.gather.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.scatter_gather.
scatter
(**kwargs)¶ Scatter
updates
todata
at locationsindices
at dimensionaxis
by operationmode
.Example:
mode == update
.For
i
in[0, len(indices)]
:
\[output[p_0, ..., p_{axis-1}, indice[i], p_{axis+1}, ..., p_D] =\]\[updates[p_0, ..., p_{axis-1}, i, p_{axis+1}, ..., p_D]\]For
j! = i
:
\[output[p_0, ..., p_{axis-1}, j, p_{axis+1}, ..., p_D] =\]\[data[p_0, ..., p_{axis-1}, j, p_{axis+1}, ..., p_D]\]Example:
mode == add
.For
i
in[0, len(indices)]
:
\[output[p_0, ..., p_{axis-1}, indice[i], p_{axis+1}, ..., p_D] =\]\[updates[p_0, ..., p_{axis-1}, i, p_{axis+1}, ..., p_D] +\]\[x[p_0, ..., p_{axis-1}, indice[i], p_{axis+1}, ..., p_D]\]For
j! = i
:
\[output[p_0, ..., p_{axis-1}, j, p_{axis+1}, ..., p_D] =\]\[data[p_0, ..., p_{axis-1}, j, p_{axis+1}, ..., p_D]\]- Parameters
- data: tensor<*D, T> (Required)
- indices: tensor<[C],T> (Required)
1-D tensor.
- updates: tensor<*K, T> (Required)
K = data.shape[:axis] + [len(indices)] + data.shape[axis+1:]
.
- axis: const i32 (Optional)
Default to
0
.
- mode: const string (Optional)
Can be the following modes:
update
,add
,sub
,mul
,div
,max
,min
.
- Returns
- tensor<*D, T>
With the same type and shape as input
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.scatter_gather.
gather_along_axis
(**kwargs)¶ Take the values along
axis
at locationsindices
.\[idx = indices[p_0, ..., p_{axis-1}, i, p_{axis+1}, ..., p_D]\]\[output[p_0, ..., p_{axis-1}, i, p_{axis+1}, ..., p_D] = = x[p_0, ..., p_{axis-1}, idx, p_{axis+1}, ..., p_D]\]- Parameters
- x: tensor<*D, T> (Required)
- indices: tensor<*K, T> (Required)
rank(indices) == rank(x)
.
- axis: const i32 (Optional):
Default to
0
.
- Returns
- tensor<*D, T>:
Output tensor has the same shape as
indices
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.scatter_gather.
scatter_along_axis
(**kwargs)¶ Scatter
updates
todata
at locationsindices
at dimensionaxis
by operationmode
.Example:
mode == update
.For
i
in[0, len(indices)]
:
\[idx = indices[p_0, ..., p_{axis-1}, i, p_{axis+1}, ..., p_D]\]\[output[p_0, ..., p_{axis-1}, idx, p_{axis+1}, ..., p_D] =\]\[updates[p_0, ..., p_{axis-1}, i, p_{axis+1}, ..., p_D]\]For
j! = i
:
\[output[p_0, ..., p_{axis-1}, j, p_{axis+1}, ..., p_D] =\]\[data[p_0, ..., p_{axis-1}, j, p_{axis+1}, ..., p_D]\]Example:
mode == add
.For
i
in[0, len(indices)]
:
\[idx = indices[p_0, ..., p_{axis-1}, i, p_{axis+1}, ..., p_D]\]\[output[p_0, ..., p_{axis-1}, idx, p_{axis+1}, ..., p_D] =\]\[updates[p_0, ..., p_{axis-1}, i, p_{axis+1}, ..., p_D] +\]\[x[p_0, ..., p_{axis-1}, indice[i], p_{axis+1}, ..., p_D]\]For
j! = i
:
\[output[p_0, ..., p_{axis-1}, j, p_{axis+1}, ..., p_D] =\]\[data[p_0, ..., p_{axis-1}, j, p_{axis+1}, ..., p_D]\]- Parameters
- data: tensor<*D, T> (Required)
- indices: tensor<*K,T> (Required)
rank(indices) == rank(data)
.
- updates: tensor<*K, T> (Required)
Must be the same shape as
indices
.
- axis: const i32 (Optional)
Default to
0
.
- mode: const string (Optional)
Default to
add
.Can be the following modes:
update
,add
,sub
,mul
,div
,max
,min
.
- Returns
- tensor<*D, T>
With the same type and shape as input
x
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.scatter_gather.
gather_nd
(**kwargs)¶ Gather slices from
x
according toindices
, similar to tf.gather_nd.The
indices
is a K-dim tensor, whereindices[i_0,...,i_{K-2}]
defines a slice ofx
:\[output[i_0, ..., i_{K-2}]= x[indices[i_0, ..., i_{K-2}]]\]Where
K = rank(indices)
andx[indices[i_0, ..., i_{K-2}]]
has rankrank(x) - indices.shape[-1]
.- Parameters
- x: tensor<*D,T> (Required)
- indices: tensor<*K,i32> (Required)
- Returns
- tensor<*V,T>
V = K[:-1] + D[K[-1]:]
, whereD = x.shape
andK = indices.shape
.
References
See tf.gather_nd.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.scatter_gather.
scatter_nd
(**kwargs)¶ Scatter
updates
todata
at locationsindices
.The
indices
is a K-dim tensor, whereindices[i_0,...,i_{K-2}]
defines a slice ofdata
,K = rank(indices)
, anddata[indices[i_0, ..., i_{K-2}]]
has rankrank(data) - indices.shape[-1]
.Example:
mode == update
: Theoutput
is set todata
initially, and the op updatesoutput
as follows:
\[output[indices[i_0, ..., i_{K-2}]]= updates[indices[i_0, ..., i_{K-2}]]\]Example:
mode == add
. The update rule is:
\[output[indices[i_0, ..., i_{K-2}]] += updates[indices[i_0, ..., i_{K-2}]]\]- Parameters
- data: tensor<*D,T> (Required)
- indices: tensor<*K,i32> (Required)
- updates: tensor<*K, T> (Required)
Must be the shape as
K[:-1]+data.shape[K[-1]:]
.
- mode: const string (Optional)
Default to
add
.Can be the following modes:
update
,add
,sub
,mul
,div
,max
,min
.
- Returns
- tensor<*D,T>
A tensor with the same shape and type as
data
.
- Attributes
- T: fp32
tensor_operation¶
-
class
coremltools.converters.mil.mil.ops.defs.tensor_operation.
band_part
(**kwargs)¶ Returns a tensor setting everything outside a center band to zeros for the innermost matrix. Special cases:
band_part(x, 0, -1)
returns upper triangular part.band_part(x, -1, 0)
returns lower triangular part.band_part(x, 0, 0)
returns diagonal.
- Parameters
- x: tensor<*?, T> (Required)
Input tensor.
- lower: const<i32> (Optional)
Number of lower / below sub-diagonals to keep. If negative, keep entire lower triangle.
Defaults to
-1
(keep the entire lower triangle).
- upper: const<i32> (Optional)
Number of upper / above sub-diagonals to keep. If negative, keep entire lower triangle.
Defaults to
-1
(keep the entire upper triangle).
- Returns
- tensor<*?, T>
Same type and shape as the input tensor.
-
class
coremltools.converters.mil.mil.ops.defs.tensor_operation.
cumsum
(**kwargs)¶ Returns the cumulative sum of the input along the given axis.
- Parameters
- x: tensor<*?, T> (Required)
Input tensor.
- axis: const<i32> (Optional)
default to
0
.Axis for which the cumulative sum is computed.
- exclusive: const<bool> (Optional)
Default to
False
.When set to
False
, inclusive cumsum is computed, that is the first element of the output is identical to the first element in the input.When set to
True
, exclusive cumsum is computed, which makes the first element of output to0
.
- reverse: const<bool> (Optional)
Default to
False
.When set to
True
, perform cumsum in the reverse order.
- Returns
- tensor<*?, T>
Same type and shape as the input tensor.
- Attributes
- T: fp32, int32
-
class
coremltools.converters.mil.mil.ops.defs.tensor_operation.
fill
(**kwargs)¶ Returns a tensor with a given shape filled with a constant value.
- Parameters
- shape: tensor<[K], i32> (Required)
Target output tensor shape.
K
is the rank of the output tensor.shape[k] > 0
fork = 0,..., K-1
.
- value: const<T> (Optional)
Default to
0.0
.Constant value to fill in.
- Returns
- tensor<*?, T>
Tensor with shape determined by the input shape.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.tensor_operation.
non_maximum_suppression
(**kwargs)¶ Applies non-maximum suppression (NMS) on the input box coordinates according to their intersection-over-union (IoU).
NMS selects a subset of bounding boxes in descending order of score, and removes boxes that have high intersection-over-union (IOU) overlap with previously-selected boxes.
- Parameters
- boxes: tensor<[n, B, 4], T> (Required)
Box coordinates on which to perform NMS.
- scores: tensor<[n, B, K], T> (Required)
Scores for each one of the boxes.
- iou_threshold: const<T> (Required)
The intersection over union (
IoU
) threshold over which boxes are suppressed. NMS remove all overlapping boxes withIoU > iou_threshold
.
- score_threshold: const<T> (Required)
Before IoU suppression is performed, boxes with class scores below this threshold are rejected.
- max_boxes: const<i32> (Required)
Maximum number of boxes to select. If the number of surviving boxes are less, output is padded up to this number.
- per_class_suppression: const<bool> (Optional)
Default to
False
.If
True
, suppression is performed independently within boxes of each class.
- Returns
- tensor<[n, max_boxes, 4], T>
Coordinates of selected boxes.
- tensor<[n, max_boxes, K], T>
Scores of selected boxes.
- tensor<[n, max_boxes], i32>
Indices of selected boxes.
- tensor<[n], i32>
Number of boxes selected for each batch.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.tensor_operation.
non_zero
(**kwargs)¶ Returns the indices of the elements in the given tensor that are non-zero.
- Parameters
- x: tensor<*?, T> (Required)
Tensor, values selected at indices where its values is not equal to
0
.
- Returns
- tensor<[N, R], int32>
2-dimensional tensor contains indices of elements that are non-zero. Each row is the index for a non-zero value.
N
is the number of non-zero elements,R
is the rank of the input.
- Attributes
- T: fp32, int32
-
class
coremltools.converters.mil.mil.ops.defs.tensor_operation.
one_hot
(**kwargs)¶ Returns one-hot vectors whose locations represented in
indices
take theon_value
, while other locations take theoff_value
.- Parameters
- indices: tensor<[D],T> (Required)
Tensor, values indicate the locations for each one-hot vector to take the
on_value
.
- one_got_vector_size: i32 (Required)
Indicates the number of returning vectors.
- axis: const i32 (Optional)
Indicates which dimension to append the new axis.
If the input indices is rank
D
, the output tensor will have rankD+1
.Default to
-1
(the last dimension).
- on_value: const i32 (Optional)
Values for locations where defined in
indices
.Default to
1
.
- off_value: const i32 (Optional)
Default to
0
.
- Returns
- tensor<*?,T>
A tensor that contains one-hot vectors.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.tensor_operation.
pad
(**kwargs)¶ Pad a tensor.
- Parameters
- x: tensor<[*D_in],T> (Required)
- pad: tensor<[2*N],i32> (Required)
N <= D_in
: LastN
dimensions ofx
are padded as follows: For each dimensioni
ofx
ifi >= D_in - N
:pad
pad[2*i]
elements beforex[..,i,..]
pad
pad[2*i+1]
elements afterx[..,i,..]
If mode is “reflect” then
pad[2*i]
andpad[2*i+1]
can be at
most
D[i]-1
. * If mode is “replicate” thenpad[2*i]
andpad[2*i+1]
can be at mostD[i]
.- mode: const<str> (Optional)
Default to
constant
.Must be one of the following values:
constant
,reflect
, orreplicate
.
- constant_val: const<T> (Optional)
Default to
0
.Constant value to pad. Ignored if
mode != constant
.
- Returns
- tensor<[*D_out],T>
Tensor with same type as the input.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.tensor_operation.
range_1d
(**kwargs)¶ Returns a numpy-like 1- range sequence.
- Parameters
- end: <T> (Required)
The upper limit of the sequence, exclusive.
- start: <T> (Required)
The start point of the sequence.
- step: <T> (Required)
Number that increments
start
.
- Returns
- tensor<M, T>
A 1-D tensor, where
M
is the length of the sequence.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.tensor_operation.
tile
(**kwargs)¶ Returns a new tensor by replicating input
x
multiples times. Dimensioni
ofx
will be replicatedreps[i]
times.- Parameters
- x: tensor<*?, T> (Required)
Input tensor.
- reps: tensor<[rank(x)], int32> (Required)
A 1-D tensor with length
rank(x)
, which indicates the number to replicate the input along each dimension.
- Returns
- tensor<*?, T>:
An n-D tensor with same type as the input.
- Attributes
- T: Any
-
class
coremltools.converters.mil.mil.ops.defs.tensor_operation.
argsort
(**kwargs)¶ Returns a tensor containing the indices of the sorted values along a given axis of the input tensor.
- Parameters
- x: <*?, T> (Required)
Input tensor.
- * axis: const<i32> (Optional)
Default to
-1
(the last dimension).Axis to perform the operation.
- * ascending: const<bool> (Optional)
Default to
False
, sort in descending order.True
to sort in ascending order.
- Returns
- tensor<*?, int32>
Tensor containing the indices of the sorted values
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.tensor_operation.
topk
(**kwargs)¶ Returns a tensor containing top or bottom
k
values and the corresponding indices of the input tensor along a given axis.- Parameters
- x: <*?, T> (Required)
Input tensor.
- k: const<i32> (Optional)
Default to
1
.Number of values/indices to be computed along each axis.
- * axis: const<i32> (Optional)
Defaults to
-1
(last dimension).Axis to perform the operation.
- * ascending: const<bool> (Optional)
Default to
False
, sort in descending order.True
to sort in ascending order.
- Returns
- tensor<*?, T>
Values of top/bottom
k
elements.
- tensor<*?, int32>
Indices of the top/bottom
k
elements along axis.
- Attributes
- T: fp32, int32
-
class
coremltools.converters.mil.mil.ops.defs.tensor_operation.
flatten2d
(**kwargs)¶ Flattens input tensor into 2d tensor by flattening dimensions before and after the provided axis.
- Parameters
- x: tensor<[*d], T> (Required)
Input tensor.
- * axis: const<f32> (Optional)
Defaults to
1
.Negative axis is supported.
- Returns
- tensor<d_prior, d_post, T>
d_prior
is product of dimensionsx[:axis]
d_post
is product of dimensionsx[axis:]
Examples
input_shape = (3, ), axis = -1, output_shape = (1, 3)
input_shape = (3, ), axis = 1, output_shape = (3, 1)
input_shape = (4, 3), axis = -1, output_shape = (4, 3)
input_shape = (2, 3, 2), axis = -1, output_shape = (6, 2)
input_shape = (5, 5, 2), axis = 1, output_shape = (5, 10)
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.tensor_operation.
shape
(**kwargs)¶ Returns a 1-dimensional tensor with the shape of the input tensor
- Parameters
- x: tensor<[*?], T> (Required)
Input tensor.
- Returns
- tensor<K, i32>
Shape of the input tensor.
K = x.rank
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.tensor_operation.
concat
(**kwargs)¶ Concatenates tensors along a dimension.
- Parameters
- values: Tuple[tensor<[d0, d1, …, d_axis_i, …, d_n],T>] (Required)
The number of dimensions of the input tensors must match, and all dimensions except
axis
must be equal.The tensors may be variadic, but the number of tensors must be determined at compile time (i.e. a tuple).
- axis: const<int32> (Required)
The dimension along which to concatenate. Must be in the range
[-rank(values[i]), rank(values[i]))
for alli
.
- interleave: const<bool> (Optional, Default=False)
If true, concatenate the inputs by interleaving them.
If true, all the inputs to this op must have the exact same shape.
- Returns
- tensor<[d0, d1,…d_axis_out, …, d_n],T>
Where
d_axis_out = sum(d_axis_i)
.
Examples
in1 : shape (3, 2), value = [[1, 2], [3, 4], [5, 6]] in2 : shape (3, 2), value = [[7, 8], [9, 10], [11, 12]] axis = 0 if interleave = False (default) output : shape (6, 2) output[0:3, :] = in1 output[3:6, :] = in2 value = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12]] if interleave = True output : shape (6, 2) output[0::2, :] = in1 output[1::2, :] = in2 value = [[1, 2], [7, 8], [3, 4], [9, 10], [5, 6], [11, 12]]
- Attributes
- T: fp32, int32
-
class
coremltools.converters.mil.mil.ops.defs.tensor_operation.
split
(**kwargs)¶ Split tensors into a tuple
- Parameters
- x: <*?,T> (Required)
The tensor to split.
The tensors may be variadic, but the number of tensors must be determined at compile time (i.e. a tuple).
- num_splits: <i32> (Optional)
If specified, divide
x
intonum_splits
tensors alongaxis
. Its behavior depends onsplit_sizes
:If
split_sizes
is defined,num_splits == S
, and the output sizes may be uneven.If
split_sizes
is not defined,value.shape[axis]
must be divisible bynum_splits
, and the output sizes must be even.
At least one of
num_splits
orsplit_sizes
must be provided. Ifsplit_sizes
lengthS
cannot be determined at compile time,num_splits
must be supplied to determine the number of outputs.- split_sizes: const<S,i32> (Optional)
Sizes to split to. The sum of
split_sizes
must equal tovalue.shape[axis]
.
- axis: const<i32> (Required)
The dimension along which to concatenate. Must be in the range
[-rank(x), rank(x))
.
- Returns
- Tuple[tensor<*?,T>]
Where the length of the tuple is the number of splits (determined from
num_splits
orsplit_sizes
).
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.tensor_operation.
stack
(**kwargs)¶ Concatenates tensors along a dimension.
- Parameters
- values: Tuple[tensor<[d0, d1,…d_axis_i, …, d_n],T>] (Required)
All tensors must have identical shape.
- axis: const<i32> (Required)
The dimension along which to concatenate. Must be in the range
[-rank(values[i]), rank(values[i]))
for alli
.
- Returns
- tenor<[d0, d1,…d_axis_out, …, d_n],T>
Where
d_axis_out = sum(d_axis_i)
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.tensor_operation.
identity
(**kwargs)¶ Returns a tensor with the same shape and contents as input.
- Parameters
- x: tensor<*?, T> (Required)
Input tensor.
- Returns
- tensor<*?, T>
Same type and shape as the input tensor.
tensor_transformation¶
-
class
coremltools.converters.mil.mil.ops.defs.tensor_transformation.
depth_to_space
(**kwargs)¶ Rearrange elements in a tensor from depth (channel) into spatial dimensions.
- Parameters
- x: tensor<[n, C, H, W], T> (Required)
Input tensor of rank
4
.
- block_size: const i32 (Required)
The size of the spatial block. Must be greater than
1
and divisible by channel dimensionC
.
- Returns
- tensor<[n, C / block_size^2, H x block_size, W x block_size], T>
Where
b
is the block size.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.tensor_transformation.
expand_dims
(**kwargs)¶ Insert a single-dimension in a 1-D or higher tensor at each axis in axes.
- Parameters
- x: tensor<*?, T> (Required)
Scalar or tensor.
- axes: const tensor<[K], i32> Required
K
is the number of dimensions expanded.Insert single dimension at dimension index at each axes.
Negative value to index from the end.
-d-1 <= axis <= d
whered
is the rank ofx
.
- Returns
- tensor<*(rank(x)+K), T>
Same type as the input
x
with rankrank(x)+K
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.tensor_transformation.
reshape
(**kwargs)¶ Return a tensor that has the same values as
x
with shapeshape
.shape
must have the same volume (number of elements) asx
.- Parameters
- x: tensor<*?, T> (Required)
A n-D tensor or a scalar.
If
x
is fixed rank (and possibly contains symbolic dimension), shape may contain elements that are not positive integers (see below).If
x
is variadic rank, shape can only contain positive integers.
- shape: tensor<[K], i32> (Required)
A 1-D tensor, with elements from the following:
Positive integers.
Symbols: All but one symbol in shape must be present in
x.shape
. The new symbol that is not present inx.shape
represent a dimension such that the total size remains constant. Symbol is illegal ifx
is variadic rank.-1
:-1
introduces a new symbol (see Symbols). Therefore,-1
is allowed if all symbols in the shape appear inx.shape
.-1
is illegal ifx
is variadic rank.0
: IfK == rank(x)
then0
means inheriting from the corresponding dimension inx.shape
.0
is illegal ifx
is variadic rank.
- Returns
- tensor<*?, T>
Tensor with shape determined by the input shape.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.tensor_transformation.
reverse
(**kwargs)¶ Reverse the order of the input tensor
x
along specified ``axes``(dimensions).- Parameters
- x: tensor<*?, T> (Required)
Input tensor.
- axes: const<D, i32> (Optional)
Dimension(s) to reverse. Each axis must be in the range
[-rank(x), rank(x))
.Defaults to None (reverse on all dimensions).
- Returns
- tensor<*?, T>
Same type and shape as the input tensor.
References
See tf.reverse and TORCH.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.tensor_transformation.
reverse_sequence
(**kwargs)¶ Reverse variable length slices for specified axes / dimensions of the input tensor. This op first slices input tensor along the
batch_axis
dimension, then partially reverses the elements along theseq_axis
for the firstlengths[i]
elements.- Parameters
- x: tensor<*?, T> (Required)
Input tensor.
- lengths: tensor<L, i32> (Required)
1-dimensional tensor of length
x.shape[batch_axis]
specifying the length of the sequence to reverse.Values must be in range
[0, x.shape[seq_axis]]
.
- seq_axis: const<i32> (Optional)
The dimension to reverse.
Defaults to
0
.
- batch_axis: const<i32> (Optional)
Dimension for slicing.
Defaults to
0
.
- Returns
- tensor<*?, T>
Same type and shape as the input tensor.
References
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.tensor_transformation.
slice_by_index
(**kwargs)¶ Method for numpy style indexing and slicing. Suppose we have a tensor
x
, this method achieves:result = x[begin[0]: end[0]: stride[0], begin[1]: end[1]: stride[1], ...]
Note this method does not support pure indexing. You would need to do squeeze if indexing is intended.- Parameters
- x: tensor<*?, T> (Required)
Input tensor
- begin: tensor<[rank<x>], i32> (Required)
Starting index for the dimension of slicing.
- end: tensor<[rank(x)], i32> (Required)
Ending index for the dimension of slicing.
- stride: tensor<[rank(x)], i32> (Optional)
Default as all ``1``s.
Stride for the dimension of slicing.
- begin_mask: tensor<[rank(x)], bool> (Optional)
Default to all
False
.If
begin_mask[i]==True
, neglectbegin[i]
, and setbegin[i]
to0
.
- end_mask: tensor<[rank(x)], bool> (Optional)
Default to all
False
.If
end_mask[i]==True
, neglectend[i]
, and setend[i]
tox.shape[i]
.
- squeeze_mask: tensor<[rank(x)], bool> (Optional)
Default to all
False
.If
squeeze_mask[i]==true
, neglectend[i]
, and do the pure index atbegin[i]
.
- Returns
- tensor<*?, T>
Scalar or tensor.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.tensor_transformation.
slice_by_size
(**kwargs)¶ Perform numpy-style indexing and slicing. For example, if you have a tensor
x
, this method produces:result = x[begin[0]: end[0]: stride[0], begin[1]: end[1]: stride[1], ...]
Note: This method does not support pure indexing. You would need to do a squeeze if indexing is intended.
- Parameters
- x: tensor<*?, T> (Required)
Input tensor.
- begin: tensor<[rank<x>], i32> (Required)
Starting index for the dimension of slicing.
- end: tensor<[rank(x)], i32> (Required)
Ending index for the dimension of slicing.
- stride: tensor<[rank(x)], i32> (Optional)
Default to all ones (
1
).Stride for the dimension of slicing.
- begin_mask: tensor<[rank(x)], bool> (Optional)
Default to all
False
.If
begin_mask[i]==True
, neglectbegin[i]
, and setbegin[i]
to0
.
- end_mask: tensor<[rank(x)], bool> (Optional)
Default to all
False
.If
end_mask[i]==True
, neglectend[i]
, and setend[i]
tox.shape[i]
.
- squeeze_mask: tensor<[rank(x)], bool> (Optional)
Default to all
False
.If
squeeze_mask[i]==true
, neglectend[i]
, and do the pure index atbegin[i]
.
- Returns
- tensor<*?, T>
Scalar or tensor.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.tensor_transformation.
space_to_depth
(**kwargs)¶ Rearrange elements in a tensor from spatial into depth (channel) dimension.
- Parameters
- x: tensor<[n, C, H, W], T> (Required)
Input tensor of rank
4
.
- block_size: const<i32> (Required)
The size of the spatial block. Must be greater than
1
and divisible by spatial dimensionsH, W
.
- Returns
- tensor<[n, C x block_size^2, H / block_size, W / block_size], T>
Where
b
is the block size.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.tensor_transformation.
squeeze
(**kwargs)¶ Remove single-dimension dimensions in a 1-D or higher tensor.
- Parameters
- x: tensor<*?,T> (Required)
Must be at least 1-D.
- axes: const<K,i32> (Optional)
Axes to squeeze out.
Default to remove all single-dimensions.
- Returns
- tensor<*(rank(x)-K),T>
Tensor with same type as input
x
and rankrank(x)-K
.
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.tensor_transformation.
transpose
(**kwargs)¶ Permute tensor
x
dimensions according toperm
.- Parameters
- x: tensor<*?, T> (Required)
Must be at least 1-D.
x
may have a symbolic shape.
- perm: const<[rank(x)], i32> (Required)
Permutation order. Must be non-negative integers.
- Returns
- tensor<*?,T>
Tensor with same rank and type as
x
.
References
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.tensor_transformation.
pixel_shuffle
(**kwargs)¶ Rearrange elements in a tensor from depth (channel) into spatial dimensions. Equivalent to PyTorch’s
PixelShuffle
.- Parameters
- x: tensor<[n, C x f^2, H, W], T> (Required)
Input tensor of rank
4
.
- upscale_factor: const<i32>
Factor to increase spatial resolution by.
- Returns
- tensor<[n, C, H x f, W x f], T>
Where
f
is the upscale factor.
References
- Attributes
- T: fp32
-
class
coremltools.converters.mil.mil.ops.defs.tensor_transformation.
sliding_windows
(**kwargs)¶ Return a tensor containing all windows of
size
, separated by stride along the givenaxis
.- Parameters
- x: tensor<[*d0, d_axis, *dn], T>
Input tensor.
- axis: const<i32>
Axis to perform the operation.
- size: const<i32>
Number of elements in the sliding window.
- stride: const<i32> Optional
Default to
1
.The stride of the input elements in the sliding window.
- Returns
- tensor<[*d0, d_axis - size // stride + 1, size, *dn], T>
The output will be a tensor of rank
N+1
whereN
is the input tensor rank.
- Attributes
- T: fp32