Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

python - Why I can not convert this List to a Ragged Tensor?

Anyone can please help me with a tensorflow question ? I have this database of audio files, and i computed them the coresponding mel spectograms.

The audio files have different lenghts, so consequently the mel spectograms will have different shapes. Finally i'm adding all these mel spectograms in a list called " mels "

I'm trying to convert the "mels" list to a tensor, so i can add it to my tf.data.Dataset variable, but it keeps getting me the error that a non rectulangar shape can not be converted to a tensor.

So I tried to convert it to tensor using ragged tensors, but it takes waaay to long to convert the whole mel list to a ragged tensor. I tried to convert a smaller length list ( only having 3 mel spectograms ) and it took like 30 seconds to finish the convertion to a ragged tensor So for a list having like over 200 mel spectograms, would take like half an hour or something which is not ok. Is there a way to convert this mel list to a tensor ?

Here's the small part of the code in case I've done some silly mistakes

###########

def _load_spectrograms(fpaths):

fnames = []
mels = []
mags = []

for f in fpaths:
    
        fname = os.path.basename(f)
        mel = "mels/{}".format(fname.replace("wav", "npy"))
        mag = "mags/{}".format(fname.replace("wav", "npy"))
        mel = np.load(mel)
        mag = np.load(mag)
        # mel = tf.convert_to_tensor(mel)
        # mag = tf.convert_to_tensor(mag)
        # mel.set_shape((None, hp.n_mels * hp.r))
        # mag.set_shape((None, hp.n_fft // 2 + 1))
        fnames.append(fname)
        mels.append(mel)
        mags.append(mag)
       
return fnames, mels, mags

fnames, mels, mags = _load_spectrograms(fpaths)
mels = tf.ragged.constant(mels)
mags = tf.ragged.constant(mags)

########


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

1 Reply

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...