示例#1
0
def load_dataset_wavegan():
    """Load WaveGAN's dataset.

  The loaded dataset consists of:
    - original data (dataset_blob, train_data, train_label),
    - encoded data from a pretrained model (train_mu, train_sigma), and
    - index grouped by label (index_grouped_by_label).

  Some of these attributes are not avaiable (set as None) but are left here
  to keep everything aligned with returned value of `load_dataset`.

  Returns:
    An tuple of abovementioned components in the dataset.
  """

    latent_dir = os.path.expanduser(FLAGS.wavegan_latent_dir)
    path_train = os.path.join(latent_dir, 'data_train.npz')
    train = np.load(path_train)
    train_z = train['z']
    train_label = train['label']
    index_grouped_by_label = common.get_index_grouped_by_label(train_label)

    dataset_blob, train_data = None, None
    train_mu, train_sigma = train_z, None
    return (dataset_blob, train_data, train_label, train_mu, train_sigma,
            index_grouped_by_label)
示例#2
0
def load_dataset_wavegan():
  """Load WaveGAN's dataset.

  The loaded dataset consists of:
    - original data (dataset_blob, train_data, train_label),
    - encoded data from a pretrained model (train_mu, train_sigma), and
    - index grouped by label (index_grouped_by_label).

  Some of these attributes are not avaiable (set as None) but are left here
  to keep everything aligned with returned value of `load_dataset`.

  Returns:
    An tuple of abovementioned components in the dataset.
  """

  latent_dir = os.path.expanduser(FLAGS.wavegan_latent_dir)
  path_train = os.path.join(latent_dir, 'data_train.npz')
  train = np.load(path_train)
  train_z = train['z']
  train_label = train['label']
  index_grouped_by_label = common.get_index_grouped_by_label(train_label)

  dataset_blob, train_data = None, None
  train_mu, train_sigma = train_z, None
  return (dataset_blob, train_data, train_label, train_mu, train_sigma,
          index_grouped_by_label)
示例#3
0
def load_dataset(config_name, exp_uid):
    """Load a dataset from a config's name.

  The loaded dataset consists of:
    - original data (dataset_blob, train_data, train_label),
    - encoded data from a pretrained model (train_mu, train_sigma), and
    - index grouped by label (index_grouped_by_label).

  Args:
    config_name: A string indicating the name of config to parameterize the
        model that associates with the dataset.
    exp_uid: A string representing the unique id of experiment to be used in
        model that associates with the dataset.

  Returns:
    An tuple of abovementioned components in the dataset.
  """

    config = load_config(config_name)
    if config_is_wavegan(config):
        return load_dataset_wavegan()

    model_uid = common.get_model_uid(config_name, exp_uid)

    dataset = common.load_dataset(config)
    train_data = dataset.train_data
    attr_train = dataset.attr_train
    path_train = os.path.join(dataset.basepath, 'encoded', model_uid,
                              'encoded_train_data.npz')
    train = np.load(path_train)
    train_mu = train['mu']
    train_sigma = train['sigma']
    train_label = np.argmax(attr_train, axis=-1)  # from one-hot to label
    index_grouped_by_label = common.get_index_grouped_by_label(train_label)

    tf.logging.info('index_grouped_by_label size: %s',
                    [len(_) for _ in index_grouped_by_label])

    tf.logging.info('train loaded from %s', path_train)
    tf.logging.info('train shapes: mu = %s, sigma = %s', train_mu.shape,
                    train_sigma.shape)
    dataset_blob = dataset
    return (dataset_blob, train_data, train_label, train_mu, train_sigma,
            index_grouped_by_label)
示例#4
0
def load_dataset(config_name, exp_uid):
  """Load a dataset from a config's name.

  The loaded dataset consists of:
    - original data (dataset_blob, train_data, train_label),
    - encoded data from a pretrained model (train_mu, train_sigma), and
    - index grouped by label (index_grouped_by_label).

  Args:
    config_name: A string indicating the name of config to parameterize the
        model that associates with the dataset.
    exp_uid: A string representing the unique id of experiment to be used in
        model that associates with the dataset.

  Returns:
    An tuple of abovementioned components in the dataset.
  """

  config = load_config(config_name)
  if config_is_wavegan(config):
    return load_dataset_wavegan()

  model_uid = common.get_model_uid(config_name, exp_uid)

  dataset = common.load_dataset(config)
  train_data = dataset.train_data
  attr_train = dataset.attr_train
  path_train = os.path.join(dataset.basepath, 'encoded', model_uid,
                            'encoded_train_data.npz')
  train = np.load(path_train)
  train_mu = train['mu']
  train_sigma = train['sigma']
  train_label = np.argmax(attr_train, axis=-1)  # from one-hot to label
  index_grouped_by_label = common.get_index_grouped_by_label(train_label)

  tf.logging.info('index_grouped_by_label size: %s',
                  [len(_) for _ in index_grouped_by_label])

  tf.logging.info('train loaded from %s', path_train)
  tf.logging.info('train shapes: mu = %s, sigma = %s', train_mu.shape,
                  train_sigma.shape)
  dataset_blob = dataset
  return (dataset_blob, train_data, train_label, train_mu, train_sigma,
          index_grouped_by_label)