(self, gen_be=True)
return args
Parse the command line arguments and setup neon
        runtime environment accordingly

        Arguments:
            gen_be (bool): if False, the arg parser will not
                           generate the backend

        Returns:
            namespace: contains the parsed arguments as attributes
Parse the command line arguments and setup neon
        runtime environment accordingly
Parse the command line arguments and setup neon runtime environment accordingly
def parse_args(self, gen_be=True):
        """
        Parse the command line arguments and setup neon
        runtime environment accordingly

        Arguments:
            gen_be (bool): if False, the arg parser will not
                           generate the backend

        Returns:
            namespace: contains the parsed arguments as attributes

        """
        args = super(NeonArgparser, self).parse_args()
        err_msg = None  # used for relaying exception to logger

        # set up the logging
        # max thresh is 50 (critical only), min is 10 (debug or higher)
        try:
            log_thresh = max(10, 40 - args.verbose * 10)
        except (AttributeError, TypeError):
            # if defaults are not set or not -v given
            # for latter will get type error
            log_thresh = 30
        args.log_thresh = log_thresh

        # logging formater
        fmtr = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')

        # get the parent logger for neon
        main_logger = logging.getLogger('neon')
        main_logger.setLevel(log_thresh)

        # setup a console stderr log handler
        stderrlog = logging.StreamHandler()
        stderrlog.setFormatter(fmtr)

        # expand any user directories in paths
        for path in ['data_dir', 'save_path', 'model_file', 'output_file',
                     'logfile']:
            if getattr(args, path):
                setattr(args, path, os.path.expanduser(getattr(args, path)))

        if args.logfile:
            # add log to file as well
            filelog = RotatingFileHandler(filename=args.logfile, mode='w',
                                          maxBytes=10000000, backupCount=5)
            filelog.setFormatter(fmtr)
            filelog.setLevel(log_thresh)
            main_logger.addHandler(filelog)

            # if a log file is specified and progress bar displayed,
            # log only errors to console.
            if args.no_progress_bar:
                stderrlog.setLevel(log_thresh)
            else:
                stderrlog.setLevel(logging.ERROR)
        else:
            stderrlog.setLevel(log_thresh)

        # add this handler instead
        main_logger.propagate = False
        main_logger.addHandler(stderrlog)

        # need to write out float otherwise numpy
        # generates type in bytes not bits (f16 == 128 bits)
        args.datatype = 'float' + args.datatype[1:]
        args.datatype = np.dtype(args.datatype).type

        # invert no_progress_bar meaning and store in args.progress_bar
        args.progress_bar = not args.no_progress_bar

        if args.backend == 'cpu' and args.rounding > 0:
            err_msg = 'CPU backend does not support stochastic rounding'
            logger.exception(err_msg)
            raise NotImplementedError(err_msg)

        # done up front to avoid losing data due to incorrect path
        if args.save_path:
            savedir = os.path.dirname(os.path.abspath(args.save_path))
            if not os.access(savedir, os.R_OK | os.W_OK):
                try:
                    os.makedirs(savedir)
                except OSError:
                    err_msg = 'Can not create save_path %s' % (savedir)
            if os.path.exists(args.save_path):
                logger.warning('save file %s exists, attempting to overwrite' % args.save_path)
                if not os.access(args.save_path, os.R_OK | os.W_OK):
                    err_msg = 'Can not write to save_path file %s' % args.save_path
            if err_msg:
                logger.exception(err_msg)
                raise IOError(err_msg)

        if (args.serialize > 0) and (args.save_path is None):
            args.save_path = "neon_model.pkl"
            logger.warn('No path given for model serialization, using default "%s"',
                        args.save_path)
        if (args.save_path is not None) and (args.serialize == 0):
            args.serialize = 1
            logger.warn('No schedule given for model serialization, using default %d',
                        args.serialize)

        if args.model_file:
            err_msg = None
            if not os.path.exists(args.model_file):
                err_msg = 'Model file %s not present' % args.model_file
            if not os.access(args.model_file, os.R_OK):
                err_msg = 'No read access for model file %s' % args.model_file
            if err_msg:
                logger.exception(err_msg)
                raise IOError(err_msg)

        if args.caffe:
            args.compat_mode = 'caffe'
        else:
            args.compat_mode = None

        if args.deterministic:
            logger.warn('--deterministic flag is deprecated.  Specify random seed for '
                        'deterministic behavior.')
        # extended parsers may need to generate backend after argparsing
        if gen_be:
            # generate the backend
            gen_backend(backend=args.backend,
                        rng_seed=args.rng_seed,
                        device_id=args.device_id,
                        batch_size=args.batch_size,
                        datatype=args.datatype,
                        max_devices=args.max_devices,
                        compat_mode=args.compat_mode)

        # display what command line / config options were set (and from where)
        logger.info(self.format_values())

        if args.manifest:
            args.manifest = {k: v for k, v in [ss.split(':') for ss in args.manifest]}

        self._PARSED = True
        self.args = args
        args.callback_args = extract_valid_args(args, Callbacks.__init__, startidx=1)
        return args
