Exemplo n.º 1
0
def cal_average_no_boot(multi_results):
    precs = []
    recs = []
    fs = []
    for res in multi_results:
        prec, rec, f1, _ = U.cal_prec_rec_f1_v2(res, targets)
        precs.append(prec)
        recs.append(rec)
        fs.append(f1)
    return np.average(fs), np.average(precs), np.average(recs)
def get_test_result_long_v2(m, testld):
    if testld is None:
        return none_dic()
    else:
        dic = {}
        testld.start = 0
        outputs, targets = U.get_test_results_single_point_v2(
            m, testld, U.logging.debug)
        prec, rec, f1, bacc = U.cal_prec_rec_f1_v2(outputs, targets)
        dic['prec'] = prec
        dic['rec'] = rec
        dic['f1'] = f1
        dic['bacc'] = bacc
        return dic
Exemplo n.º 3
0
def run_test(m, epoch = 1, path = 'result.png', log_path = 'danraku.log'):
  U.init_logger(log_path)
  results = []
  losss = []
  ld.start = 0
  for i in range(epoch):
    loss = U.train_by_data_loader_danraku(m, mini_ld, 1, U.logging.debug)[0]
    losss.append(loss)
    outputs, targets = U.get_test_results(m, mini_testld)
    prec, rec, f1, bacc = U.cal_prec_rec_f1_v2(outputs, targets)
    results.append((prec, rec, f1, bacc))
    print(f'epoch = {i}, loss = {loss}, {prec}, {rec}, {f1}')
  plot_prec_rec_f1_loss(results, losss, epoch, path)
  print('save to result.png')
  return m, results, losss
Exemplo n.º 4
0
def cal_avg_score(targets, multi_results, sampled_indexs):
    sampled_targets = [targets[idx] for idx in sampled_indexs]
    sampled_multi_results = []
    for results in multi_results:
        sampled_multi_results.append([results[idx] for idx in sampled_indexs])
    f_scores = []
    precs = []
    recs = []
    for sampled_results in sampled_multi_results:
        prec, rec, f1, bacc = U.cal_prec_rec_f1_v2(sampled_results,
                                                   sampled_targets)
        f_scores.append(f1)
        precs.append(prec)
        recs.append(rec)
    return np.average(f_scores), np.average(precs), np.average(recs)
def get_test_result_segbot(m, testds):
    dic = {}
    if testds is None:
        dic['prec'] = -1
        dic['rec'] = -1
        dic['f1'] = -1
        dic['bacc'] = -1
    else:
        outputs, targets = get_test_results_segbot_v2(m, testds,
                                                      U.logging.debug)
        prec, rec, f1, bacc = U.cal_prec_rec_f1_v2(outputs, targets)
        dic['prec'] = prec
        dic['rec'] = rec
        dic['f1'] = f1
        dic['bacc'] = bacc
    return dic
def get_test_result(m, testld):
    testld.start = 0
    dic = {}
    if testld is None:
        dic['prec'] = -1
        dic['rec'] = -1
        dic['f1'] = -1
        dic['bacc'] = -1
    else:
        outputs, targets = U.get_test_results_batch(m, testld, U.logging.debug)
        prec, rec, f1, bacc = U.cal_prec_rec_f1_v2(outputs, targets)
        dic['prec'] = prec
        dic['rec'] = rec
        dic['f1'] = f1
        dic['bacc'] = bacc
    return dic
Exemplo n.º 7
0
def get_test_result_dic(m, testld):
    testld.start = 0
    dic = {}
    if testld is None:
        dic['prec'] = -1
        dic['rec'] = -1
        dic['f1'] = -1
        dic['bacc'] = -1
    else:
        outputs, targets = get_test_result(m, testld)
        prec, rec, f1, bacc = U.cal_prec_rec_f1_v2(outputs, targets)
        dic['prec'] = prec
        dic['rec'] = rec
        dic['f1'] = f1
        dic['bacc'] = bacc
    return dic
Exemplo n.º 8
0
def run(m, epoch = 20, path = 'result.png', log_path = 'danraku.log', ld = ld, batch=8):
  U.init_logger(log_path)
  results = []
  losss = []
  recover_batch_size = ld.batch_size
  ld.batch_size = batch
  ld.start = 0
  print(f'Loader window size: {ld.ds.half_window_size}')
  for i in range(epoch):
    loss = U.train_by_data_loader_danraku(m, ld, 1, U.logging.debug)[0]
    losss.append(loss)
    outputs, targets = U.get_test_results(m, testld)
    prec, rec, f1, bacc = U.cal_prec_rec_f1_v2(outputs, targets)
    results.append((prec, rec, f1, bacc))
    print(f'epoch = {i}, loss = {loss}, {prec}, {rec}, {f1}')
  plot_prec_rec_f1_loss(results, losss, epoch, path)
  print('save to result.png')
  ld.batch_size = recover_batch_size
  return m, results, losss