{
  "id": 397977,
  "title": "how to use \"converter.representative_dataset\" ?",
  "url": "/competitions/asl-signs/discussion/397977",
  "author_name": "hengck23",
  "post_date": "2023-03-28T03:47:45.856000",
  "votes": 3,
  "comment_count": 0,
  "views": 0,
  "content": "<p>i follow the instruction for post int8 training:<br>\n<a href=\"https://www.tensorflow.org/lite/performance/post_training_integer_quant\" target=\"_blank\">https://www.tensorflow.org/lite/performance/post_training_integer_quant</a></p>\n<p>my code:</p>\n<pre><code>def representative_data_gen():\n\n    df = kaggle_df[:10].reset_index(drop=True)\n    #df = kaggle_df[::10].reset_index(drop=True)\n\n    print('representative_data_gen: len(df)', len(df))\n    data = []\n    for t, d in df.iterrows():\n        print('\\r cache', t, end='')\n        pq_file = f'{root_dir}/data/asl-signs/{d.path}'\n        xyz = load_relevant_data_subset(pq_file)#[:256]\n        yield [xyz]\n    print('')\n\n#---\nif 1:\n    tfmodel = TFModel()\n    tf.saved_model.save(tfmodel, tf_file, signatures={'serving_default': tfmodel.__call__})\n    converter = tf.lite.TFLiteConverter.from_saved_model(tf_file)\n\n    converter.optimizations = [tf.lite.Optimize.DEFAULT] \n    converter.representative_dataset = representative_data_gen\n</code></pre>\n<p>it seems the quntization is sucessful becuase it get the message:</p>\n<pre><code>fully_quantize: 0, inference_type: 6, input_inference_type: FLOAT32, output_inference_type: FLOAT32\n</code></pre>\n<p>But when i use tfite runtime to load and run the model, i have</p>\n<pre><code>Process finished with exit code 134 (interrupted by signal 6: SIGABRT)\n</code></pre>\n<p>without the use of \"converter.representative_dataset = representative_data_gen\", everything is ok. what can go wrong????</p>\n<p>does it work for dynmaic shape (variable length)?</p>",
  "messages": [
    {
      "id": 2199796,
      "postDate": "2023-03-28T03:47:45.857Z",
      "content": "<p>i follow the instruction for post int8 training:<br>\n<a href=\"https://www.tensorflow.org/lite/performance/post_training_integer_quant\" target=\"_blank\">https://www.tensorflow.org/lite/performance/post_training_integer_quant</a></p>\n<p>my code:</p>\n<pre><code>def representative_data_gen():\n\n    df = kaggle_df[:10].reset_index(drop=True)\n    #df = kaggle_df[::10].reset_index(drop=True)\n\n    print('representative_data_gen: len(df)', len(df))\n    data = []\n    for t, d in df.iterrows():\n        print('\\r cache', t, end='')\n        pq_file = f'{root_dir}/data/asl-signs/{d.path}'\n        xyz = load_relevant_data_subset(pq_file)#[:256]\n        yield [xyz]\n    print('')\n\n#---\nif 1:\n    tfmodel = TFModel()\n    tf.saved_model.save(tfmodel, tf_file, signatures={'serving_default': tfmodel.__call__})\n    converter = tf.lite.TFLiteConverter.from_saved_model(tf_file)\n\n    converter.optimizations = [tf.lite.Optimize.DEFAULT] \n    converter.representative_dataset = representative_data_gen\n</code></pre>\n<p>it seems the quntization is sucessful becuase it get the message:</p>\n<pre><code>fully_quantize: 0, inference_type: 6, input_inference_type: FLOAT32, output_inference_type: FLOAT32\n</code></pre>\n<p>But when i use tfite runtime to load and run the model, i have</p>\n<pre><code>Process finished with exit code 134 (interrupted by signal 6: SIGABRT)\n</code></pre>\n<p>without the use of \"converter.representative_dataset = representative_data_gen\", everything is ok. what can go wrong????</p>\n<p>does it work for dynmaic shape (variable length)?</p>",
      "rawMarkdown": "i follow the instruction for post int8 training:\nhttps://www.tensorflow.org/lite/performance/post_training_integer_quant\n\nmy code:\n```\ndef representative_data_gen():\n\n\tdf = kaggle_df[:10].reset_index(drop=True)\n\t#df = kaggle_df[::10].reset_index(drop=True)\n\n\tprint('representative_data_gen: len(df)', len(df))\n\tdata = []\n\tfor t, d in df.iterrows():\n\t\tprint('\\r cache', t, end='')\n\t\tpq_file = f'{root_dir}/data/asl-signs/{d.path}'\n\t\txyz = load_relevant_data_subset(pq_file)#[:256]\n\t\tyield [xyz]\n\tprint('')\n\n#---\nif 1:\n\ttfmodel = TFModel()\n\ttf.saved_model.save(tfmodel, tf_file, signatures={'serving_default': tfmodel.__call__})\n\tconverter = tf.lite.TFLiteConverter.from_saved_model(tf_file)\n\t \n\tconverter.optimizations = [tf.lite.Optimize.DEFAULT] \n\tconverter.representative_dataset = representative_data_gen\n\n```\n\nit seems the quntization is sucessful becuase it get the message:\n\n```\nfully_quantize: 0, inference_type: 6, input_inference_type: FLOAT32, output_inference_type: FLOAT32\n```\n\nBut when i use tfite runtime to load and run the model, i have\n\n```\nProcess finished with exit code 134 (interrupted by signal 6: SIGABRT)\n```\n\nwithout the use of \"converter.representative_dataset = representative_data_gen\", everything is ok. what can go wrong????\n\ndoes it work for dynmaic shape (variable length)?",
      "votes": 3
    }
  ],
  "comments": [],
  "raw_markdown_by_id": {
    "2199796": "i follow the instruction for post int8 training:\nhttps://www.tensorflow.org/lite/performance/post_training_integer_quant\n\nmy code:\n```\ndef representative_data_gen():\n\n\tdf = kaggle_df[:10].reset_index(drop=True)\n\t#df = kaggle_df[::10].reset_index(drop=True)\n\n\tprint('representative_data_gen: len(df)', len(df))\n\tdata = []\n\tfor t, d in df.iterrows():\n\t\tprint('\\r cache', t, end='')\n\t\tpq_file = f'{root_dir}/data/asl-signs/{d.path}'\n\t\txyz = load_relevant_data_subset(pq_file)#[:256]\n\t\tyield [xyz]\n\tprint('')\n\n#---\nif 1:\n\ttfmodel = TFModel()\n\ttf.saved_model.save(tfmodel, tf_file, signatures={'serving_default': tfmodel.__call__})\n\tconverter = tf.lite.TFLiteConverter.from_saved_model(tf_file)\n\t \n\tconverter.optimizations = [tf.lite.Optimize.DEFAULT] \n\tconverter.representative_dataset = representative_data_gen\n\n```\n\nit seems the quntization is sucessful becuase it get the message:\n\n```\nfully_quantize: 0, inference_type: 6, input_inference_type: FLOAT32, output_inference_type: FLOAT32\n```\n\nBut when i use tfite runtime to load and run the model, i have\n\n```\nProcess finished with exit code 134 (interrupted by signal 6: SIGABRT)\n```\n\nwithout the use of \"converter.representative_dataset = representative_data_gen\", everything is ok. what can go wrong????\n\ndoes it work for dynmaic shape (variable length)?"
  }
}