def parse_args ( self , gen_be = True ) : args = super ( NeonArgparser , self ) . parse_args ( ) err_msg = None # used for relaying exception to logger # set up the logging # max thresh is 50 (critical only), min is 10 (debug or higher) try : log_thresh = max ( 10 , 40 - args . verbose * 10 ) except ( AttributeError , TypeError ) : # if defaults are not set or not -v given # for latter will get type error log_thresh = 30 args . log_thresh = log_thresh # logging formater fmtr = logging . Formatter ( '%(asctime)s - %(name)s - %(levelname)s - %(message)s' ) # get the parent logger for neon main_logger = logging . getLogger ( 'neon' ) main_logger . setLevel ( log_thresh ) # setup a console stderr log handler stderrlog = logging . StreamHandler ( ) stderrlog . setFormatter ( fmtr ) # expand any user directories in paths for path in [ 'data_dir' , 'save_path' , 'model_file' , 'output_file' , 'logfile' ] : if getattr ( args , path ) : setattr ( args , path , os . path . expanduser ( getattr ( args , path ) ) ) if args . logfile : # add log to file as well filelog = RotatingFileHandler ( filename = args . logfile , mode = 'w' , maxBytes = 10000000 , backupCount = 5 ) filelog . setFormatter ( fmtr ) filelog . setLevel ( log_thresh ) main_logger . addHandler ( filelog ) # if a log file is specified and progress bar displayed, # log only errors to console. if args . no_progress_bar : stderrlog . setLevel ( log_thresh ) else : stderrlog . setLevel ( logging . ERROR ) else : stderrlog . setLevel ( log_thresh ) # add this handler instead main_logger . propagate = False main_logger . addHandler ( stderrlog ) # need to write out float otherwise numpy # generates type in bytes not bits (f16 == 128 bits) args . datatype = 'float' + args . datatype [ 1 : ] args . datatype = np . dtype ( args . datatype ) . type # invert no_progress_bar meaning and store in args.progress_bar args . progress_bar = not args . no_progress_bar if args . backend == 'cpu' and args . rounding > 0 : err_msg = 'CPU backend does not support stochastic rounding' logger . exception ( err_msg ) raise NotImplementedError ( err_msg ) # done up front to avoid losing data due to incorrect path if args . save_path : savedir = os . path . dirname ( os . path . abspath ( args . save_path ) ) if not os . access ( savedir , os . R_OK | os . W_OK ) : try : os . makedirs ( savedir ) except OSError : err_msg = 'Can not create save_path %s' % ( savedir ) if os . path . exists ( args . save_path ) : logger . warning ( 'save file %s exists, attempting to overwrite' % args . save_path ) if not os . access ( args . save_path , os . R_OK | os . W_OK ) : err_msg = 'Can not write to save_path file %s' % args . save_path if err_msg : logger . exception ( err_msg ) raise IOError ( err_msg ) if ( args . serialize > 0 ) and ( args . save_path is None ) : args . save_path = "neon_model.pkl" logger . warn ( 'No path given for model serialization, using default "%s"' , args . save_path ) if ( args . save_path is not None ) and ( args . serialize == 0 ) : args . serialize = 1 logger . warn ( 'No schedule given for model serialization, using default %d' , args . serialize ) if args . model_file : err_msg = None if not os . path . exists ( args . model_file ) : err_msg = 'Model file %s not present' % args . model_file if not os . access ( args . model_file , os . R_OK ) : err_msg = 'No read access for model file %s' % args . model_file if err_msg : logger . exception ( err_msg ) raise IOError ( err_msg ) if args . caffe : args . compat_mode = 'caffe' else : args . compat_mode = None if args . deterministic : logger . warn ( '--deterministic flag is deprecated.  Specify random seed for ' 'deterministic behavior.' ) # extended parsers may need to generate backend after argparsing if gen_be : # generate the backend gen_backend ( backend = args . backend , rng_seed = args . rng_seed , device_id = args . device_id , batch_size = args . batch_size , datatype = args . datatype , max_devices = args . max_devices , compat_mode = args . compat_mode ) # display what command line / config options were set (and from where) logger . info ( self . format_values ( ) ) if args . manifest : args . manifest = { k : v for k , v in [ ss . split ( ':' ) for ss in args . manifest ] } self . _PARSED = True self . args = args args . callback_args = extract_valid_args ( args , Callbacks . __init__ , startidx = 1 ) return args