MCPcopy Create free account
hub / github.com/tensorflow/tfjs-examples / binarize

Function binarize

website-phishing/utils.js:175–187  ·  view source on GitHub ↗
(y, threshold)

Source from the content-addressed store, hash-verified

173 * @returns {tf.Tensor} Binarized tensor.
174 */
175export function binarize(y, threshold) {
176 if (threshold == null) {
177 threshold = 0.5;
178 }
179 tf.util.assert(
180 threshold >= 0 && threshold <= 1,
181 `Expected threshold to be >=0 and <=1, but got ${threshold}`);
182
183 return tf.tidy(() => {
184 const condition = y.greater(tf.scalar(threshold));
185 return tf.where(condition, tf.onesLike(y), tf.zerosLike(y));
186 });
187}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected