Exemplo n.º 1
0
def make_datasets(dataset_cls, filenames):
    """Creates instances of :obj:`dataset_cls`.

    Args:
      dataset_cls: A class inheriting from ``tf.data.Dataset``.
      filenames: A list of filenames or a single filename.

    Returns:
      A list of ``tf.data.Dataset`` instances if multiple :obj:`filenames` are
      passed, otherwise a single ``tf.data.Dataset``.

    Raises:
      ValueError: if :obj:`filenames` is empty.
    """
    if not isinstance(filenames, list):
        filenames = [filenames]
    elif not filenames:
        raise ValueError("At least one data file is required")
    datasets = [
        dataset_cls(
            filename,
            compression_type="GZIP" if misc.is_gzip_file(filename) else None)
        for filename in filenames
    ]
    if len(datasets) == 1:
        return datasets[0]
    return datasets
 def make_dataset(self, data_file, training=None):
   return tf.data.TextLineDataset(
       data_file, compression_type="GZIP" if misc.is_gzip_file(data_file) else None)