{"record":{"id":"6fbb02b016b1efa7","repo":"tensorflow/models","slug":"cannot-finalize-with-finalize-method-i","errorCode":null,"errorMessage":"Cannot finalize with {finalize_method[i]}.","messagePattern":"Cannot finalize with (.+?)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/projects/edgetpu/vision/serving/export_util.py","lineNumber":139,"sourceCode":"    return output_layer\n  discrete = False\n  for i in range(len(finalize_method)):\n    if finalize_method[i] == 'argmax':\n      discrete = True\n      is_argmax_last = (i + 1) == len(finalize_method)\n      if is_argmax_last:\n        output_layer = tf.argmax(\n            output_layer, axis=3, output_type=tf.dtypes.int32)\n      else:\n        # TODO(tohaspiridonov): add first_match=False when cl/383951533 submited\n        output_layer = custom_layers.argmax(\n            output_layer, keepdims=True, epsilon=1e-3)\n    elif finalize_method[i] == 'squeeze':\n      output_layer = tf.squeeze(output_layer, axis=3)\n    else:\n      resize_params = finalize_method[i].split('resize')\n      if len(resize_params) != 2 or resize_params[0]:\n        raise ValueError('Cannot finalize with ' + finalize_method[i] + '.')\n      resize_to_size = int(resize_params[1])\n      if discrete:\n        output_layer = tf.image.resize(\n            output_layer, [resize_to_size, resize_to_size],\n            method=tf.image.ResizeMethod.NEAREST_NEIGHBOR)\n      else:\n        output_layer = tf.image.resize(\n            output_layer, [resize_to_size, resize_to_size],\n            method=tf.image.ResizeMethod.BILINEAR)\n  return output_layer\n\n\ndef preprocess_for_quantization(image_data, image_size, crop_padding=32):\n  \"\"\"Crops to center of image with padding then scales, normalizes image_size.\n\n  Args:\n    image_data: A 3D Tensor representing the RGB image data. Image can be of\n      arbitrary height and width.","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/projects/edgetpu/vision/serving/export_util.py#L121-L157","documentation":"Error \"Cannot finalize with {finalize_method[i]}.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/projects/edgetpu/vision/serving/export_util.py:139 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e006f5f0d534913e49c1f1dae87364039fa607e2","analyzedAt":"2026-08-24T14:09:15.576Z","schemaVersion":2},"datasetVersion":"2026-08-24T17:17:21.512Z"}