Closed lucaro closed 2 years ago
Never mind, it works using
private static byte[] serialize(TFloat32 tensor) {
try (
ConcreteFunction fun = ConcreteFunction.create(Main::serializeTensor);
TString serialized = (TString) fun.call(tensor);
) {
DataBuffer<byte[]> buf = DataBuffers.ofObjects(byte[].class, 1);
serialized.asBytes().read(buf);
serialized.close();
return buf.getObject(0);
}
}
I'm trying to write tfrecords from a Java application, but when I read back the String from the tensor serialization function and convert it to bytes in order to be written, I get differences in certain places. This has probably something to do with the character encoding in Java. I added some example code below. Is there another way to get to the raw bytes of a
TString
in order to get around this?