Skip to content

Instantly share code, notes, and snippets.

@r7vme
Created July 8, 2019 21:22
Show Gist options
  • Save r7vme/b2bec39ab758e7f81090d163c8bff058 to your computer and use it in GitHub Desktop.
Save r7vme/b2bec39ab758e7f81090d163c8bff058 to your computer and use it in GitHub Desktop.
with ops.name_scope(name, "l2_normalize", [x]) as name:
x = ops.convert_to_tensor(x, name="x")
square_sum = math_ops.reduce_sum(math_ops.square(x), axis, keepdims=True)
x_inv_norm = math_ops.rsqrt(math_ops.maximum(square_sum, epsilon))
return math_ops.multiply(x, x_inv_norm, name=name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment