forked from gbegus/fiwGAN-ciwGAN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup.py
38 lines (28 loc) · 876 Bytes
/
backup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from __future__ import print_function
if __name__ == '__main__':
import glob
import os
import shutil
import sys
import time
import tensorflow as tf
train_dir, nmin = sys.argv[1:3]
nsec = int(float(nmin) * 60.)
backup_dir = os.path.join(train_dir, 'backup')
if not os.path.exists(backup_dir):
os.makedirs(backup_dir)
while tf.train.latest_checkpoint(train_dir) is None:
print('Waiting for first checkpoint')
time.sleep(1)
while True:
latest_ckpt = tf.train.latest_checkpoint(train_dir)
# Sleep for two seconds in case file flushing
time.sleep(2)
for fp in glob.glob(latest_ckpt + '*'):
_, name = os.path.split(fp)
backup_fp = os.path.join(backup_dir, name)
print('{}->{}'.format(fp, backup_fp))
shutil.copyfile(fp, backup_fp)
print('-' * 80)
# Sleep for an hour
time.sleep(nsec)