Skip to content

Commit 4bc8bdf

Browse files
committed
change shell scripts to universal filesystem calls
1 parent 7d0587b commit 4bc8bdf

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

tasks/base_task.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import glob
22
import re
3+
import shutil
34
import subprocess
45
from datetime import datetime
56

@@ -249,10 +250,12 @@ def start(cls):
249250
if not hparams['infer']: # train
250251
t = datetime.now().strftime('%Y%m%d%H%M%S')
251252
code_dir = f'{work_dir}/codes/{t}'
252-
subprocess.check_call(f'mkdir "{code_dir}"', shell=True)
253+
# TODO: test filesystem calls
254+
os.mkdir(code_dir)
255+
# subprocess.check_call(f'mkdir "{code_dir}"', shell=True)
253256
for c in hparams['save_codes']:
254-
# TODO
255-
subprocess.check_call(f'xcopy "{c}" "{code_dir}/" /s /e /y', shell=True)
257+
shutil.copytree(c, code_dir, dirs_exist_ok=True)
258+
# subprocess.check_call(f'xcopy "{c}" "{code_dir}/" /s /e /y', shell=True)
256259
print(f"| Copied codes to {code_dir}.")
257260
trainer.checkpoint_callback.task = task
258261
trainer.fit(task)

utils/pl_utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,9 @@ def on_epoch_end(self, epoch, logs=None):
335335
logging.info(f'Epoch {epoch:05d}@{self.task.global_step}: saving model to {filepath}')
336336
self._save_model(filepath)
337337
for old_ckpt in self.get_all_ckpts()[self.num_ckpt_keep:]:
338-
# TODO
339-
subprocess.check_call(f'del "{old_ckpt}"', shell=True)
338+
# TODO: test filesystem calls
339+
os.remove(old_ckpt)
340+
# subprocess.check_call(f'del "{old_ckpt}"', shell=True)
340341
if self.verbose > 0:
341342
logging.info(f'Delete ckpt: {os.path.basename(old_ckpt)}')
342343
current = logs.get(self.monitor)

0 commit comments

Comments
 (0)