將 signal 的 axis 維度擴展為 frame_length 的框架。
用法
tf.signal.frame(
signal, frame_length, frame_step, pad_end=False, pad_value=0, axis=-1, name=None
)參數
-
signal一個[..., samples, ...]Tensor。等級和維度可能是未知的。排名必須至少為 1。 -
frame_length樣本中的幀長度。整數或標量Tensor。 -
frame_step樣本中的幀跳大小。整數或標量Tensor。 -
pad_end是否用pad_value填充signal的末尾。 -
pad_value當pad_end為真時,在輸入信號不存在的地方使用可選標量Tensor。 -
axis一個標量整數Tensor,指示要框架的軸。默認為最後一個軸。支持從末尾開始索引的負值。 -
name操作的可選名稱。
返回
-
A
Tensor形狀為[..., num_frames, frame_length, ...]的幀。
拋出
-
ValueError如果frame_length,frame_step,pad_value或axis不是標量。
在 signal 的 axis 維度上滑動大小為 frame_length 的窗口,步長為 frame_step ,將 axis 維度替換為 [frames, frame_length] 幀。
如果 pad_end 為 True,則超過 axis 維度末尾的窗口位置將使用 pad_value 填充,直到窗口完全移動到維度末尾。否則,隻會生成與axis 維度完全重疊的窗口位置。
例如:
# A batch size 3 tensor of 9152 audio samples.
audio = tf.random.normal([3, 9152])
# Compute overlapping frames of length 512 with a step of 180 (frames overlap
# by 332 samples). By default, only 49 frames are generated since a frame
# with start position j*180 for j > 48 would overhang the end.
frames = tf.signal.frame(audio, 512, 180)
frames.shape.assert_is_compatible_with([3, 49, 512])
# When pad_end is enabled, the final two frames are kept (padded with zeros).
frames = tf.signal.frame(audio, 512, 180, pad_end=True)
frames.shape.assert_is_compatible_with([3, 51, 512])
如果沿 axis 的維度為 N,並且 pad_end=False ,則可以通過以下方式計算幀數:
num_frames = 1 + (N - frame_size) // frame_step
如果 pad_end=True ,則可以通過以下方式計算幀數:
num_frames = -(-N // frame_step) # ceiling division
相關用法
- Python tf.signal.fftshift用法及代碼示例
- Python tf.signal.overlap_and_add用法及代碼示例
- Python tf.signal.linear_to_mel_weight_matrix用法及代碼示例
- Python tf.signal.inverse_mdct用法及代碼示例
- Python tf.signal.mfccs_from_log_mel_spectrograms用法及代碼示例
- Python tf.signal.ifftshift用法及代碼示例
- Python tf.signal.inverse_stft用法及代碼示例
- Python tf.size用法及代碼示例
- Python tf.summary.scalar用法及代碼示例
- Python tf.strings.substr用法及代碼示例
- Python tf.strings.reduce_join用法及代碼示例
- Python tf.sparse.cross用法及代碼示例
- Python tf.sparse.mask用法及代碼示例
- Python tf.strings.regex_full_match用法及代碼示例
- Python tf.sparse.split用法及代碼示例
- Python tf.strings.regex_replace用法及代碼示例
- Python tf.strings.length用法及代碼示例
- Python tf.strided_slice用法及代碼示例
- Python tf.sparse.to_dense用法及代碼示例
- Python tf.strings.bytes_split用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.signal.frame。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
