def autoFindBestEpoch(c, evaluFun, sortkey=None, epochs=None, savefig=False): '''遍历所有epoch的weight 并通过测试集评估项sortkey 找出最佳epoch Parameters ---------- c : dicto 即configManager 生成的测试集的所有环境配置 c 包含args,数据配置,各类函数等 evaluFun : Funcation 用于评测的函数,用于Evalu类 需要返回dict对象 sortkey : str, default None 用于筛选时候的key 默认为df.columns[-1] Return: DataFrame 每个参数组合及其评价的平均值 ''' args = c.args if not isinstance(epochs, (tuple, list)): pas = [ p[len(args.prefix):] for p in glob(args.prefix + '*') if p[-4:] != 'json' ] eps = map(lambda s: len(findints(s)) and findints(s)[-1], pas) maxx = len(eps) and max(eps) minn = len(eps) and min(eps) if isinstance(epochs, int): epochs = range(minn, maxx)[::epochs] + [maxx] else: epochs = range(minn, maxx + 1) args['restore'] = ArgList(epochs) # print epochs df = autoFindBestParams(c, args, evaluFun, sortkey=sortkey, savefig=savefig) return df
pr_out = pathjoin(c.tmpdir,'pr') # ============================================================================= # config BEGIN # ============================================================================= args.update( restore=-1, step=64, ) # ============================================================================= # config END # ============================================================================= if args.restore == -1: pas = [p[len(args.prefix):] for p in glob(args.prefix+'*')] args.restore = len(pas) and max(map(lambda s:len(findints(s)) and findints(s)[-1],pas)) makeValEnv(args) #setMod('train') if __name__ == '__main__': import predictInterface c.predictInterface = predictInterface predict = predictInterface.predict # c.predict = predict # e = Evalu(diceEvalu, ## evaluName='restore-%s'%restore, # valNames=c.names, ## loadcsv=1, # logFormat='dice:{dice:.3f}, loss:{loss:.3f}', # sortkey='loss', ## loged=False,
# config BEGIN # ============================================================================= args.update( # restore=43, restore=28, step=None, # step=.2, ) # ============================================================================= # config END # ============================================================================= if args.restore == -1: pas = [p[len(args.prefix):] for p in glob(args.prefix + '*')] args.restore = len(pas) and max( map(lambda s: len(findints(s)) and findints(s)[-1], pas)) makeValEnv(args) accEvalu = lambda re, gt: { 'acc': (re == gt).sum() * 1. / re.size, 'loss': (~(re == gt)).sum() * 1. / re.size } colors = np.array([ (255, 255, 255), (0, 0, 255), (0, 255, 255), (0, 255, 0), (255, 255, 0), (255, 0, 0), ]) / 255.