val g = new Graph()
val ops = Ops.create(g)
import ops.*
val a = constant(3.0)
val b = constant(2.0)
val x = placeholder(classOf[TFloat64])
val y = placeholder(classOf[TFloat64])
val ax = math.mul(a, x)
val by = math.mul(b, y)
val z = math.add(ax, by)
val session = new Session(g)
val r = session.runner()
val tensor = r.fetch(z)
.feed(x, TFloat64.scalarOf(3.0))
.feed(y, TFloat64.scalarOf(6.0))
.run
.get(0)
tensor match
case tf: TFloat64 => println(tf.getDouble()) // 21.0
case other => println(s"OTHER: $other")
Tensors.create(float[][])
?
Tensor.of(TFloat32.class, Shape.of(javaArray.length, javaArray[0].length), data -> StdArrays.copyTo(javaArray, data))
I guess ... ? Is there a utility function that does this?
I'm stuck with these:
public class Ones {
public <T extends TNumber> Operand<T> initialize(Ops tf, Operand<TInt32> shape, Class<T> dtype) {
return tf.fill(shape, tf.constant(1.0f, dtype)); // no such method
}
}
How can I convert from a float
to a TNumber
? In Scala this would be a type class instance TNumbers[T <: TNumber] { def fromFloat(f: Float): Operand[T] }
, but I don't know how to express that in Java. Should I change Class<T>
for something that has factory capabilities?
NdArray
hierarchy from the start, you’ll have better performances and memory usage
saved_model_cli
". And saved_model_cli tells me that "SavedModel file does not exist" in that directory. I'm confused and my question is: how is this usually done and what works for TF java?
Trying to translate this tutorial. Python:
noise = tf.random.normal([1, 100])
How do I write that in Java/Scala? I try
val noise = tf.random.randomStandardNormal(Shape.of(1, 100), classOf[TFloat32])
But this is not an Operand[? <: TNumber]
. How I get from Shape
to that?
tf.constant(Array(1, 100))
correct?