(y, threshold)
| 173 | * @returns {tf.Tensor} Binarized tensor. |
| 174 | */ |
| 175 | export 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 | } |
nothing calls this directly
no outgoing calls
no test coverage detected