def __call__(self, depth=0, printt=True): if depth is False: printt = depth depth = 0 frame = sys._getframe(depth + 1) code = frame.f_code p.clear() glob = frame.f_globals local = frame.f_locals p.update(glob) p.update(local) self.c = self.code = code self.f = self.frame = frame self.l = self.local = local if printt: print('') prettyStr = prettyFrameLocation(frame) print(prettyStr) fs = getFatherFrames(frame) self.fs = fs s = prettyFrameStack(frame) print((colorFormat.b % 'Stacks: ' + colorFormat.r % s)) print((colorFormat.b % 'Locals: ')) from boxx import tree tree(local, deep=1, maxprint=40) if saveOut[id(self)]: root = getRootFrame() addDic = dict( # code=code, # frame=frame, # local=local, # glob=glob, # gl=glob, # rootGlob=root.f_globals, ) addDic.update(local) same = set(addDic).intersection(set(root.f_globals)) if printt: print("") addVarStr = ', '.join( [colorFormat.p % k for k in addDic if k not in same]) if addVarStr: print(colorFormat.b % '\nVars add to Root Frame by out: ' + '\n└── ' + addVarStr) if len(same): print(colorFormat.r % '\nVars that replaced by out in Root Frame: ' + '\n└── ' + ', '.join([colorFormat.p % k for k in same])) root.f_globals.update(addDic) lc.c = lc.code = code lc.f = lc.frame = frame lc.l = lc.local = local self.clear() self.update(local)
def __exit__(self, typee, value, traceback): f = sys._getframe(self.deep + 1) ind = id(f) locsb = self.locs[ind].pop() locs = f.f_locals kvs = [] newVars = [] for k in locs: if k in locsb: if not (locsb[k] is locs[k]): kvs.append((k, locs[k])) else: kvs.append((k, locs[k])) newVars.append(k) if self.transport: root = getRootFrame() root.f_locals.update(kvs) printf = lambda *l, **kv: 0 if self.printt: printf = log printf("") printf(colorFormat.b % 'withprint from %s' % prettyFrameLocation(f)) if len(kvs): tag = '' if locs.get('__name__') == '__main__': printf(colorFormat.b % 'New Vars: ', end='') if len(newVars): printf((', '.join([colorFormat.p % k for k in newVars]))) else: printf((colorFormat.b % 'None')) tag = ( "\nP.S. code run in __main__, some vars may not detected if id(var) not change." ) printf((colorFormat.b % "All Vars's Values :" )) #(P.S.some base object may not detected):")) if self.printt: from boxx import tree tree(dict(kvs)) tag and printf(tag) else: print(( colorFormat.r % '\n\nNot detected any Vars:' + '\n id(var) may not change in interactive mod if var is int and < 256 \n' + ' `help(withprint)` for more infomation\n' + ' P.S assignment self is not work for with statement.\n' + ' Instead, `new_var = old_var` is OK!'))
def __exit__(self, typee, value, traceback): f = sys._getframe(1) ind = id(f) locsb = self.locs[ind].pop() locs = f.f_locals kvs = [] newVars = [] for k in locs: if k in locsb: if not (locsb[k] is locs[k]): kvs.append((k, locs[k])) else: kvs.append((k, locs[k])) newVars.append(k) print("") from .toolTools import increase count = increase('boxxx.withprint id:%s' % id(self)) if count: print(colorFormat.p % (str(count + 1) + 'st') + colorFormat.b % ' times ', end='') print(colorFormat.b % 'withprint from %s' % prettyFrameLocation(f)) if len(kvs): print(colorFormat.b % 'New Vars: ', end='') if len(newVars): print((', '.join([colorFormat.p % k for k in newVars]))) else: print((colorFormat.b % 'None')) print( (colorFormat.b % "All Vars's Values (ps.some base object may not detected):")) from boxx import tree tree(dict(kvs)) else: print(( colorFormat.r % 'No detected any Vars:' + '\n id(var) may not change in interactive mod if var is int and < 256 \n' + ' `help(withprint)` for more infomation'))
# gtdf['level'] = gtdf.image_id.apply(lambda idd: imgdf.loc[idd]['level']) gtdf['fname'] = gtdf.image_id.apply( lambda idd: imgdf.loc[idd]['file_name']) rebboxs = loadjson(resJsp) redf = pd.DataFrame(rebboxs) redf = redf[redf.score > thre] redf = redf[redf.image_id.isin(imgIds)] redf['fname'] = redf.image_id.apply( lambda idd: imgdf.loc[idd]['file_name']) # TODO reImgIds = set(redf.image_id) if imgIds - reImgIds: print("less in bbox.json") tree(imgIds - reImgIds) gtdf = gtdf[gtdf.image_id.isin(reImgIds)] def getCnNameByCatId(catId, ): return skuDf.loc[catId - 1]['name'] def getCounter(name, all=False): imgId = imgdf[imgdf.file_name.apply(lambda x: name in x)].iloc[0].id gt, re = Counter(gtdf[gtdf.image_id == imgId].category_id.apply( getCnNameByCatId)), Counter( redf[redf.image_id == imgId].category_id.apply(getCnNameByCatId)) if all: return gt, re return gt - re, re - gt
def get_default_cfg(): return cfg.clone() def get_arguments(): parser = argparse.ArgumentParser( description="Build synthetic dataset by bpycv") parser.add_argument("--config", type=str, default=None, help="config file path") parser.add_argument( "opts", help="Modify config options using the command-line", default=None, nargs=argparse.REMAINDER, ) argv_for_py = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else [] args = parser.parse_args(argv_for_py) return args if __name__ == "__main__": from boxx import tree args = get_arguments() cfg = get_default_cfg() cfg.merge_from_list_or_str(args.opts) tree(cfg)