{
  "id": 399162,
  "title": "tf.keras.layers.Conv2D and linear algebra compatibility confusion",
  "url": "/competitions/asl-signs/discussion/399162",
  "author_name": "",
  "post_date": "2023-04-02T19:43:31.846937500Z",
  "votes": null,
  "comment_count": 5,
  "views": 0,
  "content": "<p>Hi Everyone,</p>\n<p>I'm having a bit of trouble with the following error when I try to convert my model.</p>\n<p>\"Some ops are not supported by the native TFLite runtime, you can enable TF kernels fallback using TF Select. See instructions: <a href=\"https://www.tensorflow.org/lite/guide/ops_select\" target=\"_blank\">https://www.tensorflow.org/lite/guide/ops_select</a> <br>\nTF Select ops: Conv2D, MatrixDiagPartV3\"</p>\n<p>The Conv2D is from a convolutional layer I'm using and I'm assuming the \"MatrixDiagPartV3\" is from the following line of code in my notebook: tf.linalg.diag_part(G)</p>\n<p>When I use the following code, which I got from the link provided after \"See instructions:\", the model converts just fine.</p>\n<p>keras_model_converter.target_spec.supported_ops = [<br>\n  tf.lite.OpsSet.TFLITE_BUILTINS, # enable TensorFlow Lite ops.<br>\n  tf.lite.OpsSet.SELECT_TF_OPS # enable TensorFlow ops.<br>\n]</p>\n<p>However, as noted in the linked notebook (<a href=\"https://www.kaggle.com/competitions/asl-signs/discussion/398531)\" target=\"_blank\">https://www.kaggle.com/competitions/asl-signs/discussion/398531)</a>, these ops don't seem to be supported for this competition…Does anyone have any advice on how to use tf.keras.layers.Conv2D() or tf.linalg.diag_part() in this competition without having to write a convolutional block and a matrix diagonalizer from scratch?</p>",
  "messages": [
    {
      "id": "2206734",
      "postDate": "04/02/2023 19:43:31",
      "content": "<p>Hi Everyone,</p>\n<p>I'm having a bit of trouble with the following error when I try to convert my model.</p>\n<p>\"Some ops are not supported by the native TFLite runtime, you can enable TF kernels fallback using TF Select. See instructions: <a href=\"https://www.tensorflow.org/lite/guide/ops_select\" target=\"_blank\">https://www.tensorflow.org/lite/guide/ops_select</a> <br>\nTF Select ops: Conv2D, MatrixDiagPartV3\"</p>\n<p>The Conv2D is from a convolutional layer I'm using and I'm assuming the \"MatrixDiagPartV3\" is from the following line of code in my notebook: tf.linalg.diag_part(G)</p>\n<p>When I use the following code, which I got from the link provided after \"See instructions:\", the model converts just fine.</p>\n<p>keras_model_converter.target_spec.supported_ops = [<br>\n  tf.lite.OpsSet.TFLITE_BUILTINS, # enable TensorFlow Lite ops.<br>\n  tf.lite.OpsSet.SELECT_TF_OPS # enable TensorFlow ops.<br>\n]</p>\n<p>However, as noted in the linked notebook (<a href=\"https://www.kaggle.com/competitions/asl-signs/discussion/398531)\" target=\"_blank\">https://www.kaggle.com/competitions/asl-signs/discussion/398531)</a>, these ops don't seem to be supported for this competition…Does anyone have any advice on how to use tf.keras.layers.Conv2D() or tf.linalg.diag_part() in this competition without having to write a convolutional block and a matrix diagonalizer from scratch?</p>",
      "rawMarkdown": "Hi Everyone,\n\nI'm having a bit of trouble with the following error when I try to convert my model.\n\n\"Some ops are not supported by the native TFLite runtime, you can enable TF kernels fallback using TF Select. See instructions: https://www.tensorflow.org/lite/guide/ops_select \nTF Select ops: Conv2D, MatrixDiagPartV3\"\n\nThe Conv2D is from a convolutional layer I'm using and I'm assuming the \"MatrixDiagPartV3\" is from the following line of code in my notebook: tf.linalg.diag_part(G)\n\nWhen I use the following code, which I got from the link provided after \"See instructions:\", the model converts just fine.\n\nkeras_model_converter.target_spec.supported_ops = [\n  tf.lite.OpsSet.TFLITE_BUILTINS, # enable TensorFlow Lite ops.\n  tf.lite.OpsSet.SELECT_TF_OPS # enable TensorFlow ops.\n]\n\nHowever, as noted in the linked notebook (https://www.kaggle.com/competitions/asl-signs/discussion/398531), these ops don't seem to be supported for this competition...Does anyone have any advice on how to use tf.keras.layers.Conv2D() or tf.linalg.diag_part() in this competition without having to write a convolutional block and a matrix diagonalizer from scratch?",
      "votes": null
    },
    {
      "id": "2206879",
      "postDate": "04/03/2023 01:07:17",
      "content": "<p><a href=\"https://www.tensorflow.org/model_optimization/guide/pruning/pruning_for_on_device_inference\" target=\"_blank\">https://www.tensorflow.org/model_optimization/guide/pruning/pruning_for_on_device_inference</a></p>\n<p>I found this example where tf.keras.layers.Conv2D is acceptable without needing extra OPs, but I can't seem to make it work and when I paste it in my notebook and try to just convert exactly their model, it throws the same error as above…I'm very new to tflite, so this is rather confusing.</p>",
      "rawMarkdown": "https://www.tensorflow.org/model_optimization/guide/pruning/pruning_for_on_device_inference\n\nI found this example where tf.keras.layers.Conv2D is acceptable without needing extra OPs, but I can't seem to make it work and when I paste it in my notebook and try to just convert exactly their model, it throws the same error as above...I'm very new to tflite, so this is rather confusing.",
      "votes": null
    },
    {
      "id": "2207123",
      "postDate": "04/03/2023 06:05:28",
      "content": "<p><a href=\"https://stackoverflow.com/questions/33700049/get-the-diagonal-of-a-matrix-in-tensorflow\" target=\"_blank\">https://stackoverflow.com/questions/33700049/get-the-diagonal-of-a-matrix-in-tensorflow</a></p>\n<pre><code>x_flat = tf.reshape(x, [-1])  # flatten the matrix\nx_diag = tf.gather(x, [0, 3, 6]) # hard code the digonal index\n</code></pre>",
      "rawMarkdown": "https://stackoverflow.com/questions/33700049/get-the-diagonal-of-a-matrix-in-tensorflow\n```\nx_flat = tf.reshape(x, [-1])  # flatten the matrix\nx_diag = tf.gather(x, [0, 3, 6]) # hard code the digonal index\n```",
      "votes": null
    },
    {
      "id": "2207343",
      "postDate": "04/03/2023 10:52:22",
      "content": "<p>Indeed, Conv2D op is supported by tflite, but there may be some limitations. Recently, I've faced the same issue, that Conv2D op was not supported. I've spent a lot of time debugging it and finally I discovered, that key problem was not in Conv2D itself, but in some operation before Conv2D. I've preprocessed data in such a way that I lose the shape of the input feature. This caused a failure of tflite.</p>\n<p>I am not sure whether this is your case, but I am pretty sure that Conv2D is working well, except for some minor things (like unknown shape, unsupported input data type, etc.). I would recommend you to try to convert a raw model without preprocessing step and check out whether it causes crash. </p>",
      "rawMarkdown": "Indeed, Conv2D op is supported by tflite, but there may be some limitations. Recently, I've faced the same issue, that Conv2D op was not supported. I've spent a lot of time debugging it and finally I discovered, that key problem was not in Conv2D itself, but in some operation before Conv2D. I've preprocessed data in such a way that I lose the shape of the input feature. This caused a failure of tflite.\n\nI am not sure whether this is your case, but I am pretty sure that Conv2D is working well, except for some minor things (like unknown shape, unsupported input data type, etc.). I would recommend you to try to convert a raw model without preprocessing step and check out whether it causes crash.",
      "votes": null
    },
    {
      "id": "2207475",
      "postDate": "04/03/2023 12:56:23",
      "content": "<p>Thanks <a href=\"https://www.kaggle.com/Mykola\" target=\"_blank\">@Mykola</a>! This might be my problem as well. I'll try debugging this!</p>",
      "rawMarkdown": "Thanks @Mykola! This might be my problem as well. I'll try debugging this!",
      "votes": null
    },
    {
      "id": "2207667",
      "postDate": "04/03/2023 15:09:42",
      "content": "<p>Good luck for you. Would love to hear that was a problem, once you found it</p>",
      "rawMarkdown": "Good luck for you. Would love to hear that was a problem, once you found it",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 2206879,
      "author_name": "chemdatafarmer",
      "author_url": "",
      "post_date": "04/03/2023 01:07:17",
      "content": "<p><a href=\"https://www.tensorflow.org/model_optimization/guide/pruning/pruning_for_on_device_inference\" target=\"_blank\">https://www.tensorflow.org/model_optimization/guide/pruning/pruning_for_on_device_inference</a></p>\n<p>I found this example where tf.keras.layers.Conv2D is acceptable without needing extra OPs, but I can't seem to make it work and when I paste it in my notebook and try to just convert exactly their model, it throws the same error as above…I'm very new to tflite, so this is rather confusing.</p>",
      "votes": null,
      "replies": [
        {
          "id": 2207343,
          "author_name": "meowmeowmeowmeowmeow",
          "author_url": "",
          "post_date": "04/03/2023 10:52:22",
          "content": "<p>Indeed, Conv2D op is supported by tflite, but there may be some limitations. Recently, I've faced the same issue, that Conv2D op was not supported. I've spent a lot of time debugging it and finally I discovered, that key problem was not in Conv2D itself, but in some operation before Conv2D. I've preprocessed data in such a way that I lose the shape of the input feature. This caused a failure of tflite.</p>\n<p>I am not sure whether this is your case, but I am pretty sure that Conv2D is working well, except for some minor things (like unknown shape, unsupported input data type, etc.). I would recommend you to try to convert a raw model without preprocessing step and check out whether it causes crash. </p>",
          "votes": null,
          "replies": [
            {
              "id": 2207475,
              "author_name": "chemdatafarmer",
              "author_url": "",
              "post_date": "04/03/2023 12:56:23",
              "content": "<p>Thanks <a href=\"https://www.kaggle.com/Mykola\" target=\"_blank\">@Mykola</a>! This might be my problem as well. I'll try debugging this!</p>",
              "votes": null,
              "replies": [
                {
                  "id": 2207667,
                  "author_name": "meowmeowmeowmeowmeow",
                  "author_url": "",
                  "post_date": "04/03/2023 15:09:42",
                  "content": "<p>Good luck for you. Would love to hear that was a problem, once you found it</p>",
                  "votes": null,
                  "replies": []
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "id": 2207123,
      "author_name": "hengck23",
      "author_url": "",
      "post_date": "04/03/2023 06:05:28",
      "content": "<p><a href=\"https://stackoverflow.com/questions/33700049/get-the-diagonal-of-a-matrix-in-tensorflow\" target=\"_blank\">https://stackoverflow.com/questions/33700049/get-the-diagonal-of-a-matrix-in-tensorflow</a></p>\n<pre><code>x_flat = tf.reshape(x, [-1])  # flatten the matrix\nx_diag = tf.gather(x, [0, 3, 6]) # hard code the digonal index\n</code></pre>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "2206734": "Hi Everyone,\n\nI'm having a bit of trouble with the following error when I try to convert my model.\n\n\"Some ops are not supported by the native TFLite runtime, you can enable TF kernels fallback using TF Select. See instructions: https://www.tensorflow.org/lite/guide/ops_select \nTF Select ops: Conv2D, MatrixDiagPartV3\"\n\nThe Conv2D is from a convolutional layer I'm using and I'm assuming the \"MatrixDiagPartV3\" is from the following line of code in my notebook: tf.linalg.diag_part(G)\n\nWhen I use the following code, which I got from the link provided after \"See instructions:\", the model converts just fine.\n\nkeras_model_converter.target_spec.supported_ops = [\n  tf.lite.OpsSet.TFLITE_BUILTINS, # enable TensorFlow Lite ops.\n  tf.lite.OpsSet.SELECT_TF_OPS # enable TensorFlow ops.\n]\n\nHowever, as noted in the linked notebook (https://www.kaggle.com/competitions/asl-signs/discussion/398531), these ops don't seem to be supported for this competition...Does anyone have any advice on how to use tf.keras.layers.Conv2D() or tf.linalg.diag_part() in this competition without having to write a convolutional block and a matrix diagonalizer from scratch?",
    "2206879": "https://www.tensorflow.org/model_optimization/guide/pruning/pruning_for_on_device_inference\n\nI found this example where tf.keras.layers.Conv2D is acceptable without needing extra OPs, but I can't seem to make it work and when I paste it in my notebook and try to just convert exactly their model, it throws the same error as above...I'm very new to tflite, so this is rather confusing.",
    "2207123": "https://stackoverflow.com/questions/33700049/get-the-diagonal-of-a-matrix-in-tensorflow\n```\nx_flat = tf.reshape(x, [-1])  # flatten the matrix\nx_diag = tf.gather(x, [0, 3, 6]) # hard code the digonal index\n```",
    "2207343": "Indeed, Conv2D op is supported by tflite, but there may be some limitations. Recently, I've faced the same issue, that Conv2D op was not supported. I've spent a lot of time debugging it and finally I discovered, that key problem was not in Conv2D itself, but in some operation before Conv2D. I've preprocessed data in such a way that I lose the shape of the input feature. This caused a failure of tflite.\n\nI am not sure whether this is your case, but I am pretty sure that Conv2D is working well, except for some minor things (like unknown shape, unsupported input data type, etc.). I would recommend you to try to convert a raw model without preprocessing step and check out whether it causes crash.",
    "2207475": "Thanks @Mykola! This might be my problem as well. I'll try debugging this!",
    "2207667": "Good luck for you. Would love to hear that was a problem, once you found it"
  },
  "source": "meta"
}