8000 Breaking change of TFLite model definition in TensorFlow 2.4.0: OperatorCode.BuiltinCode · Issue #46663 · tensorflow/tensorflow · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Breaking change of TFLite model definition in TensorFlow 2.4.0: OperatorCode.BuiltinCode #46663
Closed
@zhenhuaw-me

Description

@zhenhuaw-me

(source issue: zhenhuaw-me/tflite#9)

This change breaks software stacks that depend on the built TFLite model parser, e.g. tvm, tflite2onnx, and etc.

Starting from TensorFlow 2.4.0, the BuiltinOperator switches to int32 from byte. As a result, the OperatorCode.builtin_code is now an int32 too, and code like op_code.BuiltinCode() is broken.

// An OperatorCode can be an enum value (BuiltinOperator) if the operator is a
// builtin, or a string if the operator is custom.
table OperatorCode {
  // This field is for backward compatibility. This field will be used when
  // the value of the extended builtin_code field has less than
  // BulitinOperator_PLACEHOLDER_FOR_GREATER_OP_CODES.
  deprecated_builtin_code:byte;
  custom_code:string;

  // The version of the operator. The version need to be bumped whenever new
  // parameters are introduced into an op.
  version:int = 1;

  // This field is introduced for resolving op builtin code shortage problem
  // (the original BuiltinOperator enum field was represented as a byte).
  // This field will be used when the value of the extended builtin_code field
  // has greater than BulitinOperator_PLACEHOLDER_FOR_GREATER_OP_CODES.
  builtin_code:BuiltinOperator;
}

For any code that uses op_code.BuiltinCode(), a workaround like the below (or this PR) is needed.

if op_code.BuiltinCode() < BuiltinOperator.PLACEHOLDER_FOR_GREATER_OP_CODES:
    opc = op_code.DeprecatedBuiltinCode()
else:
    opc = op_code.BuiltinCode()

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0