(params_dir, param_names)
Gets the first found value from `param_names` in `params_dir`.
Gets the first found value from `param_names` in `params_dir`.
Gets the first found value from param_names in params_dir .
def get_value_from_params_dir(params_dir, param_names):
  """Gets the first found value from `param_names` in `params_dir`."""

  def _load_params(param_name, params_file, loader, mode):
    with tf.io.gfile.GFile(params_file, mode) as f:
      params = loader(f)
    logging.info('Found params file %s', params_file)
    return params[param_name]

  for param_name in param_names:
    try:
      try:
        return _load_params(param_name, os.path.join(params_dir, 'params.json'),
                            json.load, 'r')
      except tf.errors.NotFoundError:
        logging.info('%s does not exist in %s', 'params.json', params_dir)

      try:
        return _load_params(param_name, os.path.join(params_dir, 'params.pkl'),
                            pkl.load, 'rb')
      except tf.errors.NotFoundError:
        logging.info('%s does not exist in %s', 'params.pkl', params_dir)

    except KeyError:
      pass

  raise ValueError('Did not find any of the following keys: %s' % param_names)
def get_value_from_params_dir ( params_dir , param_names ) : def _load_params ( param_name , params_file , loader , mode ) : with tf . io . gfile . GFile ( params_file , mode ) as f : params = loader ( f ) logging . info ( 'Found params file %s' , params_file ) return params [ param_name ] for param_name in param_names : try : try : return _load_params ( param_name , os . path . join ( params_dir , 'params.json' ) , json . load , 'r' ) except tf . errors . NotFoundError : logging . info ( '%s does not exist in %s' , 'params.json' , params_dir ) try : return _load_params ( param_name , os . path . join ( params_dir , 'params.pkl' ) , pkl . load , 'rb' ) except tf . errors . NotFoundError : logging . info ( '%s does not exist in %s' , 'params.pkl' , params_dir ) except KeyError : pass raise ValueError ( 'Did not find any of the following keys: %s' % param_names )