Skip to content

Commit 25fa392

Browse files
committed
Added an additional optional --tmp_dir parameter to specify the temporary directory in which tesstrain.py creates the training temporary files. The main reason is due to the slow R/W on HDD, if anyone wants to speed up this process can use as tmp_dir a directory on an SSDrive
1 parent 7fbde96 commit 25fa392

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/training/tesstrain_utils.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ def check_file_readable(*filenames):
125125
help="A list of fontnames to train on.",
126126
)
127127
parser.add_argument("--fonts_dir", help="Path to font files.")
128+
parser.add_argument("--tmp_dir", help="Path to temporary training directory.")
128129
parser.add_argument(
129130
"--lang", metavar="LANG_CODE", dest="lang_code", help="ISO 639 code."
130131
)
@@ -214,8 +215,11 @@ def parse_flags(argv=None):
214215
ctx.output_dir = mkdtemp(prefix=f"trained-{ctx.lang_code}-{ctx.timestamp}")
215216
log.info(f"Output directory set to: {ctx.output_dir}")
216217

217-
# Location where intermediate files will be created.
218-
ctx.training_dir = mkdtemp(prefix=f"{ctx.lang_code}-{ctx.timestamp}")
218+
# Location where intermediate files will be created.
219+
if not ctx.tmp_dir:
220+
ctx.training_dir = mkdtemp(prefix=f"{ctx.lang_code}-{ctx.timestamp}")
221+
else:
222+
ctx.training_dir = mkdtemp(prefix=f"{ctx.lang_code}-{ctx.timestamp}", dir=ctx.tmp_dir)
219223
# Location of log file for the whole run.
220224
ctx.log_file = Path(ctx.training_dir) / "tesstrain.log"
221225
log.info(f"Log file location: {ctx.log_file}")

0 commit comments

Comments
 (0)