Calls function to convert the TensorFlow 2.0 model into a TFLite model. Args: flags: argparse.Namespace object. Raises: ValueError: Unsupported file format.
(flags)
| 202 | |
| 203 | |
| 204 | def _convert_tf2_model(flags): |
| 205 | """Calls function to convert the TensorFlow 2.0 model into a TFLite model. |
| 206 | |
| 207 | Args: |
| 208 | flags: argparse.Namespace object. |
| 209 | |
| 210 | Raises: |
| 211 | ValueError: Unsupported file format. |
| 212 | """ |
| 213 | # Load the model. |
| 214 | if flags.saved_model_dir: |
| 215 | converter = lite.TFLiteConverterV2.from_saved_model(flags.saved_model_dir) |
| 216 | elif flags.keras_model_file: |
| 217 | model = keras.models.load_model(flags.keras_model_file) |
| 218 | converter = lite.TFLiteConverterV2.from_keras_model(model) |
| 219 | |
| 220 | # Convert the model. |
| 221 | tflite_model = converter.convert() |
| 222 | with open(flags.output_file, "wb") as f: |
| 223 | f.write(tflite_model) |
| 224 | |
| 225 | |
| 226 | def _check_tf1_flags(flags, unparsed): |
no test coverage detected