def __init__(self, impath='', label=0, domain=-1, classname=''): assert isinstance(impath, str) assert isinstance(label, int) assert isinstance(domain, int) assert isinstance(classname, str) assert check_isfile(impath) self._impath = impath self._label = label self._domain = domain self._classname = classname
def parse_dir(directory, end_signal, regex_acc, regex_err, args): print('Parsing {}'.format(directory)) subdirs = listdir_nohidden(directory, sort=True) valid_fpaths = [] valid_accs = [] valid_errs = [] for subdir in subdirs: fpath = osp.join(directory, subdir, 'log.txt') assert check_isfile(fpath) good_to_go = False with open(fpath, 'r') as f: lines = f.readlines() for line in lines: line = line.strip() if line == end_signal: good_to_go = True match_acc = regex_acc.search(line) if match_acc and good_to_go: acc = float(match_acc.group(1)) valid_accs.append(acc) valid_fpaths.append(fpath) match_err = regex_err.search(line) if match_err and good_to_go: err = float(match_err.group(1)) valid_errs.append(err) for fpath, acc, err in zip(valid_fpaths, valid_accs, valid_errs): print('file: {}. acc: {:.2f}%. err: {:.2f}%'.format(fpath, acc, err)) acc_mean = np.mean(valid_accs) acc_std = compute_ci95(valid_accs) if args.ci95 else np.std(valid_accs) err_mean = np.mean(valid_errs) err_std = compute_ci95(valid_errs) if args.ci95 else np.std(valid_errs) print('===') print('outcome of directory: {}'.format(directory)) if args.res_format in ['acc', 'acc_and_err']: print('* acc: {:.2f}% +- {:.2f}%'.format(acc_mean, acc_std)) if args.res_format in ['err', 'acc_and_err']: print('* err: {:.2f}% +- {:.2f}%'.format(err_mean, err_std)) print('===') return acc_mean, err_mean
def check_cfg(self, cfg): assert check_isfile(cfg.MODEL.INIT_WEIGHTS ), 'The weights of source model must be provided'