0

tensorflow 的例子是 https://www.tensorflow.org/tutorials/audio/simple_audio

我想知道file_path这个例子中的如下:

def get_waveform_and_label(file_path):
  label = get_label(file_path)
  audio_binary = tf.io.read_file(file_path)
  waveform = decode_audio(audio_binary)
  return waveform, label

'file_path' 在函数中被调用如下:

waveform_ds = files_ds.map(get_waveform_and_label, num_parallel_calls=AUTOTUNE)

我尝试使用 获取 file_path 的值print(file_path),但答案是Tensor("args_0:0", shape=(), dtype=string).

这不是 file_path 的确切值。

最后,我不知道 中的file_path和输入参数的get_waveform_and_labelwaveform_ds = files_ds.map(get_waveform_and_label, num_parallel_calls=AUTOTUNE)

4

1 回答 1

-1

我一直陷入同样的​​问题,但我想我明白了:

file_path来自file_ds变量,其中file_ds 可能代表一大组元素”,其中每个元素是每个 wav 的“文件路径”。文件。

设置train_files变量后,运行以下命令以了解我的意思。

file_ds = tf.data.Dataset.from_tensor_slices(train_files)
for element in dataset:
  print(element)

那么当你使用地图功能时

file_ds.map(get_waveform_and_label)

它将函数get_waveform_and_label应用于大集合的每个元素,在这种情况下,应用于每个 wav 文件。

参考资料:https ://www.tensorflow.org/api_docs/python/tf/data/Dataset

于 2021-05-23T03:58:30.567 回答