MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / frame

Function frame

tensorflow/python/ops/signal/shape_ops.py:56–191  ·  view source on GitHub ↗

Expands `signal`'s `axis` dimension into frames of `frame_length`. Slides a window of size `frame_length` over `signal`'s `axis` dimension with a stride of `frame_step`, replacing the `axis` dimension with `[frames, frame_length]` frames. If `pad_end` is True, window positions that are pas

(signal, frame_length, frame_step, pad_end=False, pad_value=0, axis=-1,
          name=None)

Source from the content-addressed store, hash-verified

54
55@tf_export("signal.frame")
56def frame(signal, frame_length, frame_step, pad_end=False, pad_value=0, axis=-1,
57 name=None):
58 """Expands `signal`'s `axis` dimension into frames of `frame_length`.
59
60 Slides a window of size `frame_length` over `signal`'s `axis` dimension
61 with a stride of `frame_step`, replacing the `axis` dimension with
62 `[frames, frame_length]` frames.
63
64 If `pad_end` is True, window positions that are past the end of the `axis`
65 dimension are padded with `pad_value` until the window moves fully past the
66 end of the dimension. Otherwise, only window positions that fully overlap the
67 `axis` dimension are produced.
68
69 For example:
70
71 ```python
72 pcm = tf.compat.v1.placeholder(tf.float32, [None, 9152])
73 frames = tf.signal.frame(pcm, 512, 180)
74 magspec = tf.abs(tf.signal.rfft(frames, [512]))
75 image = tf.expand_dims(magspec, 3)
76 ```
77
78 Args:
79 signal: A `[..., samples, ...]` `Tensor`. The rank and dimensions
80 may be unknown. Rank must be at least 1.
81 frame_length: The frame length in samples. An integer or scalar `Tensor`.
82 frame_step: The frame hop size in samples. An integer or scalar `Tensor`.
83 pad_end: Whether to pad the end of `signal` with `pad_value`.
84 pad_value: An optional scalar `Tensor` to use where the input signal
85 does not exist when `pad_end` is True.
86 axis: A scalar integer `Tensor` indicating the axis to frame. Defaults to
87 the last axis. Supports negative values for indexing from the end.
88 name: An optional name for the operation.
89
90 Returns:
91 A `Tensor` of frames with shape `[..., frames, frame_length, ...]`.
92
93 Raises:
94 ValueError: If `frame_length`, `frame_step`, `pad_value`, or `axis` are not
95 scalar.
96 """
97 with ops.name_scope(name, "frame", [signal, frame_length, frame_step,
98 pad_value]):
99 signal = ops.convert_to_tensor(signal, name="signal")
100 frame_length = ops.convert_to_tensor(frame_length, name="frame_length")
101 frame_step = ops.convert_to_tensor(frame_step, name="frame_step")
102 axis = ops.convert_to_tensor(axis, name="axis")
103
104 signal.shape.with_rank_at_least(1)
105 frame_length.shape.assert_has_rank(0)
106 frame_step.shape.assert_has_rank(0)
107 axis.shape.assert_has_rank(0)
108
109 result_shape = _infer_frame_shape(signal, frame_length, frame_step, pad_end,
110 axis)
111
112 # Axis can be negative. Convert it to positive.
113 signal_rank = array_ops.rank(signal)

Callers 1

ToStringMethod · 0.85

Calls 14

_infer_frame_shapeFunction · 0.85
with_rank_at_leastMethod · 0.80
assert_has_rankMethod · 0.80
reshapeMethod · 0.80
maximumMethod · 0.80
name_scopeMethod · 0.45
rankMethod · 0.45
rangeMethod · 0.45
shapeMethod · 0.45
splitMethod · 0.45
sizeMethod · 0.45
concatMethod · 0.45

Tested by

no test coverage detected