dotnet/machinelearning · error · NotSupportedException

TensorFlow type not supported.

Error message

TensorFlow type not supported.

What it means

Tf2MlNetType maps a TF_DataType to an ML.NET PrimitiveDataViewType. If Tf2MlNetTypeOrNull returns null (the TF type has no ML.NET equivalent), it throws NotSupportedException("TensorFlow type not supported.").

Solutions

  1. Re-export the model with only supported dtypes (float32, double, int32, int64, string, bool) on inputs/outputs.
  2. Wrap the unsupported tensor with TF cast ops to a supported type before the model's output.
  3. Check Tf2MlNetTypeOrNull over all model signatures before training/loading to detect unsupported dtypes early.
  4. Catch NotSupportedException and fall back to a different model or featurization path.

Example fix

// before
var type = Tf2MlNetType(TF_DataType.TF_QINT8); // throws
// after
var type = Tf2MlNetTypeOrNull(dtype) ?? Tf2MlNetType(TF_DataType.TF_FLOAT); // after casting model outputs to float
Defensive patterns

Strategy: validation

Validate before calling

foreach (var dtype in modelInputAndOutputDtypes)
    if (Tf2MlNetTypeOrNull(dtype) == null)
        throw new InvalidOperationException($"Model uses unsupported TF dtype {dtype}");

Try / catch

try { type = Tf2MlNetType(dtype); }
catch (NotSupportedException) { useFallbackModelOrCastToFloat(); }

Prevention

When it happens

Trigger: Loading a TensorFlow model (TensorFlowTransformer/TensorFlowEstimator) whose input or output tensors use a dtype without an ML.NET mapping — e.g. TF_COMPLEX64, TF_UINT32, TF_QINT8, TF_RESOURCE, or other exotic quantized/resource types.

Common situations: Using SavedModels that export quantized (QINT/QUINT), complex, string-resource, or variant outputs; TF 2.x models exposing control-flow/resource tensors; models saved with unusual dtypes for embeddings or hashes.

Related errors


AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11). Data as JSON: /api/errors/dad63f2e9c0df9ad. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.ML.TensorFlow/TensorflowUtils.cs:153

        /// <summary>
        /// Load TensorFlow model into memory.
        /// </summary>
        /// <param name="env">The environment to use.</param>
        /// <param name="modelPath">The model to load.</param>
        /// <param name="treatOutputAsBatched">If the first dimension of the output is unknown, should it be treated as batched or not.</param>
        /// <returns></returns>
        internal static TensorFlowModel LoadTensorFlowModel(IHostEnvironment env, string modelPath, bool treatOutputAsBatched = true)
        {
            var session = GetSession(env, modelPath);
            return new TensorFlowModel(env, session, modelPath, treatOutputAsBatched: treatOutputAsBatched);
        }

        internal static PrimitiveDataViewType Tf2MlNetType(TF_DataType type)
        {
            var mlNetType = Tf2MlNetTypeOrNull(type);
            if (mlNetType == null)
                throw new NotSupportedException("TensorFlow type not supported.");
            return mlNetType;
        }

        internal static PrimitiveDataViewType Tf2MlNetTypeOrNull(TF_DataType type)
        {
            switch (type)
            {
                case TF_DataType.TF_FLOAT:
                    return NumberDataViewType.Single;
                case TF_DataType.DtFloatRef:
                    return NumberDataViewType.Single;
                case TF_DataType.TF_DOUBLE:
                    return NumberDataViewType.Double;
                case TF_DataType.TF_UINT8:
                    return NumberDataViewType.Byte;
                case TF_DataType.TF_UINT16:
                    return NumberDataViewType.UInt16;
                case TF_DataType.TF_UINT32:

View on GitHub (pinned to 7b76e69cf9)