{
  "id": 390008,
  "title": "Hello from the TensorFlow Lite team!",
  "url": "/competitions/asl-signs/discussion/390008",
  "author_name": "Paul Ruiz",
  "post_date": "2023-02-23T17:38:21.647000",
  "votes": 26,
  "comment_count": 75,
  "views": 0,
  "content": "<p>Hey all! I'm Paul, a developer advocate with the TensorFlow team. I wanted to make a discussion thread here for all TensorFlow Lite related questions so we can follow along in a centralized place and get the correct people around for sharing their knowledge :)</p>",
  "messages": [
    {
      "id": 2157047,
      "postDate": "2023-02-23T17:38:21.647Z",
      "content": "<p>Hey all! I'm Paul, a developer advocate with the TensorFlow team. I wanted to make a discussion thread here for all TensorFlow Lite related questions so we can follow along in a centralized place and get the correct people around for sharing their knowledge :)</p>",
      "rawMarkdown": "Hey all! I'm Paul, a developer advocate with the TensorFlow team. I wanted to make a discussion thread here for all TensorFlow Lite related questions so we can follow along in a centralized place and get the correct people around for sharing their knowledge :)",
      "votes": 26
    },
    {
      "id": 2160198,
      "postDate": "2023-02-26T13:13:00.060Z",
      "content": "<blockquote>\n  <p>Your model must also require less than 40 MB in memory</p>\n</blockquote>\n<p>How do we calculate the in-memory size of a model?  What specific checks does the submission evaluation run - so that we can pre-check our models and avoid wasted submissions.</p>",
      "rawMarkdown": "> Your model must also require less than 40 MB in memory\n\nHow do we calculate the in-memory size of a model?  What specific checks does the submission evaluation run - so that we can pre-check our models and avoid wasted submissions.",
      "votes": 11,
      "replies": [
        {
          "id": 2169859,
          "postDate": "2023-03-05T13:58:28.253Z",
          "content": "<p>This is my rule of thumb:</p>\n<p>Calculate the memory usage of the model by multiplying the number of parameters by the number of bytes required to store each parameter. For example, if your model has 10 million parameters and each parameter requires 4 bytes, the total memory usage would be 40 MB.</p>\n<p>Note that the actual memory usage of the model may differ from this calculated value due to various factors such as the use of GPU memory, data type of the parameters, and any compression or optimization techniques used.</p>\n<p>I’d also note that it appears more permissive than the above because I’ve definitely submitted models that are 10M+ that have succeeded.</p>\n<p>Hope that helps!</p>",
          "rawMarkdown": "This is my rule of thumb:\n\nCalculate the memory usage of the model by multiplying the number of parameters by the number of bytes required to store each parameter. For example, if your model has 10 million parameters and each parameter requires 4 bytes, the total memory usage would be 40 MB.\n\nNote that the actual memory usage of the model may differ from this calculated value due to various factors such as the use of GPU memory, data type of the parameters, and any compression or optimization techniques used.\n\nI’d also note that it appears more permissive than the above because I’ve definitely submitted models that are 10M+ that have succeeded.\n\nHope that helps!",
          "votes": 6
        }
      ]
    },
    {
      "id": 2162315,
      "postDate": "2023-02-28T05:59:02.477Z",
      "content": "<p>I recently started learning Tensorflow and wish to confirm that my understanding is correct:</p>\n<ul>\n<li>TFlite is not for building models but for using them in practice.</li>\n<li>So they can be built in Tensorflow as usual.</li>\n<li>But tensorflow models by themselves are not tflite compatible.</li>\n<li>So we use tf.lite.TFLiteConverter to make it tflite compatible.(source: <a href=\"https://www.tensorflow.org/lite/guide/inference\" target=\"_blank\">https://www.tensorflow.org/lite/guide/inference</a>)<br>\nPlease let me know if this is correct or correct where required.<br>\nAlso, please suggest any other methods we can use.</li>\n</ul>",
      "rawMarkdown": "I recently started learning Tensorflow and wish to confirm that my understanding is correct:\n- TFlite is not for building models but for using them in practice.\n- So they can be built in Tensorflow as usual.\n- But tensorflow models by themselves are not tflite compatible.\n- So we use tf.lite.TFLiteConverter to make it tflite compatible.(source: [https://www.tensorflow.org/lite/guide/inference](https://www.tensorflow.org/lite/guide/inference))\nPlease let me know if this is correct or correct where required.\nAlso, please suggest any other methods we can use.",
      "votes": 5
    },
    {
      "id": 2170436,
      "postDate": "2023-03-06T02:06:44.333Z",
      "content": "<p>Is there a list somewhere that tells us what layers are compatible with TFlite? Since we are dealing with sequences of data, I tried using LSTM and GRU, but both don't seem to be compatible with TFlite. It technically runs, but when I convert to TFlite I get this warning: </p>\n<p>WARNING:absl:Found untraced functions such as _update_step_xla, lstm_cell_1_layer_call_fn, lstm_cell_1_layer_call_and_return_conditional_losses, lstm_cell_2_layer_call_fn, lstm_cell_2_layer_call_and_return_conditional_losses while saving (showing 5 of 5). These functions will not be directly callable after loading.</p>\n<p>The accuracy when using the TFlite model is much lower than when using regular TF model. Assuming it's because GRU and LSTM are not compatible with TFlite?</p>",
      "rawMarkdown": "Is there a list somewhere that tells us what layers are compatible with TFlite? Since we are dealing with sequences of data, I tried using LSTM and GRU, but both don't seem to be compatible with TFlite. It technically runs, but when I convert to TFlite I get this warning: \n\nWARNING:absl:Found untraced functions such as _update_step_xla, lstm_cell_1_layer_call_fn, lstm_cell_1_layer_call_and_return_conditional_losses, lstm_cell_2_layer_call_fn, lstm_cell_2_layer_call_and_return_conditional_losses while saving (showing 5 of 5). These functions will not be directly callable after loading.\n\nThe accuracy when using the TFlite model is much lower than when using regular TF model. Assuming it's because GRU and LSTM are not compatible with TFlite?",
      "votes": 3
    },
    {
      "id": 2157188,
      "postDate": "2023-02-23T19:05:00.070Z",
      "content": "<p>As, I am at starting state of learning, I don't known weather it will complete or not. But for me this project seams to be a great one and I will try to learn at least something while working on this.</p>\n<p>thank you for this amazing project</p>",
      "rawMarkdown": "As, I am at starting state of learning, I don't known weather it will complete or not. But for me this project seams to be a great one and I will try to learn at least something while working on this.\n\n\nthank you for this amazing project\n",
      "votes": 3
    },
    {
      "id": 2158548,
      "postDate": "2023-02-25T00:32:07.537Z",
      "content": "<blockquote>\n  <p>Your model must also require less than 40 MB in memory and perform inference with less than 100 milliseconds of latency per video. </p>\n</blockquote>\n<p>How should we calculate the inference latency for each video on the validation set? Should we calculate the time between reading data from disk and getting inference results? Because I assume we can't get all the data to be read into RAM or graphics memory</p>",
      "rawMarkdown": ">Your model must also require less than 40 MB in memory and perform inference with less than 100 milliseconds of latency per video. \n\nHow should we calculate the inference latency for each video on the validation set? Should we calculate the time between reading data from disk and getting inference results? Because I assume we can't get all the data to be read into RAM or graphics memory",
      "votes": 4,
      "replies": [
        {
          "id": 2160593,
          "postDate": "2023-02-26T19:46:55.430Z",
          "content": "<p>It talks about the storage and runtime your trained model takes for a given input. Hope this clarifies your query!</p>",
          "rawMarkdown": "It talks about the storage and runtime your trained model takes for a given input. Hope this clarifies your query!",
          "votes": -3
        },
        {
          "id": 2169858,
          "postDate": "2023-03-05T13:56:41.720Z",
          "content": "<p>For inference timing you can time the inference code that they provide in a loop and time it. If your using a variable time series, I would do the 75% upper quantile of number of frames to mimic a slightly longer than average runtime. That should give you a bit of buffer.</p>\n<p>For size, calculate the memory usage of the model by multiplying the number of parameters by the number of bytes required to store each parameter. For example, if your model has 10 million parameters and each parameter requires 4 bytes, the total memory usage would be 40 MB.<br>\nNote that the actual memory usage of the model may differ from this calculated value due to various factors such as the use of GPU memory, data type of the parameters, and any compression or optimization techniques used.</p>\n<p>Hope that helps!</p>",
          "rawMarkdown": "For inference timing you can time the inference code that they provide in a loop and time it. If your using a variable time series, I would do the 75% upper quantile of number of frames to mimic a slightly longer than average runtime. That should give you a bit of buffer.\n\nFor size, calculate the memory usage of the model by multiplying the number of parameters by the number of bytes required to store each parameter. For example, if your model has 10 million parameters and each parameter requires 4 bytes, the total memory usage would be 40 MB.\nNote that the actual memory usage of the model may differ from this calculated value due to various factors such as the use of GPU memory, data type of the parameters, and any compression or optimization techniques used.\n\nHope that helps!"
        }
      ]
    },
    {
      "id": 2157243,
      "postDate": "2023-02-23T20:35:48.100Z",
      "content": "<p>what is the best tools/way to convert Pytorch model to tflite?</p>",
      "rawMarkdown": "what is the best tools/way to convert Pytorch model to tflite?",
      "votes": 1,
      "replies": [
        {
          "id": 2157381,
          "postDate": "2023-02-24T01:03:09.540Z",
          "content": "<p>We see many PyTorch developers who deploy via TensorFlow Lite use a path of PyTorch -&gt; ONNX -&gt; TensorFlow -&gt; TensorFlow Lite. Two community posts demonstrating this path are <a href=\"https://medium.com/geekculture/converting-yolo-v7-to-tensorflow-lite-for-mobile-deployment-ebc1103e8d1e\" target=\"_blank\">https://medium.com/geekculture/converting-yolo-v7-to-tensorflow-lite-for-mobile-deployment-ebc1103e8d1e</a> and <a href=\"https://github.com/sayakpaul/Adventures-in-TensorFlow-Lite/blob/master/TUNIT_Conversion_to_TF_Lite.ipynb\" target=\"_blank\">https://github.com/sayakpaul/Adventures-in-TensorFlow-Lite/blob/master/TUNIT_Conversion_to_TF_Lite.ipynb</a></p>",
          "rawMarkdown": "We see many PyTorch developers who deploy via TensorFlow Lite use a path of PyTorch -> ONNX -> TensorFlow -> TensorFlow Lite. Two community posts demonstrating this path are https://medium.com/geekculture/converting-yolo-v7-to-tensorflow-lite-for-mobile-deployment-ebc1103e8d1e and https://github.com/sayakpaul/Adventures-in-TensorFlow-Lite/blob/master/TUNIT_Conversion_to_TF_Lite.ipynb",
          "votes": 9
        }
      ]
    },
    {
      "id": 2157385,
      "postDate": "2023-02-24T01:04:14.190Z",
      "content": "<blockquote>\n  <p>This competition requires submissions to be made in the form of TensorFlow Lite models. You are welcome to train your model using the framework of your choice as long as you convert the model checkpoint into the tflite format prior to submission. Please see the evaluation page for details.</p>\n</blockquote>\n<p>What if we did not use TensorFlow Lite models? We will be removed from Leaderboard?</p>",
      "rawMarkdown": "> This competition requires submissions to be made in the form of TensorFlow Lite models. You are welcome to train your model using the framework of your choice as long as you convert the model checkpoint into the tflite format prior to submission. Please see the evaluation page for details.\n\nWhat if we did not use TensorFlow Lite models? We will be removed from Leaderboard?",
      "replies": [
        {
          "id": 2157387,
          "postDate": "2023-02-24T01:07:14.163Z",
          "content": "<p>Your submission will fail without a TF Lite model.</p>",
          "rawMarkdown": "Your submission will fail without a TF Lite model.",
          "votes": 3,
          "replies": [
            {
              "id": 2216731,
              "postDate": "2023-04-10T09:52:33.367Z",
              "content": "<p>Cool, thank you!</p>",
              "rawMarkdown": "Cool, thank you!"
            }
          ]
        }
      ]
    },
    {
      "id": 2217824,
      "postDate": "2023-04-11T07:39:54.293Z",
      "content": "<p>Thanks for you amazing code, it helps me a lot</p>",
      "rawMarkdown": "Thanks for you amazing code, it helps me a lot",
      "votes": -2
    },
    {
      "id": 2232348,
      "postDate": "2023-04-24T08:31:08.840Z",
      "content": "<p>very good.this code help me a lot</p>",
      "rawMarkdown": "very good.this code help me a lot"
    },
    {
      "id": 2226249,
      "postDate": "2023-04-18T19:17:47.850Z",
      "content": "<p>Hello<br>\nI receive error message:</p>\n<pre><code>error:  op  neither a custom op nor a flex op\nerror: failed  converting: : \nSome ops are  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\nDetails:\n    tf.Conv2D(tensor&lt;*xf32&gt;, tensor&lt;2x2x3x32xf32&gt;) -&gt; (tensor&lt;?x?x?x32xf32&gt;) : {data_format = , device = , dilations = [, , , ], explicit_paddings = [], padding = , strides = [, , , ], use_cudnn_on_gpu = true}\n</code></pre>\n<p>Why it's happens? According <a href=\"https://www.tensorflow.org/mlir/tfl_ops?hl=ru#tflconv_2d_mlirtflconv2dop\" target=\"_blank\">https://www.tensorflow.org/mlir/tfl_ops?hl=ru#tflconv_2d_mlirtflconv2dop</a> conv_2d layers are supported</p>",
      "rawMarkdown": "Hello\nI receive error message:\n\n```python\nerror: 'tf.Conv2D' op is neither a custom op nor a flex op\nerror: failed while converting: 'main': \nSome 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\nDetails:\n    tf.Conv2D(tensor<*xf32>, tensor<2x2x3x32xf32>) -> (tensor<?x?x?x32xf32>) : {data_format = \"NHWC\", device = \"\", dilations = [1, 1, 1, 1], explicit_paddings = [], padding = \"SAME\", strides = [1, 1, 1, 1], use_cudnn_on_gpu = true}\n```\nWhy it's happens? According https://www.tensorflow.org/mlir/tfl_ops?hl=ru#tflconv_2d_mlirtflconv2dop conv_2d layers are supported"
    },
    {
      "id": 2218660,
      "postDate": "2023-04-11T22:27:55.273Z",
      "content": "<p>TFlite models seem to grow in size very quickly for just a few more features in the data. Are there standard ways to shrink the size? </p>",
      "rawMarkdown": "TFlite models seem to grow in size very quickly for just a few more features in the data. Are there standard ways to shrink the size? "
    },
    {
      "id": 2198405,
      "postDate": "2023-03-27T01:22:30.350Z",
      "content": "<p>Several people have already mentioned the topic of \"TensorFlow operators\".<br>\nAs far as I can confirm, the current submission environment does not support TensorFlow operators, I would expect.<br>\nI checked on the Kaggle notebook and it is possible to support TensorFlow operators in tflite_runtime by importing tensorflow as follows</p>\n<pre><code>@@ -1,3 +1,4 @@\n+import tensorflow\n import tflite_runtime.interpreter as tflite\n interpreter = tflite.Interpreter(model_path)\n</code></pre>\n<p>It seems that the introduction of TensorFlow operators is not impractical for device implementations.<br>\n<a href=\"https://www.tensorflow.org/lite/guide/ops_select\" target=\"_blank\">https://www.tensorflow.org/lite/guide/ops_select</a></p>\n<p>Is there any possibility of this modification to the submission environment?</p>\n<p>I would be very happy if TensorFlow operators were introduced, as I think it would make it easier to implement more complex models and increase our chances of achieving greater results.</p>\n<p>I welcome any comments on implementation issues on the device, concerns about competitiveness, etc.</p>",
      "rawMarkdown": "Several people have already mentioned the topic of \"TensorFlow operators\".\nAs far as I can confirm, the current submission environment does not support TensorFlow operators, I would expect.\nI checked on the Kaggle notebook and it is possible to support TensorFlow operators in tflite_runtime by importing tensorflow as follows\n\n```\n@@ -1,3 +1,4 @@\n+import tensorflow\n import tflite_runtime.interpreter as tflite\n interpreter = tflite.Interpreter(model_path)\n```\n\nIt seems that the introduction of TensorFlow operators is not impractical for device implementations.\nhttps://www.tensorflow.org/lite/guide/ops_select\n\nIs there any possibility of this modification to the submission environment?\n\nI would be very happy if TensorFlow operators were introduced, as I think it would make it easier to implement more complex models and increase our chances of achieving greater results.\n\nI welcome any comments on implementation issues on the device, concerns about competitiveness, etc.\n",
      "replies": [
        {
          "id": 2199328,
          "postDate": "2023-03-27T16:27:59.200Z",
          "content": "<p>We're deliberately excluding TensorFlow operators as the goal of the competition is to generate models that could potentially run on cell phones.</p>",
          "rawMarkdown": "We're deliberately excluding TensorFlow operators as the goal of the competition is to generate models that could potentially run on cell phones.",
          "votes": 1
        }
      ]
    },
    {
      "id": 2189855,
      "postDate": "2023-03-20T20:52:02.770Z",
      "content": "<p>Hello, guys. I faced an issue with tf.data pipeline working in graph mode. I need to edit the tensor somehow, but I cannot do so. I understand that tf.Tensor is immutable and supposed to work in a functional style. So, I am creating tf.Variable from it and that works well in eager execution mode. But tf.data pipeline uses graph mode and makes tf.Variable creation in such a way impossible. <br>\nHere is a minimalistic code, which reproduce my issue:</p>\n<blockquote>\n  <p>import tensorflow as tf</p>\n  <p>x = tf.constant([1,2,3.0])<br>\n  ds = tf.data.Dataset.from_tensors(x)</p>\n  <p>def test(x):<br>\n       with tf.init_scope():<br>\n       v = tf.Variable(x)</p>\n  <p>ds_x = ds.map(test)<br>\n  next(iter(ds_x))</p>\n</blockquote>\n<p>Here is an error I get</p>\n<p>`<br>\nValueError: in user code:</p>\n<pre><code>File \"/tmp/ipykernel_3517/140449158.py\", line 6, in test  *\n    v = tf.Variable(x)\n\nValueError: Argument `initial_value` (Tensor(\"args_0:0\", shape=(3,), dtype=float32)) could not be lifted out of a `tf.function`. (Tried to create variable with name='None'). To avoid this error, when constructing `tf.Variable`s inside of `tf.function` you can create the `initial_value` tensor in a `tf.init_scope` or pass a callable `initial_value` (e.g., `tf.Variable(lambda : tf.truncated_normal([10, 40]))`). Please file a feature request if this restriction inconveniences you.\n</code></pre>\n<p>`</p>\n<p>Best to my understanding, I cannot create a tf.Variable which depends on input tensor <code>x</code> because of static execution graph. But how do I change a part of input tensor <code>x</code>, where the decision of that part is depends on <code>x</code> content?</p>\n<p>Looking forward to your advice. Thank you in advance</p>",
      "rawMarkdown": "Hello, guys. I faced an issue with tf.data pipeline working in graph mode. I need to edit the tensor somehow, but I cannot do so. I understand that tf.Tensor is immutable and supposed to work in a functional style. So, I am creating tf.Variable from it and that works well in eager execution mode. But tf.data pipeline uses graph mode and makes tf.Variable creation in such a way impossible. \nHere is a minimalistic code, which reproduce my issue:\n\n>import tensorflow as tf\n>\n>x = tf.constant([1,2,3.0])\n>ds = tf.data.Dataset.from_tensors(x)\n>\n>def test(x):\n>      with tf.init_scope():\n>      v = tf.Variable(x)\n>\n>ds_x = ds.map(test)\n>next(iter(ds_x))\n\nHere is an error I get\n\n`\nValueError: in user code:\n\n    File \"/tmp/ipykernel_3517/140449158.py\", line 6, in test  *\n        v = tf.Variable(x)\n\n    ValueError: Argument `initial_value` (Tensor(\"args_0:0\", shape=(3,), dtype=float32)) could not be lifted out of a `tf.function`. (Tried to create variable with name='None'). To avoid this error, when constructing `tf.Variable`s inside of `tf.function` you can create the `initial_value` tensor in a `tf.init_scope` or pass a callable `initial_value` (e.g., `tf.Variable(lambda : tf.truncated_normal([10, 40]))`). Please file a feature request if this restriction inconveniences you.\n`\n\nBest to my understanding, I cannot create a tf.Variable which depends on input tensor `x` because of static execution graph. But how do I change a part of input tensor `x`, where the decision of that part is depends on `x` content?\n\nLooking forward to your advice. Thank you in advance",
      "replies": [
        {
          "id": 2190236,
          "postDate": "2023-03-21T06:04:22.103Z",
          "content": "<p>Hi Mykola,</p>\n<p>This is the code snippet I was sent for your issue:</p>\n<pre><code>import tensorflow as tf\n\nx = tf.constant([1,2,3,4,5,6])\nds = tf.data.Dataset.from_tensor_slices(x)\n\n@tf.function\ndef test(x):\n  if x &gt; 2:\n    return x**2\n  else:\n    return x\n\nds_x = ds.map(test)\n\nfor x in iter(ds_x):\n  print(x)\n</code></pre>\n<p>You can also find a lot of examples for tf.data here:  <a href=\"https://www.tensorflow.org/guide/data\" target=\"_blank\">https://www.tensorflow.org/guide/data</a></p>",
          "rawMarkdown": "Hi Mykola,\n\nThis is the code snippet I was sent for your issue:\n\n```\nimport tensorflow as tf\n\nx = tf.constant([1,2,3,4,5,6])\nds = tf.data.Dataset.from_tensor_slices(x)\n\n@tf.function\ndef test(x):\n  if x > 2:\n    return x**2\n  else:\n    return x\n\nds_x = ds.map(test)\n\nfor x in iter(ds_x):\n  print(x)\n```\n\nYou can also find a lot of examples for tf.data here:  https://www.tensorflow.org/guide/data",
          "votes": 1,
          "replies": [
            {
              "id": 2190448,
              "postDate": "2023-03-21T08:40:22.010Z",
              "content": "<p>I am not sure, whether this solves my problem, but further investigation gives me the following intuition and almost the solution (I am still in progress now). I would like to ask you whether my thoughts are correct or if am I wrong in so something. </p>\n<p>The goal is to calculate the mean of the input vector by segments. The actual segments depend on the content of the input vector.</p>\n<pre><code> ():\n    ...\n     segments \n</code></pre>\n<p>And now I am going to iterate over each segments and calculate mean</p>\n<pre><code> ():\n    segments = get_segments(x)\n    mean_list = []\n     i  segments: \n        mean_list.append(tf.math.reduce_mean(x[i[]:i[]))  \n\n    means = tf.stack(mean_list)  \n</code></pre>\n<p>This works pretty well in eager mode, but fails if I decorate it with <code>@tf.function</code>. That makes sense. Creating a mutable list is a violation of functional programming, thus we could not build a static computational graph. In fact, a list works well, if I create it with a  predefined length (like, <code>mean_list = [tf.constant(2), tf.math.reduce_mean(x[a:b]), ...]</code>). I guess TensorFlow graph compiler is smart enough to understand that list in that case is not going to be mutable ever.</p>\n<p>Regarding the task of calculating mean over segments currently, I found a possible solution with <code>tf.map_fn</code>. I discover a way to pass multiple arguments to <code>fn</code> using <code>tf.map_fn</code> (via tuples) - vector <code>x</code> and segment <code>i</code> in my case. This way enforces me to have the same shape over the first axis. So, I need to tile an <code>x</code> vector <code>N</code> times, in order to have the same length first axis - <code>[N, None]</code> for <code>x</code> and <code>[N, 2]</code> for segments. Hope, that would resolve my current issue.</p>\n<p>Taking the opportunity, I would like to ask you the following questions:</p>\n<ul>\n<li><p>Am I right, that all code under <code>tf.function</code> should be purely functional?</p></li>\n<li><p>Does my solution with <code>tf.map_fn</code> the best one for the task described above?</p></li>\n<li><p>Doesn't the <code>tf.data</code> pipeline support eager execution mode?</p>\n<p>Sorry, I some of the questions are trivial, but I spent a loot of time starting from the first release of TF2.0 on this. Thank you in advance!</p></li>\n</ul>",
              "rawMarkdown": "I am not sure, whether this solves my problem, but further investigation gives me the following intuition and almost the solution (I am still in progress now). I would like to ask you whether my thoughts are correct or if am I wrong in so something. \n\nThe goal is to calculate the mean of the input vector by segments. The actual segments depend on the content of the input vector.\n\n```python\ndef get_segments(x):\n    ...\n    return segments # Tensor of shape [N, 2], where N - number of segments found\n```\n\nAnd now I am going to iterate over each segments and calculate mean\n\n```python\ndef mean_by_segments(x):\n    segments = get_segments(x)\n    mean_list = []\n    for i in segments: # Iterate over each segments, so i has a shape of [2]\n        mean_list.append(tf.math.reduce_mean(x[i[0]:i[1]))  # Calculate mean on i-th segment and append it to the list\n\n    means = tf.stack(mean_list)  # Now stack all scalars together\n```\n\nThis works pretty well in eager mode, but fails if I decorate it with `@tf.function`. That makes sense. Creating a mutable list is a violation of functional programming, thus we could not build a static computational graph. In fact, a list works well, if I create it with a  predefined length (like, `mean_list = [tf.constant(2), tf.math.reduce_mean(x[a:b]), ...]`). I guess TensorFlow graph compiler is smart enough to understand that list in that case is not going to be mutable ever.\n\nRegarding the task of calculating mean over segments currently, I found a possible solution with `tf.map_fn`. I discover a way to pass multiple arguments to `fn` using `tf.map_fn` (via tuples) - vector `x` and segment `i` in my case. This way enforces me to have the same shape over the first axis. So, I need to tile an `x` vector `N` times, in order to have the same length first axis - `[N, None]` for `x` and `[N, 2]` for segments. Hope, that would resolve my current issue.\n\nTaking the opportunity, I would like to ask you the following questions:\n\n* Am I right, that all code under `tf.function` should be purely functional?\n* Does my solution with `tf.map_fn` the best one for the task described above?\n* Doesn't the `tf.data` pipeline support eager execution mode?\n\n Sorry, I some of the questions are trivial, but I spent a loot of time starting from the first release of TF2.0 on this. Thank you in advance!"
            },
            {
              "id": 2190528,
              "postDate": "2023-03-21T10:03:23.133Z",
              "content": "<p>The solution with <code>tf.map_fn</code> works, until <code>fn</code> returns tensors of different shapes. I want to apply the following function</p>\n<pre><code> ():\n    x = arg[]\n    _ = arg[]\n    a = r[]\n    b = r[]\n     x[a:b]*x[]  \n\n ():\n    segments = get_segments(x)\n    a = tf.tile(x, [(segments)])  \n    a = tf.reshape(a, [(segments), -])\n    c = tf.map_fn(take_it, (a,segments), fn_output_signature=tf.int64)\n\n    means = tf.stack(mean_list)  \n</code></pre>\n<p>Let say <code>x</code> is a tensor [0,1,2,3,4,5,6,7,8,9] and <code>get_segments(x)</code> returns the following</p>\n<pre><code>[[0, 3],\n [3, 7],\n [7, 10]]\n</code></pre>\n<p>I expect to get <code>[0,0,   4,6,8,10,   49,63]</code> as a result, but it is impossible since <code>take_it</code> returns tensors of different shapes. Now I get the following error:</p>\n<pre><code>2023-03-21 09:52:22.638552: W tensorflow/core/framework/op_kernel.cc:1830] OP_REQUIRES failed at list_kernels.h:206 : INVALID_ARGUMENT: PartialTensorShape: Incompatible shapes during merge: [2] vs. [4]\n</code></pre>\n<p>Could anyone give me an idea of how to solve my problem with <code>@tf.function</code> approach?</p>",
              "rawMarkdown": "The solution with `tf.map_fn` works, until `fn` returns tensors of different shapes. I want to apply the following function\n\n```python\ndef take_it(arg):\n    x = arg[0]\n    _range = arg[1]\n    a = r[0]\n    b = r[1]\n    return x[a:b]*x[0]  # Return segment multiplied by its first element\n\ndef mean_by_segments(x):\n    segments = get_segments(x)\n    a = tf.tile(x, [len(segments)])  # Tile ant reshape x to match shape [N, None]\n    a = tf.reshape(a, [len(segments), -1])\n    c = tf.map_fn(take_it, (a,segments), fn_output_signature=tf.int64)\n\n    means = tf.stack(mean_list)  # Now stack all scalars together\n```\n\nLet say `x` is a tensor [0,1,2,3,4,5,6,7,8,9] and `get_segments(x)` returns the following\n```\n[[0, 3],\n [3, 7],\n [7, 10]]\n```\n\nI expect to get `[0,0,   4,6,8,10,   49,63]` as a result, but it is impossible since `take_it` returns tensors of different shapes. Now I get the following error:\n```\n2023-03-21 09:52:22.638552: W tensorflow/core/framework/op_kernel.cc:1830] OP_REQUIRES failed at list_kernels.h:206 : INVALID_ARGUMENT: PartialTensorShape: Incompatible shapes during merge: [2] vs. [4]\n```\n\nCould anyone give me an idea of how to solve my problem with `@tf.function` approach?\n"
            },
            {
              "id": 2191285,
              "postDate": "2023-03-21T21:02:04.733Z",
              "content": "<p>It was a little bit tricky, but <code>tf.RadgedTensor</code> helped with stacking tensors of different shapes, produced by <code>tf.map_fn</code>. It works, but unfortunately, it is very slow, since I need to process each vector individually, in a 3D tensor of shape <code>[None, 543, 3]</code>. Since the example above deals only with vectors, I've tried to exploit <code>tf.map_fn</code> again, in order to map my <code>mean_by_segments</code> per frame axis and then per coordinate axis (yes, one <code>tf.map_fn</code> call another <code>tf.map_fn</code>. Now, it works as expected in autograph mode, but it is dramatically slow. For instance, processing one (sic!) sample takes from 200ms to 2s+ (depending on hardware). Having that, it is impossible ven to train a model using such preprocessing (even not talking about submission). <br>\nCould you provide any though on this? Thank you in advance.</p>",
              "rawMarkdown": "It was a little bit tricky, but `tf.RadgedTensor` helped with stacking tensors of different shapes, produced by `tf.map_fn`. It works, but unfortunately, it is very slow, since I need to process each vector individually, in a 3D tensor of shape `[None, 543, 3]`. Since the example above deals only with vectors, I've tried to exploit `tf.map_fn` again, in order to map my `mean_by_segments` per frame axis and then per coordinate axis (yes, one `tf.map_fn` call another `tf.map_fn`. Now, it works as expected in autograph mode, but it is dramatically slow. For instance, processing one (sic!) sample takes from 200ms to 2s+ (depending on hardware). Having that, it is impossible ven to train a model using such preprocessing (even not talking about submission). \nCould you provide any though on this? Thank you in advance."
            }
          ]
        }
      ]
    },
    {
      "id": 2185203,
      "postDate": "2023-03-16T21:52:32.470Z",
      "content": "<p>Hi there! Are there any constrains on the model submission for using <code>supported_ops</code>?<br>\n<strong>If so, it should be updated on the Submission Requirements</strong></p>\n<p>My submission size is les than 2mb and time is under 100ms but still gives an error.<br>\nThe only different thing I have from other submissions is that Im using this:</p>\n<pre><code>converter.target_spec.supported_ops = [\n    tf.lite.OpsSet.TFLITE_BUILTINS, \n    tf.lite.OpsSet.SELECT_TF_OPS \n]\n</code></pre>",
      "rawMarkdown": "Hi there! Are there any constrains on the model submission for using `supported_ops`?\n**If so, it should be updated on the Submission Requirements**\n\nMy submission size is les than 2mb and time is under 100ms but still gives an error.\nThe only different thing I have from other submissions is that Im using this:\n```python\nconverter.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```",
      "replies": [
        {
          "id": 2195167,
          "postDate": "2023-03-24T13:23:35.303Z",
          "content": "<p>me too.<br>\nI faced the following error </p>\n<blockquote>\n  <p>ConverterError: /opt/conda/lib/python3.7/site-packages/tensorflow/python/util/deprecation.py:561:0: error: 'tf.TensorListReserve' op requires element_shape to be 1D tensor during TF Lite transformation pass<br>\n  :0: note: loc(fused[\"StatefulPartitionedCall:\", \"StatefulPartitionedCall\"]): called from<br>\n  /opt/conda/lib/python3.7/site-packages/tensorflow/python/util/deprecation.py:561:0: error: failed to legalize operation 'tf.TensorListReserve' that was explicitly marked illegal<br>\n  :0: note: loc(fused[\"StatefulPartitionedCall:\", \"StatefulPartitionedCall\"]): called from<br>\n  :0: error: Lowering tensor list ops is failed. Please consider using Select TF ops and disabling <code>_experimental_lower_tensor_list_ops</code> flag in the TFLite converter object. For example, converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS, tf.lite.OpsSet.SELECT_TF_OPS]\\n converter._experimental_lower_tensor_list_ops = False</p>\n</blockquote>\n<p>and tried to prevent this error to add following code.</p>\n<blockquote>\n  <p>keras_model_converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS, tf.lite.OpsSet.SELECT_TF_OPS]<br>\n  keras_model_converter._experimental_lower_tensor_list_ops = False</p>\n</blockquote>\n<p>It worked fine in kaggle notebook, but my submission failed.</p>\n<p>Unfortunately, the error don't show which part(operator) is the error, so I can't solve the problem now.</p>",
          "rawMarkdown": "me too.\nI faced the following error \n>ConverterError: /opt/conda/lib/python3.7/site-packages/tensorflow/python/util/deprecation.py:561:0: error: 'tf.TensorListReserve' op requires element_shape to be 1D tensor during TF Lite transformation pass\n:0: note: loc(fused[\"StatefulPartitionedCall:\", \"StatefulPartitionedCall\"]): called from\n/opt/conda/lib/python3.7/site-packages/tensorflow/python/util/deprecation.py:561:0: error: failed to legalize operation 'tf.TensorListReserve' that was explicitly marked illegal\n:0: note: loc(fused[\"StatefulPartitionedCall:\", \"StatefulPartitionedCall\"]): called from\n:0: error: Lowering tensor list ops is failed. Please consider using Select TF ops and disabling `_experimental_lower_tensor_list_ops` flag in the TFLite converter object. For example, converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS, tf.lite.OpsSet.SELECT_TF_OPS]\\n converter._experimental_lower_tensor_list_ops = False\n\nand tried to prevent this error to add following code.\n>keras_model_converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS, tf.lite.OpsSet.SELECT_TF_OPS]\nkeras_model_converter._experimental_lower_tensor_list_ops = False\n\nIt worked fine in kaggle notebook, but my submission failed.\n\nUnfortunately, the error don't show which part(operator) is the error, so I can't solve the problem now.",
          "replies": [
            {
              "id": 2195297,
              "postDate": "2023-03-24T14:59:22.013Z",
              "content": "<p>I've solve the problem by only using simple operator.<br>\nBy rewriting function with simple operator step by step and converting, I found the source of problem.</p>",
              "rawMarkdown": "I've solve the problem by only using simple operator.\nBy rewriting function with simple operator step by step and converting, I found the source of problem.",
              "votes": 1
            }
          ]
        }
      ]
    },
    {
      "id": 2173968,
      "postDate": "2023-03-08T18:49:17.810Z",
      "content": "<p>Hi all, I Hope you all are well. </p>\n<p>My TFLite model works fine with tflite-runtime version 2.11.0, However, it causes the notebook to crash if I use 2.9.1 instead.</p>\n<p>The notebook crashes while initializing the interpreter.</p>\n<p>interpreter = tflite.Interpreter(tflite_model_path)</p>\n<p>while loading the interpreter in tflite-runtime version 2.11.0, I get following warnings.</p>\n<ul>\n<li>INFO: Created TensorFlow Lite delegate for select TF ops.</li>\n<li>INFO: TfLiteFlexDelegate delegate: 30 nodes delegated out of 166 nodes with 2 partitions.</li>\n</ul>\n<p>Any help would be appreciated. Thanks</p>",
      "rawMarkdown": "Hi all, I Hope you all are well. \n\nMy TFLite model works fine with tflite-runtime version 2.11.0, However, it causes the notebook to crash if I use 2.9.1 instead.\n\nThe notebook crashes while initializing the interpreter.\n\ninterpreter = tflite.Interpreter(tflite_model_path)\n\nwhile loading the interpreter in tflite-runtime version 2.11.0, I get following warnings.\n\n-  INFO: Created TensorFlow Lite delegate for select TF ops.\n-  INFO: TfLiteFlexDelegate delegate: 30 nodes delegated out of 166 nodes with 2 partitions.\n\nAny help would be appreciated. Thanks"
    },
    {
      "id": 2173799,
      "postDate": "2023-03-08T16:42:54.613Z",
      "content": "<p>How do I convert from Pytorch and use tensorflow without running into any bugs ?</p>",
      "rawMarkdown": "How do I convert from Pytorch and use tensorflow without running into any bugs ?",
      "replies": [
        {
          "id": 2198675,
          "postDate": "2023-03-27T08:26:25.443Z",
          "content": "<p>I think this answer may be what you're looking for (unless you figured it out already): <a href=\"https://www.kaggle.com/competitions/asl-signs/discussion/390008#2157381\" target=\"_blank\">https://www.kaggle.com/competitions/asl-signs/discussion/390008#2157381</a> </p>",
          "rawMarkdown": "I think this answer may be what you're looking for (unless you figured it out already): https://www.kaggle.com/competitions/asl-signs/discussion/390008#2157381 "
        }
      ]
    },
    {
      "id": 2171174,
      "postDate": "2023-03-06T15:03:59.573Z",
      "content": "<p>Hi all,</p>\n<p>I have two questions:</p>\n<p>(1) several preprocessed datasets are currently in use: if we generate our own preprocessed dataset (e.g. with a different batch size or different preprocessing), do we need to regenerate this from scratch in our final submission? Or do we only need to generate it once and is any dataset we generate automatically coupled to the notebook that generated it? I'm also not sure how (where) to save a self-generated dataset from one notebook in such a way we can use it from a different notebook.<br>\n(2) W.r.t. the time constraint for TfLite inference: does a submission fail when that is exceeded? And if not: how can we know whether our submission meets this constraint?</p>",
      "rawMarkdown": "Hi all,\n\nI have two questions:\n\n(1) several preprocessed datasets are currently in use: if we generate our own preprocessed dataset (e.g. with a different batch size or different preprocessing), do we need to regenerate this from scratch in our final submission? Or do we only need to generate it once and is any dataset we generate automatically coupled to the notebook that generated it? I'm also not sure how (where) to save a self-generated dataset from one notebook in such a way we can use it from a different notebook.\n(2) W.r.t. the time constraint for TfLite inference: does a submission fail when that is exceeded? And if not: how can we know whether our submission meets this constraint?",
      "replies": [
        {
          "id": 2172416,
          "postDate": "2023-03-07T14:10:27.773Z",
          "content": "<blockquote>\n  <p>I'm also not sure how (where) to save a self-generated dataset from one notebook in such a way we can use it from a different notebook.</p>\n</blockquote>\n<p>As I understand, you can add your own dataset through upload button in top right of the notebook, and then you can add it in any notebook. You can also set visibility setting to private if you don't want others to see it. </p>",
          "rawMarkdown": ">I'm also not sure how (where) to save a self-generated dataset from one notebook in such a way we can use it from a different notebook.\n\nAs I understand, you can add your own dataset through upload button in top right of the notebook, and then you can add it in any notebook. You can also set visibility setting to private if you don't want others to see it. "
        }
      ]
    },
    {
      "id": 2169836,
      "postDate": "2023-03-05T13:28:47.837Z",
      "content": "<p>Hi,</p>\n<p>I'm using TensorFlow to make my model for this competition. I tried enabling mixed precision (using float16 and float32 during the training) to reduce the training time, which works just fine. But when I try to convert my (final) trained model into TensorFlow Lite format for submission, the conversion takes too much time. (I waited about 5 hours before manually stopping  the conversion code; the code for conversion just stayed hung.) When I don't enable global mixed precision policy in TensorFlow, the conversion works fine, and it takes about a minute or so. </p>\n<p>This is my conversion code:</p>\n<pre><code>\nconverter = tf.lite.TFLiteConverter.from_keras_model(final_model)\n\ntflite_model = converter.convert()\nmodel_path = \n\n\n (model_path, )  f:\n    f.write(tflite_model)\n\n\n! submission. $model_path\n</code></pre>\n<p>Do you have any workarounds for this problem?</p>\n<p>BTW, I use TensorFlow 2.10 and 2.11 for training (and conversion).</p>",
      "rawMarkdown": "Hi,\n\nI'm using TensorFlow to make my model for this competition. I tried enabling mixed precision (using float16 and float32 during the training) to reduce the training time, which works just fine. But when I try to convert my (final) trained model into TensorFlow Lite format for submission, the conversion takes too much time. (I waited about 5 hours before manually stopping  the conversion code; the code for conversion just stayed hung.) When I don't enable global mixed precision policy in TensorFlow, the conversion works fine, and it takes about a minute or so. \n\nThis is my conversion code:\n\n```Python\n\n# Convert the final model to a 'tflite' model\nconverter = tf.lite.TFLiteConverter.from_keras_model(final_model)\n\ntflite_model = converter.convert()\nmodel_path = \"model.tflite\"\n\n# Save the tflite model\nwith open(model_path, 'wb') as f:\n    f.write(tflite_model)\n\n# Make the 'submission.zip'\n!zip submission.zip $model_path\n\n```\n\nDo you have any workarounds for this problem?\n\nBTW, I use TensorFlow 2.10 and 2.11 for training (and conversion).\n",
      "replies": [
        {
          "id": 2169854,
          "postDate": "2023-03-05T13:52:12.870Z",
          "content": "<p>Just a simple check, your using the right tflite runtime? I believe from the evaluation page it’s 2.9.1.</p>\n<p>An alternative to help with troubleshooting would be to try to make a simple, reproducible notebook.</p>\n<p>Ie </p>\n<ol>\n<li>New Notebook</li>\n<li>Initialize simple model with mixed precision (literally any model)</li>\n<li>Try to convert</li>\n</ol>\n<p>If it doesn’t fail, it’s probably something specific to comparability in one of the layers and potentially the interaction of that layer with mixed precision.</p>\n<p>You could also try training in full precision on your original notebook and converting as a simple check to make sure it has something to do with the mixed precision and not a particular op or layer </p>",
          "rawMarkdown": "Just a simple check, your using the right tflite runtime? I believe from the evaluation page it’s 2.9.1.\n\nAn alternative to help with troubleshooting would be to try to make a simple, reproducible notebook.\n\nIe \n1. New Notebook\n2. Initialize simple model with mixed precision (literally any model)\n3. Try to convert\n\nIf it doesn’t fail, it’s probably something specific to comparability in one of the layers and potentially the interaction of that layer with mixed precision.\n\nYou could also try training in full precision on your original notebook and converting as a simple check to make sure it has something to do with the mixed precision and not a particular op or layer ",
          "votes": 3,
          "replies": [
            {
              "id": 2170558,
              "postDate": "2023-03-06T05:16:42.490Z",
              "content": "<p>Great suggestions. Thanks for the help.</p>",
              "rawMarkdown": "Great suggestions. Thanks for the help."
            }
          ]
        }
      ]
    },
    {
      "id": 2169118,
      "postDate": "2023-03-04T19:44:49.497Z",
      "content": "<p>Dear experts,</p>\n<p>I'm still confused about one thing in TfLite. Tensorflow models always have a 'hidden' first input dimension corresponding to batch size, with 'None' size to account for variable batch size. In the code posted by Lonnie, for the inference model, the batch dimension is 'abused' as a time dimension. When you train a variable time step time series model in Tensorflow, you typically have two None dimensions: one for batch size and one for frames. I've already tried many things, but haven't found a way to get this into TfLight. So is this at all possible and if so: how? Do we need to pass specific arguments to the TfLite model generation? This would be by far the easiest solution since you could then directly compile your trained model instead of having to reconstruct it in the inference model code (this is particularly painful if your model has branches and merges).</p>\n<p>As an alternative, I also tried adding a size-1 first dimension inside the inference model (since batch size would always be 1 at inference time), but never managed to get this running: whatever I try, I get errors either at compile time or when trying to run it for inference. </p>",
      "rawMarkdown": "Dear experts,\n\nI'm still confused about one thing in TfLite. Tensorflow models always have a 'hidden' first input dimension corresponding to batch size, with 'None' size to account for variable batch size. In the code posted by Lonnie, for the inference model, the batch dimension is 'abused' as a time dimension. When you train a variable time step time series model in Tensorflow, you typically have two None dimensions: one for batch size and one for frames. I've already tried many things, but haven't found a way to get this into TfLight. So is this at all possible and if so: how? Do we need to pass specific arguments to the TfLite model generation? This would be by far the easiest solution since you could then directly compile your trained model instead of having to reconstruct it in the inference model code (this is particularly painful if your model has branches and merges).\n\nAs an alternative, I also tried adding a size-1 first dimension inside the inference model (since batch size would always be 1 at inference time), but never managed to get this running: whatever I try, I get errors either at compile time or when trying to run it for inference. ",
      "replies": [
        {
          "id": 2169178,
          "postDate": "2023-03-04T20:26:20.500Z",
          "content": "<p>I don't have any direct evidence or proof, but my assumption is for inference we will get a single test entry at a time (frames, 543, 3). Never (batch, frames, 543, 3). That would break the contract we were told to expect in the Evaluation instructions. </p>\n<p>So your inference model can expect None, 543, 3 and can choose to do whatever tricks desired with the variable dimension. Averaging, padding, and \"resize\"-ing: personally I'm doing all three individually then concatenating together</p>",
          "rawMarkdown": "I don't have any direct evidence or proof, but my assumption is for inference we will get a single test entry at a time (frames, 543, 3). Never (batch, frames, 543, 3). That would break the contract we were told to expect in the Evaluation instructions. \n\nSo your inference model can expect None, 543, 3 and can choose to do whatever tricks desired with the variable dimension. Averaging, padding, and \"resize\"-ing: personally I'm doing all three individually then concatenating together"
        },
        {
          "id": 2170165,
          "postDate": "2023-03-05T18:20:03.253Z",
          "content": "<p>Adding a 1-sized batch dimension works for me. For a working example you can refer to <a href=\"https://www.kaggle.com/code/aapokossi/submission-for-variable-length-time-series-model\" target=\"_blank\">my notebook</a>.</p>",
          "rawMarkdown": "Adding a 1-sized batch dimension works for me. For a working example you can refer to [my notebook](https://www.kaggle.com/code/aapokossi/submission-for-variable-length-time-series-model).",
          "votes": 2,
          "replies": [
            {
              "id": 2170208,
              "postDate": "2023-03-05T18:54:11.837Z",
              "content": "<p>Wow, thanks!</p>",
              "rawMarkdown": "Wow, thanks!\n"
            }
          ]
        }
      ]
    },
    {
      "id": 2168628,
      "postDate": "2023-03-04T11:39:40.887Z",
      "content": "<p>Hello, I've been having difficulties submitting my work and I think I finally understood why : I was using the tf.atan function in my work, which isn't handled by TFLite. <br>\nI tried some workaround (tf.asin/tf.angle for instance) but it seems every one of them is failing when converting the model to TFLite. Do you happen to know of a native tensorflow, TFLite-supported, operation to compute angles ?</p>",
      "rawMarkdown": "Hello, I've been having difficulties submitting my work and I think I finally understood why : I was using the tf.atan function in my work, which isn't handled by TFLite. \nI tried some workaround (tf.asin/tf.angle for instance) but it seems every one of them is failing when converting the model to TFLite. Do you happen to know of a native tensorflow, TFLite-supported, operation to compute angles ?",
      "replies": [
        {
          "id": 2169702,
          "postDate": "2023-03-05T10:59:24.043Z",
          "content": "<p>Inner products of normalised verctors give you cosines … </p>",
          "rawMarkdown": "Inner products of normalised verctors give you cosines ... ",
          "replies": [
            {
              "id": 2169710,
              "postDate": "2023-03-05T11:07:52.253Z",
              "content": "<p>Yes, and after one got the cosine, one need to use an arc-cos function to actually get the angle, or am I wrong ?</p>",
              "rawMarkdown": "Yes, and after one got the cosine, one need to use an arc-cos function to actually get the angle, or am I wrong ?"
            },
            {
              "id": 2170214,
              "postDate": "2023-03-05T18:54:38.207Z",
              "content": "<p>Yes, but maybe cosine is enough?</p>",
              "rawMarkdown": "Yes, but maybe cosine is enough?\n",
              "votes": 1
            }
          ]
        }
      ]
    },
    {
      "id": 2168166,
      "postDate": "2023-03-04T00:14:39.820Z",
      "content": "<p>Any suggestions how to do a basic np.nanmean on a given axis in TF Lite?</p>\n<p>I eventually found that this code below doesn't work because ragged tensor ops aren't supported in conversion. I was using it to preserve dimensions, which is obviously necessary (for only a split second) for the 'reduce_mean' to work correctly.</p>\n<pre><code>        face_center = tf.reduce_mean(tf.ragged.boolean_mask(inputs[:, :, :], tf.math.is_finite(inputs[:, :, :])), axis=, keepdims=)\n        face_center = face_center.to_tensor(default_value=(), shape=[, , ])\n</code></pre>",
      "rawMarkdown": "Any suggestions how to do a basic np.nanmean on a given axis in TF Lite?\n\nI eventually found that this code below doesn't work because ragged tensor ops aren't supported in conversion. I was using it to preserve dimensions, which is obviously necessary (for only a split second) for the 'reduce_mean' to work correctly.\n\n```python\n        face_center = tf.reduce_mean(tf.ragged.boolean_mask(inputs[:, 0:468, :], tf.math.is_finite(inputs[:, 0:468, :])), axis=1, keepdims=True)\n        face_center = face_center.to_tensor(default_value=float('nan'), shape=[None, 1, 3])\n```",
      "replies": [
        {
          "id": 2168239,
          "postDate": "2023-03-04T03:33:07.380Z",
          "content": "<p>Got it working. (h/t <a href=\"https://www.kaggle.com/dschettler8845\" target=\"_blank\">@dschettler8845</a> )</p>\n<p>The wrapper functions I'm using:</p>\n<pre><code> ():\n     tf.reduce_sum(tf.where(tf.math.is_nan(x), tf.zeros_like(x), x), axis=axis) / tf.reduce_sum(tf.where(tf.math.is_nan(x), tf.zeros_like(x), tf.ones_like(x)), axis=axis)\n\n ():\n    d = x - tf_nan_mean(x, axis=axis)\n     tf.math.sqrt(tf_nan_mean(d * d, axis=axis))\n</code></pre>",
          "rawMarkdown": "Got it working. (h/t @dschettler8845 )\n\nThe wrapper functions I'm using:\n```python\ndef tf_nan_mean(x, axis=0):\n    return tf.reduce_sum(tf.where(tf.math.is_nan(x), tf.zeros_like(x), x), axis=axis) / tf.reduce_sum(tf.where(tf.math.is_nan(x), tf.zeros_like(x), tf.ones_like(x)), axis=axis)\n\ndef tf_nan_std(x, axis=0):\n    d = x - tf_nan_mean(x, axis=axis)\n    return tf.math.sqrt(tf_nan_mean(d * d, axis=axis))\n```",
          "votes": 1,
          "replies": [
            {
              "id": 2168785,
              "postDate": "2023-03-04T14:10:28.880Z",
              "content": "<p>Nice! Glad it is working.</p>\n<p>One suggestion. You may wish to use <strong><code>tf.math.divide_no_nan</code></strong> as opposed to the <code>/</code> operator. It'll handle the case of all zeros or (non-finite) in the denominator. That being said I'm not sure if it's supported in tflite… </p>\n<pre><code> ():\n     tf.math.divide_no_nan(tf.reduce_sum(tf.where(tf.math.is_nan(x), tf.zeros_like(x), x), axis=axis),\n                                 tf.reduce_sum(tf.where(tf.math.is_nan(x), tf.zeros_like(x), tf.ones_like(x)), axis=axis))\n\n ():\n    d = x - tf_nan_mean(x, axis=axis)\n     tf.math.sqrt(tf_nan_mean(d * d, axis=axis))\n</code></pre>",
              "rawMarkdown": "Nice! Glad it is working.\n\nOne suggestion. You may wish to use **`tf.math.divide_no_nan`** as opposed to the `/` operator. It'll handle the case of all zeros or (non-finite) in the denominator. That being said I'm not sure if it's supported in tflite... \n\n```Python\ndef tf_nan_mean(x, axis=0):\n    return tf.math.divide_no_nan(tf.reduce_sum(tf.where(tf.math.is_nan(x), tf.zeros_like(x), x), axis=axis),\n                                 tf.reduce_sum(tf.where(tf.math.is_nan(x), tf.zeros_like(x), tf.ones_like(x)), axis=axis))\n\ndef tf_nan_std(x, axis=0):\n    d = x - tf_nan_mean(x, axis=axis)\n    return tf.math.sqrt(tf_nan_mean(d * d, axis=axis))\n```"
            }
          ]
        }
      ]
    },
    {
      "id": 2168049,
      "postDate": "2023-03-03T20:31:13.543Z",
      "content": "<p>I assume \"SELECT_TF_OPS\" is NOT supported and will fail in scoring?</p>\n<pre><code>keras_model_converter.target_spec.supported_ops = [\n  tf.lite.OpsSet.TFLITE_BUILTINS, \n  tf.lite.OpsSet.SELECT_TF_OPS \n]\n</code></pre>",
      "rawMarkdown": "I assume \"SELECT_TF_OPS\" is NOT supported and will fail in scoring?\n\n```python\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```"
    },
    {
      "id": 2166680,
      "postDate": "2023-03-02T23:25:35.780Z",
      "content": "<p>I'm having a lot of trouble with the preprocessing.</p>\n<p>My current problem can, hopefully, be simplified as very similar to wanting to resize a variable shape image to a fixed size:<br>\nSomething like tf.keras.layers.Resizing</p>\n<p>Examples that will never work(?)<br>\nFrom <a href=\"https://www.kaggle.com/code/lonnieqin/isolated-sign-language-recognition-with-dnn\" target=\"_blank\">https://www.kaggle.com/code/lonnieqin/isolated-sign-language-recognition-with-dnn</a></p>\n<pre><code>    inputs = tf.keras.Input((, ), dtype=tf.float32, name=)\n    x = custom_preprocess(inputs)\n</code></pre>\n<p>This is symbolic, so won't work with my custom_preprocess function that has special logic based on the number of frames.<br>\nAlong those lines, is there some way that this code COULD work with tf.keras.layers.Resizing?</p>\n<p>-<br>\nFrom <a href=\"https://www.kaggle.com/code/dschettler8845/gislr-learn-eda-baseline/notebook\" target=\"_blank\">https://www.kaggle.com/code/dschettler8845/gislr-learn-eda-baseline/notebook</a><br>\n<code>@tf.function(input_signature=[tf.TensorSpec(shape=[None, 543, 3], dtype=tf.float32, name='inputs')])</code><br>\nI think this is similar to the other example? I doubt it can work with my custom function. No idea whether it's possible or how to convert it to use something like tf.keras.layers.Resizing.</p>\n<p>Is there some approach that should work? Taking a variable dimension and dynamically converting it to a fixed size dimension using custom logic seems like a very common type of problem.</p>",
      "rawMarkdown": "I'm having a lot of trouble with the preprocessing.\n\nMy current problem can, hopefully, be simplified as very similar to wanting to resize a variable shape image to a fixed size:\nSomething like tf.keras.layers.Resizing\n\nExamples that will never work(?)\nFrom https://www.kaggle.com/code/lonnieqin/isolated-sign-language-recognition-with-dnn\n```python\n    inputs = tf.keras.Input((543, 3), dtype=tf.float32, name=\"inputs\")\n    x = custom_preprocess(inputs)\n```\nThis is symbolic, so won't work with my custom_preprocess function that has special logic based on the number of frames.\nAlong those lines, is there some way that this code COULD work with tf.keras.layers.Resizing?\n\n-\nFrom https://www.kaggle.com/code/dschettler8845/gislr-learn-eda-baseline/notebook\n`    @tf.function(input_signature=[tf.TensorSpec(shape=[None, 543, 3], dtype=tf.float32, name='inputs')])`\nI think this is similar to the other example? I doubt it can work with my custom function. No idea whether it's possible or how to convert it to use something like tf.keras.layers.Resizing.\n\nIs there some approach that should work? Taking a variable dimension and dynamically converting it to a fixed size dimension using custom logic seems like a very common type of problem.",
      "replies": [
        {
          "id": 2167125,
          "postDate": "2023-03-03T09:22:33.413Z",
          "content": "<p>Try tf.image.resize, you can find some examples in <br>\n <a href=\"https://www.tensorflow.org/api_docs/python/tf/image/resize\" target=\"_blank\">https://www.tensorflow.org/api_docs/python/tf/image/resize</a></p>",
          "rawMarkdown": "Try tf.image.resize, you can find some examples in \n https://www.tensorflow.org/api_docs/python/tf/image/resize",
          "votes": 1,
          "replies": [
            {
              "id": 2167697,
              "postDate": "2023-03-03T16:57:54.103Z",
              "content": "<p>Yeah, that's a good starting point, at least.</p>\n<p>If that works, I guess I'll have to port the underlying resize code directly into my Notebook, and debug/derive what that code does to enable itself to work, and use the learnings to write my own custom logic.</p>\n<p>Or accept a pre-built resize algorithm and give up on writing my own logic.</p>",
              "rawMarkdown": "Yeah, that's a good starting point, at least.\n\nIf that works, I guess I'll have to port the underlying resize code directly into my Notebook, and debug/derive what that code does to enable itself to work, and use the learnings to write my own custom logic.\n\nOr accept a pre-built resize algorithm and give up on writing my own logic."
            },
            {
              "id": 2167721,
              "postDate": "2023-03-03T17:09:49.180Z",
              "content": "<p>At least it works!</p>\n<p>It's pretty terrible because it doesn't handle nan, and filling with 0s distorts the resized values… but at least it works.</p>",
              "rawMarkdown": "At least it works!\n\nIt's pretty terrible because it doesn't handle nan, and filling with 0s distorts the resized values... but at least it works."
            },
            {
              "id": 2168048,
              "postDate": "2023-03-03T20:30:02.710Z",
              "rawMarkdown": "",
              "isDeleted": true
            }
          ]
        }
      ]
    },
    {
      "id": 2164090,
      "postDate": "2023-03-01T09:47:41.210Z",
      "content": "<p>Hi, I am so excited to attend this competition. I have some questions about the concentration from pytorch model to TensorFlow mode.<br>\nI know we can use onnx to do it. We need to install onnx_tf, which requires internet access. However, as a rule, says, we could n use the internet in the notebook. So how do we use onnx_tf? Is there a way to install it without using the internet?<br>\n!pip install onnx_tf</p>",
      "rawMarkdown": "Hi, I am so excited to attend this competition. I have some questions about the concentration from pytorch model to TensorFlow mode.\nI know we can use onnx to do it. We need to install onnx_tf, which requires internet access. However, as a rule, says, we could n use the internet in the notebook. So how do we use onnx_tf? Is there a way to install it without using the internet?\n!pip install onnx_tf",
      "replies": [
        {
          "id": 2167549,
          "postDate": "2023-03-03T15:00:20.787Z",
          "content": "<ol>\n<li><p>I think(?) you can simply use the internet in notebook 1, up to an including creating the tflite model, then use the result in notebook 2 that has internet off and makes the final submission. </p></li>\n<li><p>There's a couple simple ways discussed here: <a href=\"https://www.kaggle.com/competitions/icecube-neutrinos-in-deep-ice/discussion/382898\" target=\"_blank\">https://www.kaggle.com/competitions/icecube-neutrinos-in-deep-ice/discussion/382898</a></p></li>\n</ol>",
          "rawMarkdown": "1. I think(?) you can simply use the internet in notebook 1, up to an including creating the tflite model, then use the result in notebook 2 that has internet off and makes the final submission. \n\n2. There's a couple simple ways discussed here: https://www.kaggle.com/competitions/icecube-neutrinos-in-deep-ice/discussion/382898\n"
        }
      ]
    },
    {
      "id": 2161974,
      "postDate": "2023-02-27T21:48:31.017Z",
      "content": "<p>My sign language processing research is fundamentally impossible to run with tflite - <br>\nI first transcribe the sign represented as a pose sequence to SignWriting (autoregressive translation model, not supported in tflite), then I perform classification on the result. <br>\nI will not be able to participate unless you at the very least allow <em>multiple</em> tflite files, and a python function to, given a model, perform the inference loop.</p>",
      "rawMarkdown": "My sign language processing research is fundamentally impossible to run with tflite - \nI first transcribe the sign represented as a pose sequence to SignWriting (autoregressive translation model, not supported in tflite), then I perform classification on the result. \nI will not be able to participate unless you at the very least allow *multiple* tflite files, and a python function to, given a model, perform the inference loop."
    },
    {
      "id": 2160341,
      "postDate": "2023-02-26T15:45:02.307Z",
      "content": "<p>How can I learn tensorflow in kaggle, Can someone guide me pls?</p>",
      "rawMarkdown": "How can I learn tensorflow in kaggle, Can someone guide me pls?",
      "replies": [
        {
          "id": 2162057,
          "postDate": "2023-02-28T00:44:49.040Z",
          "content": "<p>Hi Ranjan, take a look at this guide: <a href=\"https://www.kaggle.com/learn-guide/tensorflow\" target=\"_blank\">https://www.kaggle.com/learn-guide/tensorflow</a></p>",
          "rawMarkdown": "Hi Ranjan, take a look at this guide: https://www.kaggle.com/learn-guide/tensorflow"
        }
      ]
    },
    {
      "id": 2159921,
      "postDate": "2023-02-26T06:23:00.787Z",
      "content": "<p>Do you happen to have example notebook/script that can convert LightGBM/XGBoost -&gt; ONNX -&gt; TensorFlow -&gt; TensorFlow Lite? Looks technically feasible with this ONNX toolset.  <a href=\"https://github.com/onnx/onnxmltools\" target=\"_blank\">https://github.com/onnx/onnxmltools</a> </p>",
      "rawMarkdown": "Do you happen to have example notebook/script that can convert LightGBM/XGBoost -> ONNX -> TensorFlow -> TensorFlow Lite? Looks technically feasible with this ONNX toolset.  https://github.com/onnx/onnxmltools "
    },
    {
      "id": 2158650,
      "postDate": "2023-02-25T03:28:37.700Z",
      "content": "<p>What resources would you suggest for beginners to learn TF Lite, given some familiarity with Tensorflow ?</p>",
      "rawMarkdown": "What resources would you suggest for beginners to learn TF Lite, given some familiarity with Tensorflow ?",
      "replies": [
        {
          "id": 2158683,
          "postDate": "2023-02-25T04:21:30.087Z",
          "content": "<p>So it really depends on how you learn best and what your current experience level is with ML in general. A few places I'd start would be the <a href=\"https://www.tensorflow.org/lite\" target=\"_blank\">official documentation pages</a> and the <a href=\"https://www.youtube.com/@TensorFlow\" target=\"_blank\">YouTube channel</a> with a bit of searching for what you want to learn. Hopefully that helps at least get you started :)</p>",
          "rawMarkdown": "So it really depends on how you learn best and what your current experience level is with ML in general. A few places I'd start would be the [official documentation pages](https://www.tensorflow.org/lite) and the [YouTube channel](https://www.youtube.com/@TensorFlow) with a bit of searching for what you want to learn. Hopefully that helps at least get you started :)"
        }
      ]
    },
    {
      "id": 2157830,
      "postDate": "2023-02-24T11:12:49.203Z",
      "content": "<p>Can we have the dataset in any object detection format- TF or YOLO?</p>",
      "rawMarkdown": "Can we have the dataset in any object detection format- TF or YOLO?",
      "replies": [
        {
          "id": 2158531,
          "postDate": "2023-02-24T23:38:36.483Z",
          "content": "<p>We are only going to provide the data in the existing format.</p>",
          "rawMarkdown": "We are only going to provide the data in the existing format."
        }
      ]
    },
    {
      "id": 2157564,
      "postDate": "2023-02-24T05:55:17.933Z",
      "content": "<p>The competition requires the use TensorFlow. What if the model I come up with is fundamentally different from commonly used machine learning models today? (Specifically, fundamentally different from a neural network.)</p>",
      "rawMarkdown": "The competition requires the use TensorFlow. What if the model I come up with is fundamentally different from commonly used machine learning models today? (Specifically, fundamentally different from a neural network.)",
      "replies": [
        {
          "id": 2158166,
          "postDate": "2023-02-24T17:05:15.180Z",
          "content": "<p>You're welcome to submit anything you can make work with TensorFlow Lite.</p>",
          "rawMarkdown": "You're welcome to submit anything you can make work with TensorFlow Lite.",
          "replies": [
            {
              "id": 2158262,
              "postDate": "2023-02-24T18:13:35.500Z",
              "content": "<p>Can TensorFlow Lite work with a non-neural network model?  I'm happy to try getting things work in TensorFlow but every doc I look, it seems that TensorFlow is only for neural networks.  </p>",
              "rawMarkdown": "Can TensorFlow Lite work with a non-neural network model?  I'm happy to try getting things work in TensorFlow but every doc I look, it seems that TensorFlow is only for neural networks.  "
            },
            {
              "id": 2158604,
              "postDate": "2023-02-25T02:18:19.607Z",
              "rawMarkdown": "",
              "isDeleted": true
            },
            {
              "id": 2158605,
              "postDate": "2023-02-25T02:19:45.350Z",
              "content": "<p>You may find this post on running k-nearest neighbors with Tensorflow Lite helpful: <a href=\"https://ata-tech.medium.com/running-k-nearest-neighbors-on-tensorflow-lite-e3affba4d706\" target=\"_blank\">https://ata-tech.medium.com/running-k-nearest-neighbors-on-tensorflow-lite-e3affba4d706</a></p>",
              "rawMarkdown": "You may find this post on running k-nearest neighbors with Tensorflow Lite helpful: https://ata-tech.medium.com/running-k-nearest-neighbors-on-tensorflow-lite-e3affba4d706"
            }
          ]
        }
      ]
    },
    {
      "id": 2220628,
      "postDate": "2023-04-13T14:53:09.157Z",
      "rawMarkdown": "",
      "isDeleted": true
    },
    {
      "id": 2217997,
      "postDate": "2023-04-11T10:27:15.153Z",
      "rawMarkdown": "",
      "votes": -2,
      "isDeleted": true
    },
    {
      "id": 2179008,
      "postDate": "2023-03-12T20:22:37.343Z",
      "rawMarkdown": "",
      "isDeleted": true
    },
    {
      "id": 2167533,
      "postDate": "2023-03-03T14:50:48.947Z",
      "rawMarkdown": "",
      "isDeleted": true
    },
    {
      "id": 2161923,
      "postDate": "2023-02-27T20:37:05.853Z",
      "rawMarkdown": "",
      "isDeleted": true
    },
    {
      "id": 2160830,
      "postDate": "2023-02-27T02:52:07.107Z",
      "rawMarkdown": "",
      "votes": 3,
      "isDeleted": true
    },
    {
      "id": 2157901,
      "postDate": "2023-02-24T12:45:06.923Z",
      "rawMarkdown": "",
      "votes": 1,
      "isDeleted": true,
      "replies": [
        {
          "id": 2158279,
          "postDate": "2023-02-24T18:36:21.057Z",
          "rawMarkdown": "",
          "isDeleted": true
        }
      ]
    }
  ],
  "comments": [
    {
      "id": 2160198,
      "author_name": "Andrew",
      "author_url": "",
      "post_date": "2023-02-26T13:13:00.060000",
      "content": "<blockquote>\n  <p>Your model must also require less than 40 MB in memory</p>\n</blockquote>\n<p>How do we calculate the in-memory size of a model?  What specific checks does the submission evaluation run - so that we can pre-check our models and avoid wasted submissions.</p>",
      "votes": 11,
      "replies": [
        {
          "id": 2169859,
          "author_name": "Darien Schettler",
          "author_url": "",
          "post_date": "2023-03-05T13:58:28.253000",
          "content": "<p>This is my rule of thumb:</p>\n<p>Calculate the memory usage of the model by multiplying the number of parameters by the number of bytes required to store each parameter. For example, if your model has 10 million parameters and each parameter requires 4 bytes, the total memory usage would be 40 MB.</p>\n<p>Note that the actual memory usage of the model may differ from this calculated value due to various factors such as the use of GPU memory, data type of the parameters, and any compression or optimization techniques used.</p>\n<p>I’d also note that it appears more permissive than the above because I’ve definitely submitted models that are 10M+ that have succeeded.</p>\n<p>Hope that helps!</p>",
          "votes": 6,
          "replies": []
        }
      ]
    },
    {
      "id": 2162315,
      "author_name": "Lakshmi Narayana Podagatlapalli",
      "author_url": "",
      "post_date": "2023-02-28T05:59:02.477000",
      "content": "<p>I recently started learning Tensorflow and wish to confirm that my understanding is correct:</p>\n<ul>\n<li>TFlite is not for building models but for using them in practice.</li>\n<li>So they can be built in Tensorflow as usual.</li>\n<li>But tensorflow models by themselves are not tflite compatible.</li>\n<li>So we use tf.lite.TFLiteConverter to make it tflite compatible.(source: <a href=\"https://www.tensorflow.org/lite/guide/inference\" target=\"_blank\">https://www.tensorflow.org/lite/guide/inference</a>)<br>\nPlease let me know if this is correct or correct where required.<br>\nAlso, please suggest any other methods we can use.</li>\n</ul>",
      "votes": 5,
      "replies": []
    },
    {
      "id": 2170436,
      "author_name": "Conweezy",
      "author_url": "",
      "post_date": "2023-03-06T02:06:44.333000",
      "content": "<p>Is there a list somewhere that tells us what layers are compatible with TFlite? Since we are dealing with sequences of data, I tried using LSTM and GRU, but both don't seem to be compatible with TFlite. It technically runs, but when I convert to TFlite I get this warning: </p>\n<p>WARNING:absl:Found untraced functions such as _update_step_xla, lstm_cell_1_layer_call_fn, lstm_cell_1_layer_call_and_return_conditional_losses, lstm_cell_2_layer_call_fn, lstm_cell_2_layer_call_and_return_conditional_losses while saving (showing 5 of 5). These functions will not be directly callable after loading.</p>\n<p>The accuracy when using the TFlite model is much lower than when using regular TF model. Assuming it's because GRU and LSTM are not compatible with TFlite?</p>",
      "votes": 3,
      "replies": []
    },
    {
      "id": 2157188,
      "author_name": "Narendra Kumar Reddy36",
      "author_url": "",
      "post_date": "2023-02-23T19:05:00.070000",
      "content": "<p>As, I am at starting state of learning, I don't known weather it will complete or not. But for me this project seams to be a great one and I will try to learn at least something while working on this.</p>\n<p>thank you for this amazing project</p>",
      "votes": 3,
      "replies": []
    },
    {
      "id": 2158548,
      "author_name": "Chen Lin",
      "author_url": "",
      "post_date": "2023-02-25T00:32:07.537000",
      "content": "<blockquote>\n  <p>Your model must also require less than 40 MB in memory and perform inference with less than 100 milliseconds of latency per video. </p>\n</blockquote>\n<p>How should we calculate the inference latency for each video on the validation set? Should we calculate the time between reading data from disk and getting inference results? Because I assume we can't get all the data to be read into RAM or graphics memory</p>",
      "votes": 4,
      "replies": [
        {
          "id": 2160593,
          "author_name": "Dhananjaya Swain",
          "author_url": "",
          "post_date": "2023-02-26T19:46:55.430000",
          "content": "<p>It talks about the storage and runtime your trained model takes for a given input. Hope this clarifies your query!</p>",
          "votes": -3,
          "replies": []
        },
        {
          "id": 2169858,
          "author_name": "Darien Schettler",
          "author_url": "",
          "post_date": "2023-03-05T13:56:41.720000",
          "content": "<p>For inference timing you can time the inference code that they provide in a loop and time it. If your using a variable time series, I would do the 75% upper quantile of number of frames to mimic a slightly longer than average runtime. That should give you a bit of buffer.</p>\n<p>For size, calculate the memory usage of the model by multiplying the number of parameters by the number of bytes required to store each parameter. For example, if your model has 10 million parameters and each parameter requires 4 bytes, the total memory usage would be 40 MB.<br>\nNote that the actual memory usage of the model may differ from this calculated value due to various factors such as the use of GPU memory, data type of the parameters, and any compression or optimization techniques used.</p>\n<p>Hope that helps!</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 2157243,
      "author_name": "DrHB",
      "author_url": "",
      "post_date": "2023-02-23T20:35:48.100000",
      "content": "<p>what is the best tools/way to convert Pytorch model to tflite?</p>",
      "votes": 1,
      "replies": [
        {
          "id": 2157381,
          "author_name": "Mark Sherwood",
          "author_url": "",
          "post_date": "2023-02-24T01:03:09.540000",
          "content": "<p>We see many PyTorch developers who deploy via TensorFlow Lite use a path of PyTorch -&gt; ONNX -&gt; TensorFlow -&gt; TensorFlow Lite. Two community posts demonstrating this path are <a href=\"https://medium.com/geekculture/converting-yolo-v7-to-tensorflow-lite-for-mobile-deployment-ebc1103e8d1e\" target=\"_blank\">https://medium.com/geekculture/converting-yolo-v7-to-tensorflow-lite-for-mobile-deployment-ebc1103e8d1e</a> and <a href=\"https://github.com/sayakpaul/Adventures-in-TensorFlow-Lite/blob/master/TUNIT_Conversion_to_TF_Lite.ipynb\" target=\"_blank\">https://github.com/sayakpaul/Adventures-in-TensorFlow-Lite/blob/master/TUNIT_Conversion_to_TF_Lite.ipynb</a></p>",
          "votes": 9,
          "replies": []
        }
      ]
    },
    {
      "id": 2157385,
      "author_name": "ONODERA",
      "author_url": "",
      "post_date": "2023-02-24T01:04:14.190000",
      "content": "<blockquote>\n  <p>This competition requires submissions to be made in the form of TensorFlow Lite models. You are welcome to train your model using the framework of your choice as long as you convert the model checkpoint into the tflite format prior to submission. Please see the evaluation page for details.</p>\n</blockquote>\n<p>What if we did not use TensorFlow Lite models? We will be removed from Leaderboard?</p>",
      "votes": 0,
      "replies": [
        {
          "id": 2157387,
          "author_name": "Sohier Dane",
          "author_url": "",
          "post_date": "2023-02-24T01:07:14.163000",
          "content": "<p>Your submission will fail without a TF Lite model.</p>",
          "votes": 3,
          "replies": [
            {
              "id": 2216731,
              "author_name": "Jh Probas",
              "author_url": "",
              "post_date": "2023-04-10T09:52:33.367000",
              "content": "<p>Cool, thank you!</p>",
              "votes": 0,
              "replies": []
            }
          ]
        }
      ]
    },
    {
      "id": 2217824,
      "author_name": "WeiweiDuan",
      "author_url": "",
      "post_date": "2023-04-11T07:39:54.293000",
      "content": "<p>Thanks for you amazing code, it helps me a lot</p>",
      "votes": -2,
      "replies": []
    },
    {
      "id": 2232348,
      "author_name": "Haoyu Jiang",
      "author_url": "",
      "post_date": "2023-04-24T08:31:08.840000",
      "content": "<p>very good.this code help me a lot</p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 2226249,
      "author_name": "Stanislav Cherkasov",
      "author_url": "",
      "post_date": "2023-04-18T19:17:47.850000",
      "content": "<p>Hello<br>\nI receive error message:</p>\n<pre><code>error:  op  neither a custom op nor a flex op\nerror: failed  converting: : \nSome ops are  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\nDetails:\n    tf.Conv2D(tensor&lt;*xf32&gt;, tensor&lt;2x2x3x32xf32&gt;) -&gt; (tensor&lt;?x?x?x32xf32&gt;) : {data_format = , device = , dilations = [, , , ], explicit_paddings = [], padding = , strides = [, , , ], use_cudnn_on_gpu = true}\n</code></pre>\n<p>Why it's happens? According <a href=\"https://www.tensorflow.org/mlir/tfl_ops?hl=ru#tflconv_2d_mlirtflconv2dop\" target=\"_blank\">https://www.tensorflow.org/mlir/tfl_ops?hl=ru#tflconv_2d_mlirtflconv2dop</a> conv_2d layers are supported</p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 2218660,
      "author_name": "Andrew",
      "author_url": "",
      "post_date": "2023-04-11T22:27:55.273000",
      "content": "<p>TFlite models seem to grow in size very quickly for just a few more features in the data. Are there standard ways to shrink the size? </p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 2198405,
      "author_name": "deoxy",
      "author_url": "",
      "post_date": "2023-03-27T01:22:30.350000",
      "content": "<p>Several people have already mentioned the topic of \"TensorFlow operators\".<br>\nAs far as I can confirm, the current submission environment does not support TensorFlow operators, I would expect.<br>\nI checked on the Kaggle notebook and it is possible to support TensorFlow operators in tflite_runtime by importing tensorflow as follows</p>\n<pre><code>@@ -1,3 +1,4 @@\n+import tensorflow\n import tflite_runtime.interpreter as tflite\n interpreter = tflite.Interpreter(model_path)\n</code></pre>\n<p>It seems that the introduction of TensorFlow operators is not impractical for device implementations.<br>\n<a href=\"https://www.tensorflow.org/lite/guide/ops_select\" target=\"_blank\">https://www.tensorflow.org/lite/guide/ops_select</a></p>\n<p>Is there any possibility of this modification to the submission environment?</p>\n<p>I would be very happy if TensorFlow operators were introduced, as I think it would make it easier to implement more complex models and increase our chances of achieving greater results.</p>\n<p>I welcome any comments on implementation issues on the device, concerns about competitiveness, etc.</p>",
      "votes": 0,
      "replies": [
        {
          "id": 2199328,
          "author_name": "Sohier Dane",
          "author_url": "",
          "post_date": "2023-03-27T16:27:59.200000",
          "content": "<p>We're deliberately excluding TensorFlow operators as the goal of the competition is to generate models that could potentially run on cell phones.</p>",
          "votes": 1,
          "replies": []
        }
      ]
    },
    {
      "id": 2189855,
      "author_name": "Mykola",
      "author_url": "",
      "post_date": "2023-03-20T20:52:02.770000",
      "content": "<p>Hello, guys. I faced an issue with tf.data pipeline working in graph mode. I need to edit the tensor somehow, but I cannot do so. I understand that tf.Tensor is immutable and supposed to work in a functional style. So, I am creating tf.Variable from it and that works well in eager execution mode. But tf.data pipeline uses graph mode and makes tf.Variable creation in such a way impossible. <br>\nHere is a minimalistic code, which reproduce my issue:</p>\n<blockquote>\n  <p>import tensorflow as tf</p>\n  <p>x = tf.constant([1,2,3.0])<br>\n  ds = tf.data.Dataset.from_tensors(x)</p>\n  <p>def test(x):<br>\n       with tf.init_scope():<br>\n       v = tf.Variable(x)</p>\n  <p>ds_x = ds.map(test)<br>\n  next(iter(ds_x))</p>\n</blockquote>\n<p>Here is an error I get</p>\n<p>`<br>\nValueError: in user code:</p>\n<pre><code>File \"/tmp/ipykernel_3517/140449158.py\", line 6, in test  *\n    v = tf.Variable(x)\n\nValueError: Argument `initial_value` (Tensor(\"args_0:0\", shape=(3,), dtype=float32)) could not be lifted out of a `tf.function`. (Tried to create variable with name='None'). To avoid this error, when constructing `tf.Variable`s inside of `tf.function` you can create the `initial_value` tensor in a `tf.init_scope` or pass a callable `initial_value` (e.g., `tf.Variable(lambda : tf.truncated_normal([10, 40]))`). Please file a feature request if this restriction inconveniences you.\n</code></pre>\n<p>`</p>\n<p>Best to my understanding, I cannot create a tf.Variable which depends on input tensor <code>x</code> because of static execution graph. But how do I change a part of input tensor <code>x</code>, where the decision of that part is depends on <code>x</code> content?</p>\n<p>Looking forward to your advice. Thank you in advance</p>",
      "votes": 0,
      "replies": [
        {
          "id": 2190236,
          "author_name": "Paul Ruiz",
          "author_url": "",
          "post_date": "2023-03-21T06:04:22.103000",
          "content": "<p>Hi Mykola,</p>\n<p>This is the code snippet I was sent for your issue:</p>\n<pre><code>import tensorflow as tf\n\nx = tf.constant([1,2,3,4,5,6])\nds = tf.data.Dataset.from_tensor_slices(x)\n\n@tf.function\ndef test(x):\n  if x &gt; 2:\n    return x**2\n  else:\n    return x\n\nds_x = ds.map(test)\n\nfor x in iter(ds_x):\n  print(x)\n</code></pre>\n<p>You can also find a lot of examples for tf.data here:  <a href=\"https://www.tensorflow.org/guide/data\" target=\"_blank\">https://www.tensorflow.org/guide/data</a></p>",
          "votes": 1,
          "replies": [
            {
              "id": 2190448,
              "author_name": "Mykola",
              "author_url": "",
              "post_date": "2023-03-21T08:40:22.010000",
              "content": "<p>I am not sure, whether this solves my problem, but further investigation gives me the following intuition and almost the solution (I am still in progress now). I would like to ask you whether my thoughts are correct or if am I wrong in so something. </p>\n<p>The goal is to calculate the mean of the input vector by segments. The actual segments depend on the content of the input vector.</p>\n<pre><code> ():\n    ...\n     segments \n</code></pre>\n<p>And now I am going to iterate over each segments and calculate mean</p>\n<pre><code> ():\n    segments = get_segments(x)\n    mean_list = []\n     i  segments: \n        mean_list.append(tf.math.reduce_mean(x[i[]:i[]))  \n\n    means = tf.stack(mean_list)  \n</code></pre>\n<p>This works pretty well in eager mode, but fails if I decorate it with <code>@tf.function</code>. That makes sense. Creating a mutable list is a violation of functional programming, thus we could not build a static computational graph. In fact, a list works well, if I create it with a  predefined length (like, <code>mean_list = [tf.constant(2), tf.math.reduce_mean(x[a:b]), ...]</code>). I guess TensorFlow graph compiler is smart enough to understand that list in that case is not going to be mutable ever.</p>\n<p>Regarding the task of calculating mean over segments currently, I found a possible solution with <code>tf.map_fn</code>. I discover a way to pass multiple arguments to <code>fn</code> using <code>tf.map_fn</code> (via tuples) - vector <code>x</code> and segment <code>i</code> in my case. This way enforces me to have the same shape over the first axis. So, I need to tile an <code>x</code> vector <code>N</code> times, in order to have the same length first axis - <code>[N, None]</code> for <code>x</code> and <code>[N, 2]</code> for segments. Hope, that would resolve my current issue.</p>\n<p>Taking the opportunity, I would like to ask you the following questions:</p>\n<ul>\n<li><p>Am I right, that all code under <code>tf.function</code> should be purely functional?</p></li>\n<li><p>Does my solution with <code>tf.map_fn</code> the best one for the task described above?</p></li>\n<li><p>Doesn't the <code>tf.data</code> pipeline support eager execution mode?</p>\n<p>Sorry, I some of the questions are trivial, but I spent a loot of time starting from the first release of TF2.0 on this. Thank you in advance!</p></li>\n</ul>",
              "votes": 0,
              "replies": []
            },
            {
              "id": 2190528,
              "author_name": "Mykola",
              "author_url": "",
              "post_date": "2023-03-21T10:03:23.133000",
              "content": "<p>The solution with <code>tf.map_fn</code> works, until <code>fn</code> returns tensors of different shapes. I want to apply the following function</p>\n<pre><code> ():\n    x = arg[]\n    _ = arg[]\n    a = r[]\n    b = r[]\n     x[a:b]*x[]  \n\n ():\n    segments = get_segments(x)\n    a = tf.tile(x, [(segments)])  \n    a = tf.reshape(a, [(segments), -])\n    c = tf.map_fn(take_it, (a,segments), fn_output_signature=tf.int64)\n\n    means = tf.stack(mean_list)  \n</code></pre>\n<p>Let say <code>x</code> is a tensor [0,1,2,3,4,5,6,7,8,9] and <code>get_segments(x)</code> returns the following</p>\n<pre><code>[[0, 3],\n [3, 7],\n [7, 10]]\n</code></pre>\n<p>I expect to get <code>[0,0,   4,6,8,10,   49,63]</code> as a result, but it is impossible since <code>take_it</code> returns tensors of different shapes. Now I get the following error:</p>\n<pre><code>2023-03-21 09:52:22.638552: W tensorflow/core/framework/op_kernel.cc:1830] OP_REQUIRES failed at list_kernels.h:206 : INVALID_ARGUMENT: PartialTensorShape: Incompatible shapes during merge: [2] vs. [4]\n</code></pre>\n<p>Could anyone give me an idea of how to solve my problem with <code>@tf.function</code> approach?</p>",
              "votes": 0,
              "replies": []
            },
            {
              "id": 2191285,
              "author_name": "Mykola",
              "author_url": "",
              "post_date": "2023-03-21T21:02:04.733000",
              "content": "<p>It was a little bit tricky, but <code>tf.RadgedTensor</code> helped with stacking tensors of different shapes, produced by <code>tf.map_fn</code>. It works, but unfortunately, it is very slow, since I need to process each vector individually, in a 3D tensor of shape <code>[None, 543, 3]</code>. Since the example above deals only with vectors, I've tried to exploit <code>tf.map_fn</code> again, in order to map my <code>mean_by_segments</code> per frame axis and then per coordinate axis (yes, one <code>tf.map_fn</code> call another <code>tf.map_fn</code>. Now, it works as expected in autograph mode, but it is dramatically slow. For instance, processing one (sic!) sample takes from 200ms to 2s+ (depending on hardware). Having that, it is impossible ven to train a model using such preprocessing (even not talking about submission). <br>\nCould you provide any though on this? Thank you in advance.</p>",
              "votes": 0,
              "replies": []
            }
          ]
        }
      ]
    },
    {
      "id": 2185203,
      "author_name": "Juanu",
      "author_url": "",
      "post_date": "2023-03-16T21:52:32.470000",
      "content": "<p>Hi there! Are there any constrains on the model submission for using <code>supported_ops</code>?<br>\n<strong>If so, it should be updated on the Submission Requirements</strong></p>\n<p>My submission size is les than 2mb and time is under 100ms but still gives an error.<br>\nThe only different thing I have from other submissions is that Im using this:</p>\n<pre><code>converter.target_spec.supported_ops = [\n    tf.lite.OpsSet.TFLITE_BUILTINS, \n    tf.lite.OpsSet.SELECT_TF_OPS \n]\n</code></pre>",
      "votes": 0,
      "replies": [
        {
          "id": 2195167,
          "author_name": "Aurora_blue",
          "author_url": "",
          "post_date": "2023-03-24T13:23:35.303000",
          "content": "<p>me too.<br>\nI faced the following error </p>\n<blockquote>\n  <p>ConverterError: /opt/conda/lib/python3.7/site-packages/tensorflow/python/util/deprecation.py:561:0: error: 'tf.TensorListReserve' op requires element_shape to be 1D tensor during TF Lite transformation pass<br>\n  :0: note: loc(fused[\"StatefulPartitionedCall:\", \"StatefulPartitionedCall\"]): called from<br>\n  /opt/conda/lib/python3.7/site-packages/tensorflow/python/util/deprecation.py:561:0: error: failed to legalize operation 'tf.TensorListReserve' that was explicitly marked illegal<br>\n  :0: note: loc(fused[\"StatefulPartitionedCall:\", \"StatefulPartitionedCall\"]): called from<br>\n  :0: error: Lowering tensor list ops is failed. Please consider using Select TF ops and disabling <code>_experimental_lower_tensor_list_ops</code> flag in the TFLite converter object. For example, converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS, tf.lite.OpsSet.SELECT_TF_OPS]\\n converter._experimental_lower_tensor_list_ops = False</p>\n</blockquote>\n<p>and tried to prevent this error to add following code.</p>\n<blockquote>\n  <p>keras_model_converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS, tf.lite.OpsSet.SELECT_TF_OPS]<br>\n  keras_model_converter._experimental_lower_tensor_list_ops = False</p>\n</blockquote>\n<p>It worked fine in kaggle notebook, but my submission failed.</p>\n<p>Unfortunately, the error don't show which part(operator) is the error, so I can't solve the problem now.</p>",
          "votes": 0,
          "replies": [
            {
              "id": 2195297,
              "author_name": "Aurora_blue",
              "author_url": "",
              "post_date": "2023-03-24T14:59:22.013000",
              "content": "<p>I've solve the problem by only using simple operator.<br>\nBy rewriting function with simple operator step by step and converting, I found the source of problem.</p>",
              "votes": 1,
              "replies": []
            }
          ]
        }
      ]
    },
    {
      "id": 2173968,
      "author_name": "Vikram Sandu",
      "author_url": "",
      "post_date": "2023-03-08T18:49:17.810000",
      "content": "<p>Hi all, I Hope you all are well. </p>\n<p>My TFLite model works fine with tflite-runtime version 2.11.0, However, it causes the notebook to crash if I use 2.9.1 instead.</p>\n<p>The notebook crashes while initializing the interpreter.</p>\n<p>interpreter = tflite.Interpreter(tflite_model_path)</p>\n<p>while loading the interpreter in tflite-runtime version 2.11.0, I get following warnings.</p>\n<ul>\n<li>INFO: Created TensorFlow Lite delegate for select TF ops.</li>\n<li>INFO: TfLiteFlexDelegate delegate: 30 nodes delegated out of 166 nodes with 2 partitions.</li>\n</ul>\n<p>Any help would be appreciated. Thanks</p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 2173799,
      "author_name": "steven hinojosa",
      "author_url": "",
      "post_date": "2023-03-08T16:42:54.613000",
      "content": "<p>How do I convert from Pytorch and use tensorflow without running into any bugs ?</p>",
      "votes": 0,
      "replies": [
        {
          "id": 2198675,
          "author_name": "Abhinav Naikawadi",
          "author_url": "",
          "post_date": "2023-03-27T08:26:25.443000",
          "content": "<p>I think this answer may be what you're looking for (unless you figured it out already): <a href=\"https://www.kaggle.com/competitions/asl-signs/discussion/390008#2157381\" target=\"_blank\">https://www.kaggle.com/competitions/asl-signs/discussion/390008#2157381</a> </p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 2171174,
      "author_name": "Wondering Alice",
      "author_url": "",
      "post_date": "2023-03-06T15:03:59.573000",
      "content": "<p>Hi all,</p>\n<p>I have two questions:</p>\n<p>(1) several preprocessed datasets are currently in use: if we generate our own preprocessed dataset (e.g. with a different batch size or different preprocessing), do we need to regenerate this from scratch in our final submission? Or do we only need to generate it once and is any dataset we generate automatically coupled to the notebook that generated it? I'm also not sure how (where) to save a self-generated dataset from one notebook in such a way we can use it from a different notebook.<br>\n(2) W.r.t. the time constraint for TfLite inference: does a submission fail when that is exceeded? And if not: how can we know whether our submission meets this constraint?</p>",
      "votes": 0,
      "replies": [
        {
          "id": 2172416,
          "author_name": "Vitaly Manoshin",
          "author_url": "",
          "post_date": "2023-03-07T14:10:27.773000",
          "content": "<blockquote>\n  <p>I'm also not sure how (where) to save a self-generated dataset from one notebook in such a way we can use it from a different notebook.</p>\n</blockquote>\n<p>As I understand, you can add your own dataset through upload button in top right of the notebook, and then you can add it in any notebook. You can also set visibility setting to private if you don't want others to see it. </p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 2169836,
      "author_name": "Hassan Abedi",
      "author_url": "",
      "post_date": "2023-03-05T13:28:47.837000",
      "content": "<p>Hi,</p>\n<p>I'm using TensorFlow to make my model for this competition. I tried enabling mixed precision (using float16 and float32 during the training) to reduce the training time, which works just fine. But when I try to convert my (final) trained model into TensorFlow Lite format for submission, the conversion takes too much time. (I waited about 5 hours before manually stopping  the conversion code; the code for conversion just stayed hung.) When I don't enable global mixed precision policy in TensorFlow, the conversion works fine, and it takes about a minute or so. </p>\n<p>This is my conversion code:</p>\n<pre><code>\nconverter = tf.lite.TFLiteConverter.from_keras_model(final_model)\n\ntflite_model = converter.convert()\nmodel_path = \n\n\n (model_path, )  f:\n    f.write(tflite_model)\n\n\n! submission. $model_path\n</code></pre>\n<p>Do you have any workarounds for this problem?</p>\n<p>BTW, I use TensorFlow 2.10 and 2.11 for training (and conversion).</p>",
      "votes": 0,
      "replies": [
        {
          "id": 2169854,
          "author_name": "Darien Schettler",
          "author_url": "",
          "post_date": "2023-03-05T13:52:12.870000",
          "content": "<p>Just a simple check, your using the right tflite runtime? I believe from the evaluation page it’s 2.9.1.</p>\n<p>An alternative to help with troubleshooting would be to try to make a simple, reproducible notebook.</p>\n<p>Ie </p>\n<ol>\n<li>New Notebook</li>\n<li>Initialize simple model with mixed precision (literally any model)</li>\n<li>Try to convert</li>\n</ol>\n<p>If it doesn’t fail, it’s probably something specific to comparability in one of the layers and potentially the interaction of that layer with mixed precision.</p>\n<p>You could also try training in full precision on your original notebook and converting as a simple check to make sure it has something to do with the mixed precision and not a particular op or layer </p>",
          "votes": 3,
          "replies": [
            {
              "id": 2170558,
              "author_name": "Hassan Abedi",
              "author_url": "",
              "post_date": "2023-03-06T05:16:42.490000",
              "content": "<p>Great suggestions. Thanks for the help.</p>",
              "votes": 0,
              "replies": []
            }
          ]
        }
      ]
    },
    {
      "id": 2169118,
      "author_name": "Wondering Alice",
      "author_url": "",
      "post_date": "2023-03-04T19:44:49.497000",
      "content": "<p>Dear experts,</p>\n<p>I'm still confused about one thing in TfLite. Tensorflow models always have a 'hidden' first input dimension corresponding to batch size, with 'None' size to account for variable batch size. In the code posted by Lonnie, for the inference model, the batch dimension is 'abused' as a time dimension. When you train a variable time step time series model in Tensorflow, you typically have two None dimensions: one for batch size and one for frames. I've already tried many things, but haven't found a way to get this into TfLight. So is this at all possible and if so: how? Do we need to pass specific arguments to the TfLite model generation? This would be by far the easiest solution since you could then directly compile your trained model instead of having to reconstruct it in the inference model code (this is particularly painful if your model has branches and merges).</p>\n<p>As an alternative, I also tried adding a size-1 first dimension inside the inference model (since batch size would always be 1 at inference time), but never managed to get this running: whatever I try, I get errors either at compile time or when trying to run it for inference. </p>",
      "votes": 0,
      "replies": [
        {
          "id": 2169178,
          "author_name": "Robert Hatch",
          "author_url": "",
          "post_date": "2023-03-04T20:26:20.500000",
          "content": "<p>I don't have any direct evidence or proof, but my assumption is for inference we will get a single test entry at a time (frames, 543, 3). Never (batch, frames, 543, 3). That would break the contract we were told to expect in the Evaluation instructions. </p>\n<p>So your inference model can expect None, 543, 3 and can choose to do whatever tricks desired with the variable dimension. Averaging, padding, and \"resize\"-ing: personally I'm doing all three individually then concatenating together</p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 2170165,
          "author_name": "aapo kossi",
          "author_url": "",
          "post_date": "2023-03-05T18:20:03.253000",
          "content": "<p>Adding a 1-sized batch dimension works for me. For a working example you can refer to <a href=\"https://www.kaggle.com/code/aapokossi/submission-for-variable-length-time-series-model\" target=\"_blank\">my notebook</a>.</p>",
          "votes": 2,
          "replies": [
            {
              "id": 2170208,
              "author_name": "Wondering Alice",
              "author_url": "",
              "post_date": "2023-03-05T18:54:11.837000",
              "content": "<p>Wow, thanks!</p>",
              "votes": 0,
              "replies": []
            }
          ]
        }
      ]
    },
    {
      "id": 2168628,
      "author_name": "Augustin Combes",
      "author_url": "",
      "post_date": "2023-03-04T11:39:40.887000",
      "content": "<p>Hello, I've been having difficulties submitting my work and I think I finally understood why : I was using the tf.atan function in my work, which isn't handled by TFLite. <br>\nI tried some workaround (tf.asin/tf.angle for instance) but it seems every one of them is failing when converting the model to TFLite. Do you happen to know of a native tensorflow, TFLite-supported, operation to compute angles ?</p>",
      "votes": 0,
      "replies": [
        {
          "id": 2169702,
          "author_name": "Wondering Alice",
          "author_url": "",
          "post_date": "2023-03-05T10:59:24.043000",
          "content": "<p>Inner products of normalised verctors give you cosines … </p>",
          "votes": 0,
          "replies": [
            {
              "id": 2169710,
              "author_name": "Augustin Combes",
              "author_url": "",
              "post_date": "2023-03-05T11:07:52.253000",
              "content": "<p>Yes, and after one got the cosine, one need to use an arc-cos function to actually get the angle, or am I wrong ?</p>",
              "votes": 0,
              "replies": []
            },
            {
              "id": 2170214,
              "author_name": "Wondering Alice",
              "author_url": "",
              "post_date": "2023-03-05T18:54:38.207000",
              "content": "<p>Yes, but maybe cosine is enough?</p>",
              "votes": 1,
              "replies": []
            }
          ]
        }
      ]
    },
    {
      "id": 2168166,
      "author_name": "Robert Hatch",
      "author_url": "",
      "post_date": "2023-03-04T00:14:39.820000",
      "content": "<p>Any suggestions how to do a basic np.nanmean on a given axis in TF Lite?</p>\n<p>I eventually found that this code below doesn't work because ragged tensor ops aren't supported in conversion. I was using it to preserve dimensions, which is obviously necessary (for only a split second) for the 'reduce_mean' to work correctly.</p>\n<pre><code>        face_center = tf.reduce_mean(tf.ragged.boolean_mask(inputs[:, :, :], tf.math.is_finite(inputs[:, :, :])), axis=, keepdims=)\n        face_center = face_center.to_tensor(default_value=(), shape=[, , ])\n</code></pre>",
      "votes": 0,
      "replies": [
        {
          "id": 2168239,
          "author_name": "Robert Hatch",
          "author_url": "",
          "post_date": "2023-03-04T03:33:07.380000",
          "content": "<p>Got it working. (h/t <a href=\"https://www.kaggle.com/dschettler8845\" target=\"_blank\">@dschettler8845</a> )</p>\n<p>The wrapper functions I'm using:</p>\n<pre><code> ():\n     tf.reduce_sum(tf.where(tf.math.is_nan(x), tf.zeros_like(x), x), axis=axis) / tf.reduce_sum(tf.where(tf.math.is_nan(x), tf.zeros_like(x), tf.ones_like(x)), axis=axis)\n\n ():\n    d = x - tf_nan_mean(x, axis=axis)\n     tf.math.sqrt(tf_nan_mean(d * d, axis=axis))\n</code></pre>",
          "votes": 1,
          "replies": [
            {
              "id": 2168785,
              "author_name": "Darien Schettler",
              "author_url": "",
              "post_date": "2023-03-04T14:10:28.880000",
              "content": "<p>Nice! Glad it is working.</p>\n<p>One suggestion. You may wish to use <strong><code>tf.math.divide_no_nan</code></strong> as opposed to the <code>/</code> operator. It'll handle the case of all zeros or (non-finite) in the denominator. That being said I'm not sure if it's supported in tflite… </p>\n<pre><code> ():\n     tf.math.divide_no_nan(tf.reduce_sum(tf.where(tf.math.is_nan(x), tf.zeros_like(x), x), axis=axis),\n                                 tf.reduce_sum(tf.where(tf.math.is_nan(x), tf.zeros_like(x), tf.ones_like(x)), axis=axis))\n\n ():\n    d = x - tf_nan_mean(x, axis=axis)\n     tf.math.sqrt(tf_nan_mean(d * d, axis=axis))\n</code></pre>",
              "votes": 0,
              "replies": []
            }
          ]
        }
      ]
    },
    {
      "id": 2168049,
      "author_name": "Robert Hatch",
      "author_url": "",
      "post_date": "2023-03-03T20:31:13.543000",
      "content": "<p>I assume \"SELECT_TF_OPS\" is NOT supported and will fail in scoring?</p>\n<pre><code>keras_model_converter.target_spec.supported_ops = [\n  tf.lite.OpsSet.TFLITE_BUILTINS, \n  tf.lite.OpsSet.SELECT_TF_OPS \n]\n</code></pre>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 2166680,
      "author_name": "Robert Hatch",
      "author_url": "",
      "post_date": "2023-03-02T23:25:35.780000",
      "content": "<p>I'm having a lot of trouble with the preprocessing.</p>\n<p>My current problem can, hopefully, be simplified as very similar to wanting to resize a variable shape image to a fixed size:<br>\nSomething like tf.keras.layers.Resizing</p>\n<p>Examples that will never work(?)<br>\nFrom <a href=\"https://www.kaggle.com/code/lonnieqin/isolated-sign-language-recognition-with-dnn\" target=\"_blank\">https://www.kaggle.com/code/lonnieqin/isolated-sign-language-recognition-with-dnn</a></p>\n<pre><code>    inputs = tf.keras.Input((, ), dtype=tf.float32, name=)\n    x = custom_preprocess(inputs)\n</code></pre>\n<p>This is symbolic, so won't work with my custom_preprocess function that has special logic based on the number of frames.<br>\nAlong those lines, is there some way that this code COULD work with tf.keras.layers.Resizing?</p>\n<p>-<br>\nFrom <a href=\"https://www.kaggle.com/code/dschettler8845/gislr-learn-eda-baseline/notebook\" target=\"_blank\">https://www.kaggle.com/code/dschettler8845/gislr-learn-eda-baseline/notebook</a><br>\n<code>@tf.function(input_signature=[tf.TensorSpec(shape=[None, 543, 3], dtype=tf.float32, name='inputs')])</code><br>\nI think this is similar to the other example? I doubt it can work with my custom function. No idea whether it's possible or how to convert it to use something like tf.keras.layers.Resizing.</p>\n<p>Is there some approach that should work? Taking a variable dimension and dynamically converting it to a fixed size dimension using custom logic seems like a very common type of problem.</p>",
      "votes": 0,
      "replies": [
        {
          "id": 2167125,
          "author_name": "Meikintom",
          "author_url": "",
          "post_date": "2023-03-03T09:22:33.413000",
          "content": "<p>Try tf.image.resize, you can find some examples in <br>\n <a href=\"https://www.tensorflow.org/api_docs/python/tf/image/resize\" target=\"_blank\">https://www.tensorflow.org/api_docs/python/tf/image/resize</a></p>",
          "votes": 1,
          "replies": [
            {
              "id": 2167697,
              "author_name": "Robert Hatch",
              "author_url": "",
              "post_date": "2023-03-03T16:57:54.103000",
              "content": "<p>Yeah, that's a good starting point, at least.</p>\n<p>If that works, I guess I'll have to port the underlying resize code directly into my Notebook, and debug/derive what that code does to enable itself to work, and use the learnings to write my own custom logic.</p>\n<p>Or accept a pre-built resize algorithm and give up on writing my own logic.</p>",
              "votes": 0,
              "replies": []
            },
            {
              "id": 2167721,
              "author_name": "Robert Hatch",
              "author_url": "",
              "post_date": "2023-03-03T17:09:49.180000",
              "content": "<p>At least it works!</p>\n<p>It's pretty terrible because it doesn't handle nan, and filling with 0s distorts the resized values… but at least it works.</p>",
              "votes": 0,
              "replies": []
            },
            {
              "id": 2168048,
              "author_name": "",
              "author_url": "",
              "post_date": "2023-03-03T20:30:02.710000",
              "content": "",
              "votes": 0,
              "replies": []
            }
          ]
        }
      ]
    },
    {
      "id": 2164090,
      "author_name": "Meikintom",
      "author_url": "",
      "post_date": "2023-03-01T09:47:41.210000",
      "content": "<p>Hi, I am so excited to attend this competition. I have some questions about the concentration from pytorch model to TensorFlow mode.<br>\nI know we can use onnx to do it. We need to install onnx_tf, which requires internet access. However, as a rule, says, we could n use the internet in the notebook. So how do we use onnx_tf? Is there a way to install it without using the internet?<br>\n!pip install onnx_tf</p>",
      "votes": 0,
      "replies": [
        {
          "id": 2167549,
          "author_name": "Robert Hatch",
          "author_url": "",
          "post_date": "2023-03-03T15:00:20.787000",
          "content": "<ol>\n<li><p>I think(?) you can simply use the internet in notebook 1, up to an including creating the tflite model, then use the result in notebook 2 that has internet off and makes the final submission. </p></li>\n<li><p>There's a couple simple ways discussed here: <a href=\"https://www.kaggle.com/competitions/icecube-neutrinos-in-deep-ice/discussion/382898\" target=\"_blank\">https://www.kaggle.com/competitions/icecube-neutrinos-in-deep-ice/discussion/382898</a></p></li>\n</ol>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 2161974,
      "author_name": "Failer",
      "author_url": "",
      "post_date": "2023-02-27T21:48:31.017000",
      "content": "<p>My sign language processing research is fundamentally impossible to run with tflite - <br>\nI first transcribe the sign represented as a pose sequence to SignWriting (autoregressive translation model, not supported in tflite), then I perform classification on the result. <br>\nI will not be able to participate unless you at the very least allow <em>multiple</em> tflite files, and a python function to, given a model, perform the inference loop.</p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 2160341,
      "author_name": "Ranjan Rashmi Sahoo",
      "author_url": "",
      "post_date": "2023-02-26T15:45:02.307000",
      "content": "<p>How can I learn tensorflow in kaggle, Can someone guide me pls?</p>",
      "votes": 0,
      "replies": [
        {
          "id": 2162057,
          "author_name": "Glenn Cameron",
          "author_url": "",
          "post_date": "2023-02-28T00:44:49.040000",
          "content": "<p>Hi Ranjan, take a look at this guide: <a href=\"https://www.kaggle.com/learn-guide/tensorflow\" target=\"_blank\">https://www.kaggle.com/learn-guide/tensorflow</a></p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 2159921,
      "author_name": "Tim Sereno",
      "author_url": "",
      "post_date": "2023-02-26T06:23:00.787000",
      "content": "<p>Do you happen to have example notebook/script that can convert LightGBM/XGBoost -&gt; ONNX -&gt; TensorFlow -&gt; TensorFlow Lite? Looks technically feasible with this ONNX toolset.  <a href=\"https://github.com/onnx/onnxmltools\" target=\"_blank\">https://github.com/onnx/onnxmltools</a> </p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 2158650,
      "author_name": "Dietzsche Nostoevsky",
      "author_url": "",
      "post_date": "2023-02-25T03:28:37.700000",
      "content": "<p>What resources would you suggest for beginners to learn TF Lite, given some familiarity with Tensorflow ?</p>",
      "votes": 0,
      "replies": [
        {
          "id": 2158683,
          "author_name": "Paul Ruiz",
          "author_url": "",
          "post_date": "2023-02-25T04:21:30.087000",
          "content": "<p>So it really depends on how you learn best and what your current experience level is with ML in general. A few places I'd start would be the <a href=\"https://www.tensorflow.org/lite\" target=\"_blank\">official documentation pages</a> and the <a href=\"https://www.youtube.com/@TensorFlow\" target=\"_blank\">YouTube channel</a> with a bit of searching for what you want to learn. Hopefully that helps at least get you started :)</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 2157830,
      "author_name": "Prateek Gupta",
      "author_url": "",
      "post_date": "2023-02-24T11:12:49.203000",
      "content": "<p>Can we have the dataset in any object detection format- TF or YOLO?</p>",
      "votes": 0,
      "replies": [
        {
          "id": 2158531,
          "author_name": "Sohier Dane",
          "author_url": "",
          "post_date": "2023-02-24T23:38:36.483000",
          "content": "<p>We are only going to provide the data in the existing format.</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 2157564,
      "author_name": "",
      "author_url": "",
      "post_date": "2023-02-24T05:55:17.933000",
      "content": "",
      "votes": 0,
      "replies": [
        {
          "id": 2158166,
          "author_name": "",
          "author_url": "",
          "post_date": "2023-02-24T17:05:15.180000",
          "content": "",
          "votes": 0,
          "replies": [
            {
              "id": 2158262,
              "author_name": "",
              "author_url": "",
              "post_date": "2023-02-24T18:13:35.500000",
              "content": "",
              "votes": 0,
              "replies": []
            },
            {
              "id": 2158604,
              "author_name": "",
              "author_url": "",
              "post_date": "2023-02-25T02:18:19.607000",
              "content": "",
              "votes": 0,
              "replies": []
            },
            {
              "id": 2158605,
              "author_name": "",
              "author_url": "",
              "post_date": "2023-02-25T02:19:45.350000",
              "content": "",
              "votes": 0,
              "replies": []
            }
          ]
        }
      ]
    },
    {
      "id": 2220628,
      "author_name": "",
      "author_url": "",
      "post_date": "2023-04-13T14:53:09.157000",
      "content": "",
      "votes": 0,
      "replies": []
    },
    {
      "id": 2217997,
      "author_name": "",
      "author_url": "",
      "post_date": "2023-04-11T10:27:15.153000",
      "content": "",
      "votes": -2,
      "replies": []
    },
    {
      "id": 2179008,
      "author_name": "",
      "author_url": "",
      "post_date": "2023-03-12T20:22:37.343000",
      "content": "",
      "votes": 0,
      "replies": []
    },
    {
      "id": 2167533,
      "author_name": "",
      "author_url": "",
      "post_date": "2023-03-03T14:50:48.947000",
      "content": "",
      "votes": 0,
      "replies": []
    },
    {
      "id": 2161923,
      "author_name": "",
      "author_url": "",
      "post_date": "2023-02-27T20:37:05.853000",
      "content": "",
      "votes": 0,
      "replies": []
    },
    {
      "id": 2160830,
      "author_name": "",
      "author_url": "",
      "post_date": "2023-02-27T02:52:07.107000",
      "content": "",
      "votes": 3,
      "replies": []
    },
    {
      "id": 2157901,
      "author_name": "",
      "author_url": "",
      "post_date": "2023-02-24T12:45:06.923000",
      "content": "",
      "votes": 1,
      "replies": [
        {
          "id": 2158279,
          "author_name": "",
          "author_url": "",
          "post_date": "2023-02-24T18:36:21.057000",
          "content": "",
          "votes": 0,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "2157047": "Hey all! I'm Paul, a developer advocate with the TensorFlow team. I wanted to make a discussion thread here for all TensorFlow Lite related questions so we can follow along in a centralized place and get the correct people around for sharing their knowledge :)",
    "2160198": "> Your model must also require less than 40 MB in memory\n\nHow do we calculate the in-memory size of a model?  What specific checks does the submission evaluation run - so that we can pre-check our models and avoid wasted submissions.",
    "2162315": "I recently started learning Tensorflow and wish to confirm that my understanding is correct:\n- TFlite is not for building models but for using them in practice.\n- So they can be built in Tensorflow as usual.\n- But tensorflow models by themselves are not tflite compatible.\n- So we use tf.lite.TFLiteConverter to make it tflite compatible.(source: [https://www.tensorflow.org/lite/guide/inference](https://www.tensorflow.org/lite/guide/inference))\nPlease let me know if this is correct or correct where required.\nAlso, please suggest any other methods we can use.",
    "2170436": "Is there a list somewhere that tells us what layers are compatible with TFlite? Since we are dealing with sequences of data, I tried using LSTM and GRU, but both don't seem to be compatible with TFlite. It technically runs, but when I convert to TFlite I get this warning: \n\nWARNING:absl:Found untraced functions such as _update_step_xla, lstm_cell_1_layer_call_fn, lstm_cell_1_layer_call_and_return_conditional_losses, lstm_cell_2_layer_call_fn, lstm_cell_2_layer_call_and_return_conditional_losses while saving (showing 5 of 5). These functions will not be directly callable after loading.\n\nThe accuracy when using the TFlite model is much lower than when using regular TF model. Assuming it's because GRU and LSTM are not compatible with TFlite?",
    "2157188": "As, I am at starting state of learning, I don't known weather it will complete or not. But for me this project seams to be a great one and I will try to learn at least something while working on this.\n\n\nthank you for this amazing project\n",
    "2158548": ">Your model must also require less than 40 MB in memory and perform inference with less than 100 milliseconds of latency per video. \n\nHow should we calculate the inference latency for each video on the validation set? Should we calculate the time between reading data from disk and getting inference results? Because I assume we can't get all the data to be read into RAM or graphics memory",
    "2157243": "what is the best tools/way to convert Pytorch model to tflite?",
    "2157385": "> This competition requires submissions to be made in the form of TensorFlow Lite models. You are welcome to train your model using the framework of your choice as long as you convert the model checkpoint into the tflite format prior to submission. Please see the evaluation page for details.\n\nWhat if we did not use TensorFlow Lite models? We will be removed from Leaderboard?",
    "2217824": "Thanks for you amazing code, it helps me a lot",
    "2232348": "very good.this code help me a lot",
    "2226249": "Hello\nI receive error message:\n\n```python\nerror: 'tf.Conv2D' op is neither a custom op nor a flex op\nerror: failed while converting: 'main': \nSome 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\nDetails:\n    tf.Conv2D(tensor<*xf32>, tensor<2x2x3x32xf32>) -> (tensor<?x?x?x32xf32>) : {data_format = \"NHWC\", device = \"\", dilations = [1, 1, 1, 1], explicit_paddings = [], padding = \"SAME\", strides = [1, 1, 1, 1], use_cudnn_on_gpu = true}\n```\nWhy it's happens? According https://www.tensorflow.org/mlir/tfl_ops?hl=ru#tflconv_2d_mlirtflconv2dop conv_2d layers are supported",
    "2218660": "TFlite models seem to grow in size very quickly for just a few more features in the data. Are there standard ways to shrink the size? ",
    "2198405": "Several people have already mentioned the topic of \"TensorFlow operators\".\nAs far as I can confirm, the current submission environment does not support TensorFlow operators, I would expect.\nI checked on the Kaggle notebook and it is possible to support TensorFlow operators in tflite_runtime by importing tensorflow as follows\n\n```\n@@ -1,3 +1,4 @@\n+import tensorflow\n import tflite_runtime.interpreter as tflite\n interpreter = tflite.Interpreter(model_path)\n```\n\nIt seems that the introduction of TensorFlow operators is not impractical for device implementations.\nhttps://www.tensorflow.org/lite/guide/ops_select\n\nIs there any possibility of this modification to the submission environment?\n\nI would be very happy if TensorFlow operators were introduced, as I think it would make it easier to implement more complex models and increase our chances of achieving greater results.\n\nI welcome any comments on implementation issues on the device, concerns about competitiveness, etc.\n",
    "2189855": "Hello, guys. I faced an issue with tf.data pipeline working in graph mode. I need to edit the tensor somehow, but I cannot do so. I understand that tf.Tensor is immutable and supposed to work in a functional style. So, I am creating tf.Variable from it and that works well in eager execution mode. But tf.data pipeline uses graph mode and makes tf.Variable creation in such a way impossible. \nHere is a minimalistic code, which reproduce my issue:\n\n>import tensorflow as tf\n>\n>x = tf.constant([1,2,3.0])\n>ds = tf.data.Dataset.from_tensors(x)\n>\n>def test(x):\n>      with tf.init_scope():\n>      v = tf.Variable(x)\n>\n>ds_x = ds.map(test)\n>next(iter(ds_x))\n\nHere is an error I get\n\n`\nValueError: in user code:\n\n    File \"/tmp/ipykernel_3517/140449158.py\", line 6, in test  *\n        v = tf.Variable(x)\n\n    ValueError: Argument `initial_value` (Tensor(\"args_0:0\", shape=(3,), dtype=float32)) could not be lifted out of a `tf.function`. (Tried to create variable with name='None'). To avoid this error, when constructing `tf.Variable`s inside of `tf.function` you can create the `initial_value` tensor in a `tf.init_scope` or pass a callable `initial_value` (e.g., `tf.Variable(lambda : tf.truncated_normal([10, 40]))`). Please file a feature request if this restriction inconveniences you.\n`\n\nBest to my understanding, I cannot create a tf.Variable which depends on input tensor `x` because of static execution graph. But how do I change a part of input tensor `x`, where the decision of that part is depends on `x` content?\n\nLooking forward to your advice. Thank you in advance",
    "2185203": "Hi there! Are there any constrains on the model submission for using `supported_ops`?\n**If so, it should be updated on the Submission Requirements**\n\nMy submission size is les than 2mb and time is under 100ms but still gives an error.\nThe only different thing I have from other submissions is that Im using this:\n```python\nconverter.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```",
    "2173968": "Hi all, I Hope you all are well. \n\nMy TFLite model works fine with tflite-runtime version 2.11.0, However, it causes the notebook to crash if I use 2.9.1 instead.\n\nThe notebook crashes while initializing the interpreter.\n\ninterpreter = tflite.Interpreter(tflite_model_path)\n\nwhile loading the interpreter in tflite-runtime version 2.11.0, I get following warnings.\n\n-  INFO: Created TensorFlow Lite delegate for select TF ops.\n-  INFO: TfLiteFlexDelegate delegate: 30 nodes delegated out of 166 nodes with 2 partitions.\n\nAny help would be appreciated. Thanks",
    "2173799": "How do I convert from Pytorch and use tensorflow without running into any bugs ?",
    "2171174": "Hi all,\n\nI have two questions:\n\n(1) several preprocessed datasets are currently in use: if we generate our own preprocessed dataset (e.g. with a different batch size or different preprocessing), do we need to regenerate this from scratch in our final submission? Or do we only need to generate it once and is any dataset we generate automatically coupled to the notebook that generated it? I'm also not sure how (where) to save a self-generated dataset from one notebook in such a way we can use it from a different notebook.\n(2) W.r.t. the time constraint for TfLite inference: does a submission fail when that is exceeded? And if not: how can we know whether our submission meets this constraint?",
    "2169836": "Hi,\n\nI'm using TensorFlow to make my model for this competition. I tried enabling mixed precision (using float16 and float32 during the training) to reduce the training time, which works just fine. But when I try to convert my (final) trained model into TensorFlow Lite format for submission, the conversion takes too much time. (I waited about 5 hours before manually stopping  the conversion code; the code for conversion just stayed hung.) When I don't enable global mixed precision policy in TensorFlow, the conversion works fine, and it takes about a minute or so. \n\nThis is my conversion code:\n\n```Python\n\n# Convert the final model to a 'tflite' model\nconverter = tf.lite.TFLiteConverter.from_keras_model(final_model)\n\ntflite_model = converter.convert()\nmodel_path = \"model.tflite\"\n\n# Save the tflite model\nwith open(model_path, 'wb') as f:\n    f.write(tflite_model)\n\n# Make the 'submission.zip'\n!zip submission.zip $model_path\n\n```\n\nDo you have any workarounds for this problem?\n\nBTW, I use TensorFlow 2.10 and 2.11 for training (and conversion).\n",
    "2169118": "Dear experts,\n\nI'm still confused about one thing in TfLite. Tensorflow models always have a 'hidden' first input dimension corresponding to batch size, with 'None' size to account for variable batch size. In the code posted by Lonnie, for the inference model, the batch dimension is 'abused' as a time dimension. When you train a variable time step time series model in Tensorflow, you typically have two None dimensions: one for batch size and one for frames. I've already tried many things, but haven't found a way to get this into TfLight. So is this at all possible and if so: how? Do we need to pass specific arguments to the TfLite model generation? This would be by far the easiest solution since you could then directly compile your trained model instead of having to reconstruct it in the inference model code (this is particularly painful if your model has branches and merges).\n\nAs an alternative, I also tried adding a size-1 first dimension inside the inference model (since batch size would always be 1 at inference time), but never managed to get this running: whatever I try, I get errors either at compile time or when trying to run it for inference. ",
    "2168628": "Hello, I've been having difficulties submitting my work and I think I finally understood why : I was using the tf.atan function in my work, which isn't handled by TFLite. \nI tried some workaround (tf.asin/tf.angle for instance) but it seems every one of them is failing when converting the model to TFLite. Do you happen to know of a native tensorflow, TFLite-supported, operation to compute angles ?",
    "2168166": "Any suggestions how to do a basic np.nanmean on a given axis in TF Lite?\n\nI eventually found that this code below doesn't work because ragged tensor ops aren't supported in conversion. I was using it to preserve dimensions, which is obviously necessary (for only a split second) for the 'reduce_mean' to work correctly.\n\n```python\n        face_center = tf.reduce_mean(tf.ragged.boolean_mask(inputs[:, 0:468, :], tf.math.is_finite(inputs[:, 0:468, :])), axis=1, keepdims=True)\n        face_center = face_center.to_tensor(default_value=float('nan'), shape=[None, 1, 3])\n```",
    "2168049": "I assume \"SELECT_TF_OPS\" is NOT supported and will fail in scoring?\n\n```python\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```",
    "2166680": "I'm having a lot of trouble with the preprocessing.\n\nMy current problem can, hopefully, be simplified as very similar to wanting to resize a variable shape image to a fixed size:\nSomething like tf.keras.layers.Resizing\n\nExamples that will never work(?)\nFrom https://www.kaggle.com/code/lonnieqin/isolated-sign-language-recognition-with-dnn\n```python\n    inputs = tf.keras.Input((543, 3), dtype=tf.float32, name=\"inputs\")\n    x = custom_preprocess(inputs)\n```\nThis is symbolic, so won't work with my custom_preprocess function that has special logic based on the number of frames.\nAlong those lines, is there some way that this code COULD work with tf.keras.layers.Resizing?\n\n-\nFrom https://www.kaggle.com/code/dschettler8845/gislr-learn-eda-baseline/notebook\n`    @tf.function(input_signature=[tf.TensorSpec(shape=[None, 543, 3], dtype=tf.float32, name='inputs')])`\nI think this is similar to the other example? I doubt it can work with my custom function. No idea whether it's possible or how to convert it to use something like tf.keras.layers.Resizing.\n\nIs there some approach that should work? Taking a variable dimension and dynamically converting it to a fixed size dimension using custom logic seems like a very common type of problem.",
    "2164090": "Hi, I am so excited to attend this competition. I have some questions about the concentration from pytorch model to TensorFlow mode.\nI know we can use onnx to do it. We need to install onnx_tf, which requires internet access. However, as a rule, says, we could n use the internet in the notebook. So how do we use onnx_tf? Is there a way to install it without using the internet?\n!pip install onnx_tf",
    "2161974": "My sign language processing research is fundamentally impossible to run with tflite - \nI first transcribe the sign represented as a pose sequence to SignWriting (autoregressive translation model, not supported in tflite), then I perform classification on the result. \nI will not be able to participate unless you at the very least allow *multiple* tflite files, and a python function to, given a model, perform the inference loop.",
    "2160341": "How can I learn tensorflow in kaggle, Can someone guide me pls?",
    "2159921": "Do you happen to have example notebook/script that can convert LightGBM/XGBoost -> ONNX -> TensorFlow -> TensorFlow Lite? Looks technically feasible with this ONNX toolset.  https://github.com/onnx/onnxmltools ",
    "2158650": "What resources would you suggest for beginners to learn TF Lite, given some familiarity with Tensorflow ?",
    "2157830": "Can we have the dataset in any object detection format- TF or YOLO?",
    "2157564": "The competition requires the use TensorFlow. What if the model I come up with is fundamentally different from commonly used machine learning models today? (Specifically, fundamentally different from a neural network.)",
    "2220628": "",
    "2217997": "",
    "2179008": "",
    "2167533": "",
    "2161923": "",
    "2160830": "",
    "2157901": ""
  }
}