good morning
i have strange problem
im using djl library, im generating neural network, and then save it to file (only avaible method). Then im getting bytes from file, encode it to base64 and save to db. Saving works almost fine, i have data, but it a lot of chars are diferent.
Original: DJL@ test FLOAT32
decoded value from db DJL@����test�FLOAT32����
gpt says the problem may be caused by float32
function that create file and copy content:
public static byte[] modelToBlob(Model model) throws IOException {
Path tempDir = Files.createTempDirectory("temp-model");
model.save(tempDir, "test");
Path modelFile = tempDir.resolve(model.getName() + "-0000.params");
return Files.readAllBytes(Paths.get(modelFile.toUri()));
}
create network
public void createEmptyNeuralNetwork() {
Block block = new Mlp(6, 2, new int[]{128, 64});
NDManager manager = NDManager.newBaseManager();
NDArray x = manager.randomUniform(0, 1, new Shape(2, 6));
block.initialize(manager, DataType.FLOAT32, x.getShape());
try (Model model = Model.newInstance("test")) {
model.setBlock(block);
byte[] modelBytes = modelToBlob(model);
String serializedModel = Base64.getEncoder().withoutPadding().encodeToString(modelBytes);
NeuralNetwork nn = new NeuralNetwork();
nn.setUuid(UUID.randomUUID());
nn.setName("test");
nn.setSerializedNeuralNetwork(serializedModel);
}
}
additional info: https://base64.guru/converter/encode/file - here encode and decode (from source file) working if im using just file
https://www.base64decode.org/ here i tried encode and decode value of file, but here i have a lot of differences
(bump)