I have a Tensor<Float>
that is all 0s and 1s. It’s a mask that was created previously. How can I convert this to a Tensor<Bool>
to use with gathering(where:alongAxis:)
? These ideas came to mind:
let myFloatMask: Tensor<Float> = Tensor<Float>(arrayLiteral: [1.0, 0.0, 0.0, 1.0])
// boolean test like https://stackoverflow.com/questions/53562417/how-to-convert-a-pytorch-tensor-of-ints-to-a-tensor-of-booleans
let booleanMask = myFloatMask == 1.0
// .where like https://www.tensorflow.org/api_docs/python/tf/where
let booleanMask = myFloatMask.where( { $0 > 0} )
// cast like https://www.tensorflow.org/api_docs/python/tf/cast
let booleanMask = Tensor<Bool>(myFloatMask)
let booleanMask = Tensor<Bool>(copying: myFloatMask, to: myDevice)
I don’t believe any of these are actually supported. Is there a recommended approach to such a conversion from Float to Bool?
Thanks,
Xander
--
To unsubscribe from this group and stop receiving emails from it, send an email to swift+un...@tensorflow.org.