0

Does anyone know if it is possible after a model is loaded into Java from Tensorflow Python to continue training the model? I've come up with this snippet of code, but did not work (yes, the output is the same as the input)

for(int i = 0; i < 10000; i++) {
    Tensor cost = b.session().runner().feed("input", input).feed("output", input).fetch("cost").run().get(0);
    System.out.println(result1);
}

This is what is printed out 10000 times:

FLOAT tensor with shape []

And after all, the predictions are the same as they were before.

Moreover, if it is possible to continue training the loaded model, is it possible to update the saved model's weights and biases?

1 Answer 1

1

You are feeding inputs and fetching the loss; this won't train the model. To do so you'll need to feed batches of data and run the update ops (returned maybe from optimizer.minimize).

It is possible to do this from Java, but the infrastructure in python is more well-developed, including threads to prefetch input data in queues, monitoring when the input is over, saving summaries, and doing distributed training.

Sign up to request clarification or add additional context in comments.

4 Comments

Good point, Thanks! Do you maybe know if it is possible to update the saved model from Java? The class SavedModelBundle doesn't have any function, which seems related to saving. Maybe the function metaGraphDef(), but I am not sure it would contain the variables as well or only the graph structure. and I do not how I could update the ProtocolBuffer (pb) saved model either using the metaGraphDef
I think you'd have to reimplement the python saving logic in java to do that.
could you able to train the models from Java?
Hy. I stopped on this project, but I think using optimizer.minimize worked for training the model

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.