tensorflow - serializing and reading 2D sequence into/from TFRecords -
i'm trying serialize 2d vector (spectrogram of speech, varied in length) tfrecord.
there example this? have tried code here , here, seem not suit needs.
how serialize 2d (or n-d array) varied in length sequence tfrecords?
my current implementation (no errors, think it's not correct):
# extract spectrogram wav rate, wav = wavfile.read(wav_path) _, __, sxx = spectrogram(wav, fs=rate, nperseg=254, noverlap=127) spectrogram_feat = np.moveaxis(sxx, 0, -1) # shift axis [freq, time] -> [time, freq] # make example ex = tf.train.sequenceexample() ex.context.feature['seq_length'].int64_list.value.append(spectrogram_feat.shape[0]) ex.context.feature['n_feature'].int64_list.value.append(spectrogram_feat.shape[1]) fl_spectogram = ex.feature_lists.feature_list['spectrogram'] fl_label = ex.feature_lists.feature_list['label'] in range(spectrogram_feat.shape[0]): # print(spectrogram_feat[i, :].reshape(1, -1)) f in spectrogram_feat[i, :]: fl_spectogram.feature.add().float_list.value.append(f) writer.write(ex.serializetostring())
Comments
Post a Comment