CallbackNBatchCsv: open_handle mode

This commit is contained in:
Starbeamrainbowlabs 2022-11-03 18:29:00 +00:00
parent 3206d6b7e7
commit 1375201c5f
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
2 changed files with 5 additions and 2 deletions

View file

@ -9,7 +9,7 @@ class CallbackNBatchCsv(tf.keras.callbacks.Callback):
self.n_batches = n_batches
self.separator = separator
self.handle = handle_open(filepath)
self.handle = handle_open(filepath, "w")
self.batches_seen = 0

View file

@ -2,7 +2,10 @@ import io
import gzip
def handle_open(filepath, mode):
def handle_open(filepath, mode, force_textwrite_gzip=True):
if mode == "w" and mode.endswith(".gz") and force_textwrite_gzip:
mode = "wt"
if filepath.endswith(".gz"):
return gzip.open(filepath, mode)
else: