Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
316 views
in Technique[技术] by (71.8m points)

python - Tfrecords parsing confusion

Here I try to get audio and label from raw_dataset(tfrec)

feature_description = {
    'recording_id': tf.io.FixedLenFeature([], tf.string, default_value=''),
    'audio_wav': tf.io.FixedLenFeature([], tf.string, default_value=''),
    'label_info': tf.io.FixedLenFeature([], tf.string, default_value='')
}

def _parse_function(example_proto):
  # Parse the input `tf.train.Example` proto using the dictionary above.
    example = tf.io.parse_single_example(example_proto, feature_description)
    wav = example['audio_wav']
     #here error occurs
    label = example['label_info'].numpy()
    decoded_audio = decode_audio(wav)
    decoded_label = tf.constant(process_label(label))
    return decoded_audio,decoded_label
    

AUTOTUNE = tf.data.experimental.AUTOTUNE
parsed_dataset = raw_dataset.map(_parse_function,AUTOTUNE)

This shows me error 'Tensor' object has no attribute 'numpy'

But when I do this:

label = []
for item in raw_dataset:
    label.append(process_label(item['label_info'].numpy()))

it works How can I solve this issue


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.7k users

...