我正在使用音頻和文本進行情緒分類的專案。我將音頻和文本傳遞給 1D CNN 并得到以下輸出陣列:
audio_features_shape = (396, 63, 64)
text_features_shape = (52, 1, 64)
現在我想將這兩個不同維度的陣列堆疊成一個,這樣我就可以將一個陣列傳遞給 LSTM。我想要的形狀為:
expected_array_shape = (448, 64, 128)
我嘗試了以下方法,但沒有人給出我想要的輸出。
x = np.column_stack((audio_features, text_features))
x = np.concatenate((audio_features,text_features), axis=2)
x = np.append(audio_features, text_features)
x = np.transpose([np.tile(audio_features, len(text_features)), np.repeat(text_features, len(audio_features))])
x = np.array([np.append(text_features,x) for x in audio_features])
任何幫助,將不勝感激。謝謝!
uj5u.com熱心網友回復:
2 個陣列的值應該如何分布在結果中?
audio_features_shape = (396, 63, 64)
text_features_shape = (52, 1, 64)
text_features應該“擴展”到 (52,63,64),或者通過在中間軸上重復值 63 次,或者將此陣列放入 0 的目標陣列中。在任何一種情況下,它都會大 63 倍。
一旦陣列在除第一個維度之外的所有維度上都匹配后,它們就可以被連接起來。
但真正的問題是,LSTM 的使用有何意義?
uj5u.com熱心網友回復:
根據您到底想要什么以及您是否只對使用 Tensorflow 感興趣,您可以嘗試以下操作:
import tensorflow as tf
audio_features = tf.random.normal((396, 63, 64))
text_features = tf.random.normal((52, 1, 64))
text_features = tf.repeat(text_features, repeats=(audio_features.shape[1]-text_features.shape[1]) 1, axis=1)
repeat_features = tf.concat([audio_features, text_features], axis=0)
text_features = tf.random.normal((52, 1, 64))
paddings = tf.constant([[0, 0], [0, audio_features.shape[1]-text_features.shape[1]], [0, 0]])
pad_features = tf.concat([audio_features, tf.pad(text_features, paddings, "CONSTANT")], axis=0)
print('Using tf.repeat --> ', audio_features.shape, text_features.shape, repeat_features.shape)
print('Using tf.pad --> ', audio_features.shape, text_features.shape, pad_features.shape)
Using tf.repeat --> (396, 63, 64) (52, 1, 64) (448, 63, 64)
Using tf.pad --> (396, 63, 64) (52, 1, 64) (448, 63, 64)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/347403.html
