Shrink#
Shrink - 9#
Version
name: Shrink (GitHub)
domain: main
since_version: 9
function:
support_level: SupportType.COMMON
shape inference: True
This version of the operator has been available since version 9.
Summary
Attributes
bias - FLOAT : The bias value added to output. Default is 0.
lambd - FLOAT : The lambd value for the Shrink formulation. Default is 0.5.
Inputs
input (heterogeneous) - T:
Outputs
output (heterogeneous) - T:
Type Constraints
T in ( tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) ): Constrain input to only numeric types.
Examples
_hard_shrink
import numpy as np
import onnx
node = onnx.helper.make_node(
"Shrink",
inputs=["x"],
outputs=["y"],
lambd=1.5,
)
X = np.arange(-2.0, 2.1, dtype=np.float32)
Y = np.array([-2, 0, 0, 0, 2], dtype=np.float32)
expect(node, inputs=[X], outputs=[Y], name="test_shrink_hard")
_soft_shrink
import numpy as np
import onnx
node = onnx.helper.make_node(
"Shrink",
inputs=["x"],
outputs=["y"],
lambd=1.5,
bias=1.5,
)
X = np.arange(-2.0, 2.1, dtype=np.float32)
Y = np.array([-0.5, 0, 0, 0, 0.5], dtype=np.float32)
expect(node, inputs=[X], outputs=[Y], name="test_shrink_soft")