def cli(): parser = argparse.ArgumentParser( description=__doc__, formatter_class=argparse.ArgumentDefaultsHelpFormatter, ) logs.cli(parser) nets.cli(parser) losses.cli(parser) encoder.cli(parser) optimize.cli(parser) datasets.train_cli(parser) parser.add_argument('-o', '--output', default=None, help='output file') parser.add_argument('--stride-apply', default=1, type=int, help='apply and reset gradients every n batches') parser.add_argument('--epochs', default=75, type=int, help='number of epochs to train') parser.add_argument('--freeze-base', default=0, type=int, help='number of epochs to train with frozen base') parser.add_argument('--pre-lr', type=float, default=1e-4, help='pre learning rate') parser.add_argument('--update-batchnorm-runningstatistics', default=False, action='store_true', help='update batch norm running statistics') parser.add_argument('--square-edge', default=401, type=int, help='square edge of input images') parser.add_argument('--crop-fraction', default=0.5, type=float, help='crop fraction versus rescale') parser.add_argument('--lambdas', default=[30.0, 2.0, 2.0, 50.0, 3.0, 3.0], type=float, nargs='+', help='prefactor for head losses') parser.add_argument('--ema', default=1e-3, type=float, help='ema decay constant') parser.add_argument('--debug-without-plots', default=False, action='store_true', help='enable debug but dont plot') parser.add_argument('--profile', default=None, help='enables profiling. specify path for chrome tracing file') parser.add_argument('--disable-cuda', action='store_true', help='disable CUDA') args = parser.parse_args() if args.output is None: args.output = default_output_file(args) if args.debug and 'skeleton' not in args.headnets: raise Exception('add "skeleton" as last headnet to see debug output') if args.debug_without_plots: args.debug = True # add args.device args.device = torch.device('cpu') args.pin_memory = False if not args.disable_cuda and torch.cuda.is_available(): args.device = torch.device('cuda') args.pin_memory = True return args
def cli(): parser = argparse.ArgumentParser( description=__doc__, formatter_class=argparse.ArgumentDefaultsHelpFormatter, ) nets.cli(parser) decoder.cli(parser, force_complete_pose=True) encoder.cli(parser) parser.add_argument('--output', default=None, help='output filename without file extension') parser.add_argument('-n', default=0, type=int, help='number of batches') parser.add_argument('--skip-n', default=0, type=int, help='skip n batches') parser.add_argument('--dataset', choices=('val', 'test', 'test-dev'), default='val', help='dataset to evaluate') parser.add_argument('--min-ann', default=0, type=int, help='minimum number of truth annotations') parser.add_argument('--batch-size', default=1, type=int, help='batch size') parser.add_argument('--long-edge', default=641, type=int, help='long edge of input images') parser.add_argument('--loader-workers', default=None, type=int, help='number of workers for data loading') parser.add_argument('--skip-existing', default=False, action='store_true', help='skip if output eval file exists already') parser.add_argument('--disable-cuda', action='store_true', help='disable CUDA') parser.add_argument('--write-predictions', default=False, action='store_true', help='write a json and a zip file of the predictions') parser.add_argument('--all-images', default=False, action='store_true', help='run over all images irrespective of catIds') group = parser.add_argument_group('logging') group.add_argument('--debug', default=False, action='store_true', help='print debug messages') args = parser.parse_args() logging.basicConfig() log_level = logging.INFO if not args.debug else logging.DEBUG logging.getLogger('openpifpaf').setLevel(log_level) LOG.setLevel(log_level) if args.loader_workers is None: args.loader_workers = args.batch_size if args.dataset == 'val': args.image_dir = IMAGE_DIR_VAL args.annotation_file = ANNOTATIONS_VAL elif args.dataset == 'test': args.image_dir = IMAGE_DIR_TEST args.annotation_file = ANNOTATIONS_TEST elif args.dataset == 'test-dev': args.image_dir = IMAGE_DIR_TEST args.annotation_file = ANNOTATIONS_TESTDEV else: raise Exception if args.dataset in ('test', 'test-dev' ) and not args.write_predictions and not args.debug: raise Exception('have to use --write-predictions for this dataset') if args.dataset in ('test', 'test-dev') and not args.all_images and not args.debug: raise Exception('have to use --all-images for this dataset') # add args.device args.device = torch.device('cpu') args.pin_memory = False if not args.disable_cuda and torch.cuda.is_available(): args.device = torch.device('cuda') args.pin_memory = True # generate a default output filename if args.output is None: args.output = default_output_name(args) return args
def cli(): parser = argparse.ArgumentParser( prog='python3 -m openpifpaf.train', usage='%(prog)s [options]', description=__doc__, formatter_class=argparse.ArgumentDefaultsHelpFormatter, ) parser.add_argument( '--version', action='version', version='OpenPifPaf {version}'.format(version=__version__)) parser.add_argument('-o', '--output', default=None, help='output file') parser.add_argument('--disable-cuda', action='store_true', help='disable CUDA') parser.add_argument('--ddp', default=False, action='store_true', help='[experimental] DistributedDataParallel') parser.add_argument('--local_rank', default=None, type=int, help='[experimental] for torch.distributed.launch') parser.add_argument('--no-sync-batchnorm', dest='sync_batchnorm', default=True, action='store_false', help='[experimental] in ddp, to not use syncbatchnorm') logger.cli(parser) network.Factory.cli(parser) network.losses.Factory.cli(parser) network.Trainer.cli(parser) encoder.cli(parser) optimize.cli(parser) datasets.cli(parser) show.cli(parser) visualizer.cli(parser) args = parser.parse_args() logger.configure(args, LOG) if args.log_stats: logging.getLogger('openpifpaf.stats').setLevel(logging.DEBUG) # DDP with SLURM slurm_process_id = os.environ.get('SLURM_PROCID') if args.ddp and slurm_process_id is not None: if torch.cuda.device_count() > 1: LOG.warning( 'Expected one GPU per SLURM task but found %d. ' 'Try with "srun --gpu-bind=closest ...". Still trying.', torch.cuda.device_count()) # if there is more than one GPU available, assume that other SLURM tasks # have access to the same GPUs and assign GPUs uniquely by slurm_process_id args.local_rank = (int(slurm_process_id) % torch.cuda.device_count() if torch.cuda.device_count() > 0 else 0) os.environ['RANK'] = slurm_process_id if not os.environ.get('WORLD_SIZE') and os.environ.get('SLURM_NTASKS'): os.environ['WORLD_SIZE'] = os.environ.get('SLURM_NTASKS') LOG.info('found SLURM process id: %s', slurm_process_id) LOG.info( 'distributed env: master=%s port=%s rank=%s world=%s, ' 'local rank (GPU)=%d', os.environ.get('MASTER_ADDR'), os.environ.get('MASTER_PORT'), os.environ.get('RANK'), os.environ.get('WORLD_SIZE'), args.local_rank) # add args.device args.device = torch.device('cpu') args.pin_memory = False if not args.disable_cuda and torch.cuda.is_available(): args.device = torch.device('cuda') args.pin_memory = True LOG.info('neural network device: %s (CUDA available: %s, count: %d)', args.device, torch.cuda.is_available(), torch.cuda.device_count()) # output if args.output is None: args.output = default_output_file(args) os.makedirs('outputs', exist_ok=True) network.Factory.configure(args) network.losses.Factory.configure(args) network.Trainer.configure(args) encoder.configure(args) datasets.configure(args) show.configure(args) visualizer.configure(args) return args
def cli(): parser = argparse.ArgumentParser( description=__doc__, formatter_class=argparse.ArgumentDefaultsHelpFormatter, ) logs.cli(parser) nets.cli(parser) losses.cli(parser) encoder.cli(parser) optimize.cli(parser) datasets.train_cli(parser) parser.add_argument('-o', '--output', default=None, help='output file') parser.add_argument('--stride-apply', default=1, type=int, help='apply and reset gradients every n batches') parser.add_argument('--epochs', default=75, type=int, help='number of epochs to train') parser.add_argument('--freeze-base', default=0, type=int, help='number of epochs to train with frozen base') parser.add_argument('--pre-lr', type=float, default=1e-4, help='pre learning rate') parser.add_argument('--rescale-images', type=float, default=1.0, help='overall image rescale factor') parser.add_argument('--orientation-invariant', default=False, action='store_true', help='augment with random orientations') parser.add_argument('--update-batchnorm-runningstatistics', default=False, action='store_true', help='update batch norm running statistics') parser.add_argument('--square-edge', default=401, type=int, help='square edge of input images') parser.add_argument('--ema', default=1e-3, type=float, help='ema decay constant') parser.add_argument('--disable-cuda', action='store_true', help='disable CUDA') parser.add_argument('--no-augmentation', dest='augmentation', default=True, action='store_false', help='do not apply data augmentation') group = parser.add_argument_group('debug') group.add_argument('--debug-pif-indices', default=[], nargs='+', type=int, help='indices of PIF fields to create debug plots for') group.add_argument('--debug-paf-indices', default=[], nargs='+', type=int, help='indices of PAF fields to create debug plots for') group.add_argument( '--profile', default=None, help='enables profiling. specify path for chrome tracing file') args = parser.parse_args() if args.output is None: args.output = default_output_file(args) if args.debug and 'skeleton' not in args.headnets: raise Exception('add "skeleton" as last headnet to see debug output') if args.freeze_base and args.checkpoint: raise Exception('remove --freeze-base when running from a checkpoint') if args.debug_pif_indices or args.debug_paf_indices: args.debug = True # add args.device args.device = torch.device('cpu') args.pin_memory = False if not args.disable_cuda and torch.cuda.is_available(): args.device = torch.device('cuda') args.pin_memory = True return args