-XX:+DisableExplicitGC
etc. ZGC maps the memory multiple times, which is known to inflate the resident set size (https://mail.openjdk.java.net/pipermail/zgc-dev/2018-November/000540.html), throwing off JavaCPP's calculation.
Hello, we run Tensorflow Java 0.2.0 (TF 2.3.1). And we have a model that produces an image out of the model as a byte[]. This is fine when running the model in python. We can write the bytes to a file. But when trying to do the same thing using TF Java we run into getting too few bytes from the output. I think I have managed to boil it down to unit test with TString.
public void testTFNdArray() throws Exception {
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
byte[] readAllBytes = Files.readAllBytes(Path.of(contextClassLoader.getResource("img_12.png").getFile()));
NdArray<byte[]> vectorOfObjects = NdArrays.vectorOfObjects(readAllBytes);
Tensor<TString> tensorOfBytes = TString.tensorOfBytes(vectorOfObjects);
TString data = tensorOfBytes.data();
byte[] asBytes = tensorOfBytes.data().asBytes().getObject(0);
System.out.println("Bytes original file: " + readAllBytes.length);
System.out.println("NdArray byte[] length: " + vectorOfObjects.getObject().length);
System.out.println("Tensor numbytes: " + tensorOfBytes.numBytes());
System.out.println("TString size: " + data.size());
System.out.println("Bytes with reading from TString (WRONG): " + asBytes.length);
}
This is the problem that I get with running through a real model. How should we be able to get the full byte[] out again?
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x0000000133cf0fbb, pid=19618, tid=5891
#
# JRE version: OpenJDK Runtime Environment (11.0.2+9) (build 11.0.2+9)
# Java VM: OpenJDK 64-Bit Server VM (11.0.2+9, mixed mode, tiered, compressed oops, g1 gc, bsd-amd64)
# Problematic frame:
# C [libtensorflow_cc.2.dylib+0x8228fbb] TF_TensorData+0xb
#
# No core dump will be written. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /Users/jakob/proj/tfjava031/hs_err_pid19618.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
Are there any examples that show the usage of the Java framework API for basic workflow like this?
training_images = training_images/255.0
test_images = test_images/255.0
model = tf.keras.models.Sequential([#tf.keras.layers.Flatten(),
tf.keras.layers.Dense(64, activation=tf.nn.relu),
tf.keras.layers.Dense(10, activation=tf.nn.softmax)])
model.compile(optimizer = 'adam',
loss = 'sparse_categorical_crossentropy')
model.fit(training_images, training_labels, epochs=5)
model.evaluate(test_images, test_labels)
classifications = model.predict(test_images)
Specifically, I don't see the equivalent of models.Sequential
, model.compile
, model.fit
etc.
model.predict()
in Java.Placeholder
. Do I invoke Ops.tensorArray()
of the same size as the placeholder, then populate that, then eventually invoke Runner.feed(placeholder, array)
? Or is there a better way?
TFloat32
either an empty one, or by copying from some source. Then feed it to the placeholder. Note the empty one returns memory which has not been zeroed yet tensorflow/java#271.
model.fit()
until I get something working.... then I can move model.fit()
to Java and model.predict()
would always sit in Java.
So to some extent it depends how complicated your model is. Tribuo's next release exposes TF models but wraps up all the fitting, evaluation and prediction in it's interface to make it a lot simpler. It's not the same as Keras, it's a little bit more like scikit-learn as we don't have callbacks in Tribuo.
However TF-Java will have this in the future, it's just a lot of stuff to build with a much smaller team than the Keras team.