yobx.tensorflow.ops.shape_ops#
Converters for TF shape-manipulation ops:
Reshape, Squeeze, Shape, StridedSlice, Pack,
ExpandDims, Transpose, Cast.
Reshape / squeeze#
Reshape, Squeeze
Type casting#
Cast
Shape / indexing#
Shape, StridedSlice
Stack / pack#
Pack
Dimension insertion / permutation#
ExpandDims, Transpose
- yobx.tensorflow.ops.shape_ops.convert_cast(g: GraphBuilderExtendedProtocol, sts: Dict[str, Any], outputs: List[str], op: Operation) str[source]#
Converts TF
Cast→ ONNXCast.The target dtype is read from the TF op’s
DstTattribute and mapped to the corresponding ONNXTensorProtointeger type.
- yobx.tensorflow.ops.shape_ops.convert_expand_dims(g: GraphBuilderExtendedProtocol, sts: Dict[str, Any], outputs: List[str], op: Operation) str[source]#
Converts TF
ExpandDims(tf.expand_dims) → ONNXUnsqueeze.The
diminput (second input) must be a scalar constant; its value is read and forwarded as theaxesargument ofUnsqueeze.
- yobx.tensorflow.ops.shape_ops.convert_pack(g: GraphBuilderExtendedProtocol, sts: Dict[str, Any], outputs: List[str], op: Operation) str[source]#
Converts TF
Pack(tf.stack) → ONNXUnsqueeze+Concat.Packstacks N tensors along a new axis. In ONNX this is expressed as unsqueezing each input along the new axis and then concatenating them.Each input is cast to
int64so that the resulting tensor can be used as an ONNXReshapeshape argument (which requiresint64).
- yobx.tensorflow.ops.shape_ops.convert_reshape(g: GraphBuilderExtendedProtocol, sts: Dict[str, Any], outputs: List[str], op: Operation) str[source]#
Converts TF
Reshape→ ONNXReshape.The TF
shapeinput (second input) may be int32; it is cast to int64 as required by the ONNXReshapespecification.When ONNX shape inference cannot determine the output shape (e.g. because the shape tensor contains a dynamic batch dimension), the TF-inferred output shape is used as a fallback so that downstream shape-inference assertions are satisfied.
- yobx.tensorflow.ops.shape_ops.convert_shape(g: GraphBuilderExtendedProtocol, sts: Dict[str, Any], outputs: List[str], op: Operation) str[source]#
Converts TF
Shape→ ONNXShape.TF’s
Shapeop may outputint32(via theout_typeattribute), but the ONNXShapeoperator always returnsint64. The output is kept asint64throughout the ONNX graph; downstream converters (e.g.StridedSlice,Pack) cast their non-int64 constant inputs to match.
- yobx.tensorflow.ops.shape_ops.convert_squeeze(g: GraphBuilderExtendedProtocol, sts: Dict[str, Any], outputs: List[str], op: Operation) str[source]#
Converts TF
Squeeze→ ONNXSqueeze.When
squeeze_dimsis empty all size-1 dimensions are removed (matching TF’s default behaviour). When specific axes are given they are passed as an int64 tensor input to the ONNX node (opset ≥ 13 API).
- yobx.tensorflow.ops.shape_ops.convert_strided_slice(g: GraphBuilderExtendedProtocol, sts: Dict[str, Any], outputs: List[str], op: Operation) str[source]#
Converts TF
StridedSlice→ ONNXGatherorSlice(+ optionalSqueeze).Only the common cases are supported:
No
begin_mask,end_mask,ellipsis_mask, ornew_axis_maskbits set.shrink_axis_maskis supported by usingGatherwith a scalar index for the typical single-element-extraction pattern (e.g. as emitted bytf.keras.layers.Flatten).
This covers the pattern generated by
tf.keras.layers.Flattenand similar common usages ofStridedSliceon shape tensors.
- yobx.tensorflow.ops.shape_ops.convert_transpose(g: GraphBuilderExtendedProtocol, sts: Dict[str, Any], outputs: List[str], op: Operation) str[source]#
Converts TF
Transpose→ ONNXTranspose.The permutation is given as a second input tensor (a 1-D int32/int64 constant); its value is read and forwarded as the
permattribute.