Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrected docstring for tf.signal.frame #36567

Merged
merged 2 commits into from
Jun 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 21 additions & 13 deletions tensorflow/python/ops/signal/shape_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,27 @@ def frame(signal, frame_length, frame_step, pad_end=False, pad_value=0, axis=-1,

For example:

>>> # 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])

If the dimension along `axis` is N, and `pad_end=False`, the number of frames
can be computed by:
```python
num_frames = 1 + (N - frame_size) // frame_step
```
If `pad_end=True`, the number of frames can be computed by:
```python
# 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 50 frames are generated since the last
# 152 samples do not form a full frame.
frames = tf.signal.frame(audio, 512, 180)
frames.shape.assert_is_compatible_with([3, 50, 512])

# When pad_end is enabled, the final frame is kept (padded with zeros).
frames = tf.signal.frame(audio, 512, 180, pad_end=True)
frames.shape.assert_is_compatible_with([3, 51, 512])
num_frames = -(-N // frame_step) # ceiling division
```

Args:
Expand All @@ -96,7 +104,7 @@ def frame(signal, frame_length, frame_step, pad_end=False, pad_value=0, axis=-1,
name: An optional name for the operation.

Returns:
A `Tensor` of frames with shape `[..., frames, frame_length, ...]`.
A `Tensor` of frames with shape `[..., num_frames, frame_length, ...]`.

Raises:
ValueError: If `frame_length`, `frame_step`, `pad_value`, or `axis` are not
Expand Down