Ejemplo n.º 1
0
def paths_and_labels_to_dataset(
    file_paths,
    labels,
    label_mode,
    num_classes,
    sampling_rate,
    output_sequence_length,
    ragged,
):
    """Constructs a fixed-size dataset of audio and labels."""
    path_ds = tf.data.Dataset.from_tensor_slices(file_paths)
    audio_ds = path_ds.map(
        lambda x: read_and_decode_audio(x, sampling_rate,
                                        output_sequence_length),
        num_parallel_calls=tf.data.AUTOTUNE,
    )

    if ragged:
        audio_ds = audio_ds.map(
            lambda x: tf.RaggedTensor.from_tensor(x),
            num_parallel_calls=tf.data.AUTOTUNE,
        )

    if label_mode:
        label_ds = dataset_utils.labels_to_dataset(labels, label_mode,
                                                   num_classes)
        audio_ds = tf.data.Dataset.zip((audio_ds, label_ds))
    return audio_ds
Ejemplo n.º 2
0
def paths_and_labels_to_dataset(file_paths, labels, label_mode, num_classes,
                                max_length):
    """Constructs a dataset of text strings and labels."""
    path_ds = tf.data.Dataset.from_tensor_slices(file_paths)
    string_ds = path_ds.map(lambda x: path_to_string_content(x, max_length),
                            num_parallel_calls=tf.data.AUTOTUNE)
    if label_mode:
        label_ds = dataset_utils.labels_to_dataset(labels, label_mode,
                                                   num_classes)
        string_ds = tf.data.Dataset.zip((string_ds, label_ds))
    return string_ds
Ejemplo n.º 3
0
def paths_and_labels_to_dataset(image_paths,
                                image_size,
                                num_channels,
                                labels,
                                label_mode,
                                num_classes,
                                interpolation,
                                crop_to_aspect_ratio=False):
    """Constructs a dataset of images and labels."""
    # TODO(fchollet): consider making num_parallel_calls settable
    path_ds = tf.data.Dataset.from_tensor_slices(image_paths)
    args = (image_size, num_channels, interpolation, crop_to_aspect_ratio)
    img_ds = path_ds.map(lambda x: load_image(x, *args),
                         num_parallel_calls=tf.data.AUTOTUNE)
    if label_mode:
        label_ds = dataset_utils.labels_to_dataset(labels, label_mode,
                                                   num_classes)
        img_ds = tf.data.Dataset.zip((img_ds, label_ds))
    return img_ds