Use GFile for internal file systems.

PiperOrigin-RevId: 541041972
This commit is contained in:
MediaPipe Team 2023-06-16 16:43:44 -07:00 committed by Copybara-Service
parent 41215a3878
commit 80208079d2

View File

@ -161,9 +161,8 @@ class TextClassifier(classifier.Classifier):
path is {self._hparams.export_dir}/{model_name}.
quantization_config: The configuration for model quantization.
"""
if not tf.io.gfile.exists(self._hparams.export_dir):
tf.io.gfile.makedirs(self._hparams.export_dir)
tflite_file = os.path.join(self._hparams.export_dir, model_name)
tf.io.gfile.makedirs(os.path.dirname(tflite_file))
metadata_file = os.path.join(self._hparams.export_dir, "metadata.json")
tflite_model = model_util.convert_to_tflite(
@ -174,7 +173,7 @@ class TextClassifier(classifier.Classifier):
writer = self._get_metadata_writer(tflite_model, vocab_filepath)
tflite_model_with_metadata, metadata_json = writer.populate()
model_util.save_tflite(tflite_model_with_metadata, tflite_file)
with open(metadata_file, "w") as f:
with tf.io.gfile.GFile(metadata_file, "w") as f:
f.write(metadata_json)
@abc.abstractmethod