def main(): parser = argparse.ArgumentParser(description='Text Recognition Training') parser.add_argument('exp', type=str) parser.add_argument('--resume', type=str, help='Resume from checkpoint') parser.add_argument('--image_path', type=str, help='image path') parser.add_argument('--result_dir', type=str, default='./demo_results/', help='path to save results') parser.add_argument('--data', type=str, help='The name of dataloader which will be evaluated on.') parser.add_argument('--image_short_side', type=int, default=736, help='The threshold to replace it in the representers') parser.add_argument('--thresh', type=float, help='The threshold to replace it in the representers') parser.add_argument('--box_thresh', type=float, default=0.6, help='The threshold to replace it in the representers') parser.add_argument('--visualize', action='store_true', help='visualize maps in tensorboard') parser.add_argument('--resize', action='store_true', help='resize') parser.add_argument('--polygon', action='store_true', help='output polygons if true') parser.add_argument('--eager', '--eager_show', action='store_true', dest='eager_show', help='Show iamges eagerly') args = parser.parse_args() args = vars(args) args = {k: v for k, v in args.items() if v is not None} conf = Config() experiment_args = conf.compile(conf.load(args['exp']))['Experiment'] experiment_args.update(cmd=args) experiment = Configurable.construct_class_from_config(experiment_args) Demo(experiment, experiment_args, cmd=args).inference(args['image_path'], args['visualize'])
def main(): parser = argparse.ArgumentParser(description='Text Recognition Training') parser.add_argument('--exp', type=str, default=exp) parser.add_argument('--resume', type=str, help='Resume from checkpoint', default=ckpt_path) parser.add_argument('--result_dir', type=str, default='./demo_results/', help='path to save results') parser.add_argument('--data', type=str, help='The name of dataloader which will be evaluated on.') parser.add_argument('--image_short_side', type=int, default=img_short_side, help='The threshold to replace it in the representers') parser.add_argument('--thresh', type=float, help='The threshold to replace it in the representers') parser.add_argument('--box_thresh', type=float, default=detector_box_thres, help='The threshold to replace it in the representers') parser.add_argument('--resize', action='store_true', help='resize') parser.add_argument('--visualize', default=visualize, help='visualize maps in tensorboard') parser.add_argument('--polygon', help='output polygons if true', default=polygon) parser.add_argument('--eager', '--eager_show', action='store_true', dest='eager_show', help='Show iamges eagerly') args = parser.parse_args() args = vars(args) args = {k: v for k, v in args.items() if v is not None} conf = Config() experiment_args = conf.compile(conf.load(args['exp']))['Experiment'] experiment_args.update(cmd=args) experiment = Configurable.construct_class_from_config(experiment_args) detector = Demo(experiment, experiment_args, gpu=gpu_test, cmd=args) begin = time.time() detector.inference2(img_path, args['visualize']) end = time.time() print ( 'Exe time:',end-begin,'seconds')
def main(): parser = argparse.ArgumentParser(description='Text Recognition Training') parser.add_argument('exp', type=str) parser.add_argument('--name', type=str) parser.add_argument('--batch_size', type=int, help='Batch size for training') parser.add_argument('--resume', type=str, help='Resume from checkpoint') parser.add_argument('--epochs', type=int, help='Number of training epochs') parser.add_argument('--num_workers', type=int, help='Number of dataloader workers') parser.add_argument('--start_iter', type=int, help='Begin counting iterations starting from this value (should be used with resume)') parser.add_argument('--start_epoch', type=int, help='Begin counting epoch starting from this value (should be used with resume)') parser.add_argument('--max_size', type=int, help='max length of label') parser.add_argument('--lr', type=float, help='initial learning rate') parser.add_argument('--optimizer', type=str, help='The optimizer want to use') parser.add_argument('--thresh', type=float, help='The threshold to replace it in the representers') parser.add_argument('--verbose', action='store_true', help='show verbose info') parser.add_argument('--visualize', action='store_true', help='visualize maps in tensorboard') parser.add_argument('--force_reload', action='store_true', dest='force_reload', help='Force reload data meta') parser.add_argument('--no-force_reload', action='store_false', dest='force_reload', help='Force reload data meta') parser.add_argument('--validate', action='store_true', dest='validate', help='Validate during training') parser.add_argument('--no-validate', action='store_false', dest='validate', help='Validate during training') parser.add_argument('--print-config-only', action='store_true', help='print config without actual training') parser.add_argument('--debug', action='store_true', dest='debug', help='Run with debug mode, which hacks dataset num_samples to toy number') parser.add_argument('--no-debug', action='store_false', dest='debug', help='Run without debug mode') parser.add_argument('--benchmark', action='store_true', dest='benchmark', help='Open cudnn benchmark mode') parser.add_argument('--no-benchmark', action='store_false', dest='benchmark', help='Turn cudnn benchmark mode off') parser.add_argument('-d', '--distributed', action='store_true', dest='distributed', help='Use distributed training') parser.add_argument('--local_rank', dest='local_rank', default=0, type=int, help='Use distributed training') parser.add_argument('-g', '--num_gpus', dest='num_gpus', default=4, type=int, help='The number of accessible gpus') parser.set_defaults(debug=False) parser.set_defaults(benchmark=True) args = parser.parse_args() args = vars(args) args = {k: v for k, v in args.items() if v is not None} # Torch分布式训练,据称即使是单电脑多卡,也比data_parallel快,使用nccl后端(需要部署) if args['distributed']: torch.cuda.set_device(args['local_rank']) torch.distributed.init_process_group(backend='nccl', init_method='env://') conf = Config() # 通过yaml文件,生成对应的配置参数,experiment里包含了name,class,structure,train,validation,logger,evaluation(=valid)信息 experiment_args = conf.compile(conf.load(args['exp']))['Experiment'] # 使用命令行参数覆盖一些默认参数,也就是命令行参数优先级高于默认参数 experiment_args.update(cmd=args) # 通过参数表构筑实验,experiment里包含distributed,local_rank(分布式时有用),evaluation(训练时为空),logger,states,structure,train,validation experiment = Configurable.construct_class_from_config(experiment_args) if not args['print_config_only']: torch.backends.cudnn.benchmark = args['benchmark'] # 构筑训练器 trainer = Trainer(experiment) # 开始训练 trainer.train()
def main(): parser = argparse.ArgumentParser(description='Text Recognition Training') parser.add_argument('--exp', type=str, default=config_file) parser.add_argument('--name', type=str, default=training_dir) parser.add_argument('--batch_size', type=int, help='Batch size for training') parser.add_argument('--resume', type=str, default=resume_ckpt, help='Resume from checkpoint') parser.add_argument('--epochs', type=int, help='Number of training epochs') parser.add_argument('--num_workers', type=int, help='Number of dataloader workers') parser.add_argument('--start_iter', type=int, help='Begin counting iterations starting from this value (should be used with resume)') parser.add_argument('--start_epoch', type=int, help='Begin counting epoch starting from this value (should be used with resume)') parser.add_argument('--max_size', type=int, help='max length of label') parser.add_argument('--lr', type=float, help='initial learning rate') parser.add_argument('--optimizer', type=str, help='The optimizer want to use') parser.add_argument('--thresh', type=float, help='The threshold to replace it in the representers') parser.add_argument('--verbose', action='store_true', help='show verbose info') parser.add_argument('--visualize', action='store_true', help='visualize maps in tensorboard') parser.add_argument('--force_reload', action='store_true', dest='force_reload', help='Force reload data meta') parser.add_argument('--no-force_reload', action='store_false', dest='force_reload', help='Force reload data meta') parser.add_argument('--validate', action='store_true', dest='validate', help='Validate during training') parser.add_argument('--no-validate', action='store_false', dest='validate', help='Validate during training') parser.add_argument('--print-config-only', action='store_true', help='print config without actual training') parser.add_argument('--debug', action='store_true', dest='debug', help='Run with debug mode, which hacks dataset num_samples to toy number') parser.add_argument('--no-debug', action='store_false', dest='debug', help='Run without debug mode') parser.add_argument('--benchmark', action='store_true', dest='benchmark', help='Open cudnn benchmark mode') parser.add_argument('--no-benchmark', action='store_false', dest='benchmark', help='Turn cudnn benchmark mode off') parser.add_argument('-d', '--distributed', action='store_true', dest='distributed', help='Use distributed training') parser.add_argument('--local_rank', dest='local_rank', default=0, type=int, help='Use distributed training') parser.add_argument('-gpu_num', '--num_gpus', dest='num_gpus', default=1, type=int, help='The number of accessible gpus') parser.set_defaults(debug=False) parser.set_defaults(benchmark=True) args = parser.parse_args() args = vars(args) args = {k: v for k, v in args.items() if v is not None} if args['distributed']: torch.cuda.set_device(args['local_rank']) torch.distributed.init_process_group(backend='nccl', init_method='env://') conf = Config() experiment_args = conf.compile(conf.load(args['exp']))['Experiment'] experiment_args.update(cmd=args) experiment = Configurable.construct_class_from_config(experiment_args) if not args['print_config_only']: torch.backends.cudnn.benchmark = args['benchmark'] trainer = Trainer(experiment) trainer.train()
def main(): parser = argparse.ArgumentParser(description='Text Recognition Training') parser.add_argument('exp', type=str) parser.add_argument('--resume', type=str, help='Resume from checkpoint') parser.add_argument('--image_path', type=str, help='image path') parser.add_argument('--result_dir', type=str, default='./demo_results/', help='path to save results') parser.add_argument('--data', type=str, help='The name of dataloader which will be evaluated on.') parser.add_argument('--image_short_side', type=int, default=736, help='The threshold to replace it in the representers') parser.add_argument('--thresh', type=float, help='The threshold to replace it in the representers') parser.add_argument('--box_thresh', type=float, default=0.6, help='The threshold to replace it in the representers') parser.add_argument('--visualize', action='store_true', help='visualize maps in tensorboard') parser.add_argument('--resize', action='store_true', help='resize') parser.add_argument('--polygon', action='store_true', help='output polygons if true') parser.add_argument('--eager', '--eager_show', action='store_true', dest='eager_show', help='Show images eagerly') parser.add_argument('--sort_boxes', action='store_true', dest='sort_boxes', help='Sort boxes for further works') args = parser.parse_args() args = vars(args) args = {k: v for k, v in args.items() if v is not None} conf = Config() experiment_args = conf.compile(conf.load(args['exp']))['Experiment'] experiment_args.update(cmd=args) # Delete train settings, prevent of reading training dataset experiment_args.pop('train') experiment_args.pop('evaluation') experiment_args.pop('validation') experiment = Configurable.construct_class_from_config(experiment_args) demo_handler = Demo(experiment, experiment_args, cmd=args) if os.path.isdir(args['image_path']): img_cnt = len(os.listdir(args['image_path'])) for idx, img in enumerate(os.listdir(args['image_path'])): if os.path.splitext(img)[1].lower() not in ['.jpg', '.tif', '.png', '.jpeg']: continue t = time.time() demo_handler.inference(os.path.join(args['image_path'], img), args['visualize']) print("{}/{} elapsed time : {:.4f}s".format(idx + 1, img_cnt, time.time() - t)) else: t = time.time() demo_handler.inference(args['image_path'], args['visualize']) print("elapsed time : {}s".format(time.time() - t))
def main(): parser = argparse.ArgumentParser(description='Convert model to ONNX') parser.add_argument('exp', type=str) parser.add_argument('resume', type=str, help='Resume from checkpoint') parser.add_argument('output', type=str, help='Output ONNX path') args = parser.parse_args() args = vars(args) args = {k: v for k, v in args.items() if v is not None} conf = Config() experiment_args = conf.compile(conf.load(args['exp']))['Experiment'] experiment_args.update(cmd=args) experiment = Configurable.construct_class_from_config(experiment_args) Demo(experiment, experiment_args, cmd=args).inference()
def __init__(self, args=params): self.RGB_MEAN = np.array([122.67891434, 116.66876762, 104.00698793]) conf = Config() experiment_args = conf.compile(conf.load(args['exp']))['Experiment'] experiment_args.update(cmd=args) self.experiment = Configurable.construct_class_from_config( experiment_args) self.experiment.load('evaluation', **args) self.args = args self.structure = self.experiment.structure self.model_path = args['resume'] self.init_torch_tensor() self.model = self.init_model() self.resume(self.model, self.model_path) self.model.eval()
def main(): parser = argparse.ArgumentParser(description='Text Recognition Training') parser.add_argument('exp', type=str) parser.add_argument('--batch_size', type=int, help='Batch size for training') parser.add_argument('--resume', type=str, help='Resume from checkpoint') parser.add_argument('--result_dir', type=str, default='./results/', help='path to save results') parser.add_argument('--epochs', type=int, help='Number of training epochs') parser.add_argument( '--start_iter', type=int, help= 'Begin counting iterations starting from this value (should be used with resume)' ) parser.add_argument( '--start_epoch', type=int, help= 'Begin counting epoch starting from this value (should be used with resume)' ) parser.add_argument('--max_size', type=int, help='max length of label') parser.add_argument( '--data', type=str, help='The name of dataloader which will be evaluated on.') parser.add_argument('--thresh', type=float, help='The threshold to replace it in the representers') parser.add_argument('--box_thresh', type=float, default=0.6, help='The threshold to replace it in the representers') parser.add_argument('--verbose', action='store_true', help='show verbose info') parser.add_argument('--no-verbose', action='store_true', help='show verbose info') parser.add_argument('--visualize', action='store_true', help='visualize maps in tensorboard') parser.add_argument('--resize', action='store_true', help='resize') parser.add_argument('--polygon', action='store_true', help='output polygons if true') parser.add_argument('--eager', '--eager_show', action='store_true', dest='eager_show', help='Show iamges eagerly') parser.add_argument('--speed', action='store_true', dest='test_speed', help='Test speed only') parser.add_argument( '--dest', type=str, help='Specify which prediction will be used for decoding.') parser.add_argument( '--debug', action='store_true', dest='debug', help= 'Run with debug mode, which hacks dataset num_samples to toy number') parser.add_argument('--no-debug', action='store_false', dest='debug', help='Run without debug mode') parser.add_argument('-d', '--distributed', action='store_true', dest='distributed', help='Use distributed training') parser.add_argument('--local_rank', dest='local_rank', default=0, type=int, help='Use distributed training') parser.add_argument('-g', '--num_gpus', dest='num_gpus', default=1, type=int, help='The number of accessible gpus') parser.set_defaults(debug=False, verbose=False) args = parser.parse_args() args = vars(args) args = {k: v for k, v in args.items() if v is not None} conf = Config() experiment_args = conf.compile(conf.load(args['exp']))['Experiment'] experiment_args.update(cmd=args) experiment = Configurable.construct_class_from_config(experiment_args) Eval(experiment, experiment_args, cmd=args, verbose=args['verbose']).eval(args['visualize'])
batch = dict() batch['image'] = tensor # ===> model predict pred = model.forward(batch, training=False) return pred if __name__ == "__main__": config = "/share_sdb/clj/DB2/DB/experiments/seg_detector/ic15_resnet_vd_18.yaml" conf = Config() experiment_args = conf.compile(conf.load(config))['Experiment'] image_path = "/share_sdb/clj/paddle/img_10.jpg" args = {} args["model_path"] = "" args["image_short_side"] = "" args["result_dir"] = "/share_sdb/clj/DB/demo_results" args["polygon"] = False args["paddle_model_path"] = "/share_sdb/clj/paddle/models/ch_ppocr_server_v1.1_det_train/best_accuracy" experiment_args.update(cmd=args) experiment = Configurable.construct_class_from_config(experiment_args) pred = Demo(experiment, args).inference(image_path) print(pred) print(pred.shape)