tensorflow / java

Java bindings for TensorFlow
Apache License 2.0
816 stars 202 forks source link

Possibly missing op functions: reduce mean/std/variance, std, variance? #148

Open rnett opened 3 years ago

rnett commented 3 years ago

I've noticed that a few ops present in the python docs are missing for reasons I can't determine. Specifically reduce_mean, reduce_std, and reduce_variance. reduce_mean seems like it is just missing the reduce wrapper (it's present in math.mean) but I can't find methods for standard deviation or variance at all. I thought it might be related to #117 so I went looking through the api def protos, and there aren't any standard deviation or variance protos, but there aren't any reduce op protos either so I'm not sure what's up. Regardless of whether this is #117 or not, variance at least would be nice to have.

Craigacp commented 3 years ago

Some operations are implemented purely in python, as collections of other ops. In some cases we've built them out in Java, in other cases we've not got around to it yet. You're welcome to make a PR to add them, there are other examples in the tensorflow-core-api module.

rnett commented 3 years ago

Will do. A few questions:

karllessard commented 3 years ago

C-side operations should all be auto-generated. It is still possible that some are missing because they are marked as HIDDEN in the base API def. When we identify such op, we override its visibility to VISIBLE in our API def and let the op generator taking care of it.

Now normally all ops should implement Op (if some are not, then they should be fixed) while Operand can only be implemented if your custom op generates a single output.

If so, yes it is recommended that you implement it as well since it allows you to pass directly an instance of your op as an operand to another. Otherwise, the user needs to pick up manually which output of the operation should be pass as the operand.