Java-火车加载的Tensorflow模型 [英] Java - train loaded tensorflow model

查看:102
本文介绍了Java-火车加载的Tensorflow模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道从Tensorflow Python将模型加载到Java后是否可以继续训练模型? 我想出了这段代码,但是没有用(是的,输出与输入相同)

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);
}

这是打印10000次的内容:

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?

推荐答案

您正在提供输入并获取损失;这不会训练模型.为此,您需要输入大量数据并运行更新操作(可能从optimizer.minimize返回).

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).

可以通过Java来做到这一点,但是python中的基础设施更加完善,包括用于预取队列中输入数据,监视输入何时结束,保存摘要以及进行分布式培训的线程.

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.

这篇关于Java-火车加载的Tensorflow模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