Conversation
Fixed dependencies in pom.xml
…hod. This allows the NAME to be used elsewhere instead of hardcoding the string.
…coding the string. added methods isFloating(), isInteger(), isNUmeric(), isBoolean() and isString()
…ng OP_NAME" to each generated operation.
…EntropyWitLogits() Added tf.nn.sparesSoftmaxCrossEntropyWithLogits() and tf.nn.raw.sparesSoftmaxCrossEntropyWithLogits() Added tf.nn.sigmoidCrossEntropyWithLogits()
…Logits to org.tensorflow.op.nn.raw
fix javadoc, fix casts
…yWithLogits.java to nn.raw, added new versions of these to NnOps
…maxCrossEntropyWithLogits()
…maxCrossEntropyWithLogits()
…x JavaDoc. Change from snake case to camel case.
…x JavaDoc. Change from snake case to camel case.
…Java files for some Ops. This also resulted in new generated source that are also committed.
…gmoidCrossEntropyWithLogits.java, and SparseSoftmaxCrossEntropyWithLogits.java under package org.tensorflow.op.nn in
…asy inclusion of a default optimizer. Cleaned up JavaDoc
Craigacp
left a comment
There was a problem hiding this comment.
Tiny things to do with casing.
tensorflow-framework/src/test/java/org/tensorflow/framework/activations/ReLUTest.java
Outdated
Show resolved
Hide resolved
tensorflow-framework/src/test/java/org/tensorflow/framework/activations/SoftmaxTest.java
Outdated
Show resolved
Hide resolved
tensorflow-framework/src/main/java/org/tensorflow/framework/activations/Activation.java
Show resolved
Hide resolved
tensorflow-framework/src/main/java/org/tensorflow/framework/activations/Activation.java
Show resolved
Hide resolved
tensorflow-framework/src/main/java/org/tensorflow/framework/activations/ELU.java
Outdated
Show resolved
Hide resolved
tensorflow-framework/src/main/java/org/tensorflow/framework/activations/ELU.java
Outdated
Show resolved
Hide resolved
tensorflow-framework/src/main/java/org/tensorflow/framework/activations/Exponential.java
Outdated
Show resolved
Hide resolved
| return LeakyRelu.create(tf.scope(), input, LeakyRelu.alpha(alpha)); | ||
| } | ||
| if (threshold != 0) { | ||
| negativePart = |
There was a problem hiding this comment.
What would you think about moving both the declaration and the initialization of negativePart down to immediately before it is used? I realize that would require a change to keep input as the original input instead of reusing it for intermediate calculations, but personally I'd see that as a feature not a bug.
There was a problem hiding this comment.
Perhaps rename negativePart -> amountBelowThreshold? For one thing, negativePart is vague to me. For another, it's always positive.
There was a problem hiding this comment.
I am not sure if this is used here as a math term, but I found Wolfram MathWorld - Negative Part. Perhaps @Craigacp and @karllessard might want to comment.
There was a problem hiding this comment.
Good point, that Wolfram definition does show why negativePart was used in the first place. That said, I'd still advocate that in the presence of threshold, it's a confusing name.
tensorflow-framework/src/main/java/org/tensorflow/framework/activations/ReLU.java
Show resolved
Hide resolved
tensorflow-framework/src/main/java/org/tensorflow/framework/activations/ReLU.java
Outdated
Show resolved
Hide resolved
| if (clipMax) { | ||
| Operand<T> lmaxValue = tf.dtypes.cast(tf.constant(maxValue), dataType); | ||
| Operand<T> zero = tf.dtypes.cast(tf.constant(0), dataType); | ||
| input = tf.clipByValue(input, zero, lmaxValue); |
There was a problem hiding this comment.
Is zero still the right lower clip if there's a threshold?
There was a problem hiding this comment.
The numbers less than the threshold get converted to zero before the clipMax is applied.
So, there is no need to move the lower bound on the clipByValue operation.
if (threshold != 0) {
// computes input for input > threshold else 0
Greater greater = tf.math.greater(input, tf.dtypes.cast(tf.constant(threshold), dataType));
input = tf.math.mul(input, tf.dtypes.cast(greater, dataType));
tensorflow-framework/src/main/java/org/tensorflow/framework/activations/SELU.java
Outdated
Show resolved
Hide resolved
tensorflow-framework/src/main/java/org/tensorflow/framework/activations/SELU.java
Outdated
Show resolved
Hide resolved
tensorflow-framework/src/main/java/org/tensorflow/framework/activations/Sigmoid.java
Outdated
Show resolved
Hide resolved
tensorflow-framework/src/main/java/org/tensorflow/framework/activations/ELU.java
Outdated
Show resolved
Hide resolved
tensorflow-framework/src/main/java/org/tensorflow/framework/activations/HardSigmoid.java
Show resolved
Hide resolved
tensorflow-framework/src/main/java/org/tensorflow/framework/activations/SELU.java
Outdated
Show resolved
Hide resolved
tensorflow-framework/src/main/java/org/tensorflow/framework/activations/SELU.java
Show resolved
Hide resolved
tensorflow-framework/src/main/java/org/tensorflow/framework/activations/Softmax.java
Outdated
Show resolved
Hide resolved
tensorflow-framework/src/main/java/org/tensorflow/framework/activations/Softmax.java
Show resolved
Hide resolved
tensorflow-framework/src/main/java/org/tensorflow/framework/activations/Swish.java
Outdated
Show resolved
Hide resolved
tensorflow-framework/src/main/java/org/tensorflow/framework/activations/Tanh.java
Show resolved
Hide resolved
tensorflow-framework/src/test/java/org/tensorflow/framework/activations/ELUTest.java
Outdated
Show resolved
Hide resolved
|
|
||
| /** Test of ELU call method */ | ||
| @Test | ||
| public void testCallFloat() { |
There was a problem hiding this comment.
Perhaps also consolidate this sort of test logic into a helper class? E.g.
assertFloat32Output(tf -> new ELU<Float32>(tf),
{1f, -0.86466473f, 3f, -0.9816844f, -0.63212055f, 2f, -0.95021296f, 4f},
{1, -2, 3, -4, -1, 2, -3, 4})
tensorflow-framework/src/main/java/org/tensorflow/framework/activations/Activation.java
Show resolved
Hide resolved
tensorflow-framework/src/main/java/org/tensorflow/framework/activations/Activation.java
Show resolved
Hide resolved
tensorflow-framework/src/main/java/org/tensorflow/framework/activations/Activation.java
Show resolved
Hide resolved
tensorflow-framework/src/main/java/org/tensorflow/framework/activations/ELU.java
Outdated
Show resolved
Hide resolved
tensorflow-framework/src/main/java/org/tensorflow/framework/activations/Exponential.java
Outdated
Show resolved
Hide resolved
tensorflow-framework/src/main/java/org/tensorflow/framework/activations/ReLU.java
Outdated
Show resolved
Hide resolved
| if (threshold != 0) { | ||
| // computes input for input > threshold else 0 | ||
| Greater greater = tf.math.greater(input, tf.dtypes.cast(tf.constant(threshold), dataType)); | ||
| input = tf.math.mul(input, tf.dtypes.cast(greater, dataType)); |
There was a problem hiding this comment.
I would try to avoid changing the value of a method parameter, better use a new variable.
karllessard
left a comment
There was a problem hiding this comment.
@JimClarke5 , it looks like this PR can almost be merged, can you please go through all remaining comments and resolve them, either by a fix or by an answer? Thanks
tensorflow-framework/src/main/java/org/tensorflow/framework/activations/Softmax.java
Outdated
Show resolved
Hide resolved
tensorflow-framework/src/main/java/org/tensorflow/framework/activations/Tanh.java
Show resolved
Hide resolved
tensorflow-framework/src/test/java/org/tensorflow/framework/activations/SwishTest.java
Show resolved
Hide resolved
Misc fixes to JavaDoc. In ReLU, change to assign to new variable 'lInput' rather than change the 'input' parameter.
…ng type, as they would no longer compile.
…ng type, as they would no longer compile.
|
I have just pushed the changes requested, the biggest was adding |
tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/types/TFloat64.java
Show resolved
Hide resolved
deansher
left a comment
There was a problem hiding this comment.
Ship it! This is a huge step forward.
|
Thanks @JimClarke5 ! |
This is a redone PR to make sure the
Activationsbranch did not rely on theInitializersbranch.I have removed all the no-arg CTORs. The original motivation was that I found previously in looking at Keras layers is that objects like “activations”, “loss” and “metric" most likely would need to be constructed
before the TensorFlow Ops is available within the model, hence I make constructors without Ops and used
setTF()so theModelcould set it later. The model itself hidesOps tffrom the user. We have decided to address this requirement later when we start looking atModel.I fixed
HardSigmoid, as I forgot to apply aclipByValueoperation on the final result. Also fixed the Unit test.I have verified all the Unit tests against their TF Python corresponding methods.
For
Softmax, we eliminated theIllegalArgmentExceptionon 1D input that was in the Keras version.In
Swish, there is a comment on not handling thegradargument from the corresponding Python class. This is a Python optimization and will not be implemented in Java, at least at this time.