File size: 1,171 Bytes
970a7a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
39
40
41
import shutil
import os
from os.path import join


class AverageMeter:
    """Computes and stores the average and current value"""
    def __init__(self):
        self.reset()

    def reset(self):
        self.val = 0
        self.avg = 0
        self.sum = 0
        self.count = 0

    def update(self, val, n=1):
        self.val = val
        self.sum += val * n
        self.count += n
        self.avg = self.sum / self.count

def create_backup(folders = None, files = None, backup_dir = 'experiments'):
    if folders is None:
        folders = ['.', 'corr_lists','detection']
    if files is None:
        files = ['.py', '.txt', '.json','.cfg']

    for folder in folders:
        if not os.path.isdir(folder):
            continue
        for file in os.listdir(folder):
            if file.endswith(tuple(files)):
                if folder != '.':
                    src = join(folder, file)
                    dest = join(backup_dir, folder, file)
                else:
                    src = file
                    dest = join(backup_dir, file)
                os.makedirs(os.path.split(dest)[0], exist_ok=True)
                shutil.copy(src, dest)