{"record":{"id":"95404166ecb39747","repo":"tensorflow/models","slug":"must-provide-a-representative-dataset-when-quantiz","errorCode":null,"errorMessage":"Must provide a representative dataset when quantizing the model.","messagePattern":"Must provide a representative dataset when quantizing the model\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/projects/edgetpu/vision/serving/export_util.py","lineNumber":213,"sourceCode":"  dataset.download_and_prepare()\n  data = dataset.as_dataset()[quantization_config.dataset_split]\n  iterator = data.as_numpy_iterator()\n  for _ in range(quantization_config.num_calibration_steps):\n    features = next(iterator)\n    image = features['image']\n    image = preprocess_for_quantization(image, export_config.image_size)\n    image = tf.reshape(\n        image, [1, export_config.image_size, export_config.image_size, 3])\n    yield [image]\n\n\ndef configure_tflite_converter(export_config, converter):\n  \"\"\"Common code for picking up quantization parameters.\"\"\"\n  quantization_config = export_config.quantization_config\n  if quantization_config.quantize:\n    if (quantization_config.dataset_dir is\n        None) and (quantization_config.dataset_name is None):\n      raise ValueError(\n          'Must provide a representative dataset when quantizing the model.')\n    converter.optimizations = [tf.lite.Optimize.DEFAULT]\n    converter.target_spec.supported_ops = [\n        tf.lite.OpsSet.TFLITE_BUILTINS_INT8\n    ]\n    converter.inference_input_type = tf.int8\n    converter.inference_output_type = tf.int8\n    if quantization_config.quantize_less_restrictive:\n      converter.target_spec.supported_ops += [\n          tf.lite.OpsSet.TFLITE_BUILTINS\n      ]\n      converter.inference_output_type = tf.float32\n    def _representative_dataset_gen():\n      return representative_dataset_gen(export_config)\n\n    converter.representative_dataset = _representative_dataset_gen\n\n","sourceCodeStart":195,"sourceCodeEnd":231,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/projects/edgetpu/vision/serving/export_util.py#L195-L231","documentation":"Error \"Must provide a representative dataset when quantizing the model.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/projects/edgetpu/vision/serving/export_util.py:213 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e006f5f0d534913e49c1f1dae87364039fa607e2","analyzedAt":"2026-08-24T14:09:15.576Z","schemaVersion":2},"datasetVersion":"2026-08-24T17:17:21.512Z"}