在等待实时预测输入时,将tensorflow估计器保存在内存中

在等待实时预测输入时,将tensorflow估计器保存在内存中,tensorflow,tensorflow-datasets,Tensorflow,Tensorflow Datasets,我有一个经过训练的估计器,当新的输入数据进来时,我用它来做实时预测 在代码的开头,我实例化了估计器: estimator=tf.estimator.estimator( 型号\ fn=型号\ fn, model_dir=“{}/model_dir{}”。格式(script_dir,3)) 然后在循环中,每次我获得足够的新数据进行预测时,我都会: predict\u input\u fn=tf.estimator.inputs.numpy\u input\u fn( x={“x”:np.arra

我有一个经过训练的估计器,当新的输入数据进来时,我用它来做实时预测

在代码的开头,我实例化了估计器:

estimator=tf.estimator.estimator(
型号\ fn=型号\ fn,
model_dir=“{}/model_dir{}”。格式(script_dir,3))
然后在循环中,每次我获得足够的新数据进行预测时,我都会:

predict\u input\u fn=tf.estimator.inputs.numpy\u input\u fn(
x={“x”:np.array([sample.normalized.input_data]),
num_epochs=1,
洗牌(错误)
预测=估计器(
输入\u fn=预测\u输入\u fn,
)
每次执行此操作时,我都会在控制台中收到这些tensorflow消息:

2018-04-21 16:01:08.401319:I tensorflow/core/common_runtime/gpu/gpu_device.cc:1195]创建tensorflow设备(/device:gpu:0)->(设备:0,名称:GeForce GTX 1060 6GB,pci总线id:0000:04:00.0,计算能力:6.1)

信息:tensorflow:从/home/fgervais/tf/model_dir_3/model.ckpt-103712恢复参数

似乎整个GPU检测过程和模型加载都是在每次预测中再次完成的


有没有一种方法可以在实时输入之间将模型加载到内存中,以便获得更好的预测率?

解决此问题的方法是使用

在问题的具体背景下,应这样做:

def服务_输入_fn():
x=tf.placeholder(dtype=tf.float32,shape=[3500],name='x')
输入={'x':x}
返回tf.estimator.export.ServingingInputReceiver(输入,输入)
估计量=tf.estimator.estimator(
型号\ fn=型号\ fn,
model_dir=“{}/model_dir{}/model.ckpt-103712”。格式(script_dir,3))
估计器\u预测器=tf.contrib.predictor.from\u估计器(
估计器,服务(输入)
p=估计器\预测器(
{“x”:np.array(sample.normalized.input_data)})

解决方法是使用一个

在问题的具体背景下,应这样做:

def服务_输入_fn():
x=tf.placeholder(dtype=tf.float32,shape=[3500],name='x')
输入={'x':x}
返回tf.estimator.export.ServingingInputReceiver(输入,输入)
估计量=tf.estimator.estimator(
型号\ fn=型号\ fn,
model_dir=“{}/model_dir{}/model.ckpt-103712”。格式(script_dir,3))
估计器\u预测器=tf.contrib.predictor.from\u估计器(
估计器,服务(输入)
p=估计器\预测器(
{“x”:np.array(sample.normalized.input_data)})

我不知道为什么人们会投反对票。我有完全相同的问题,这个解决方案非常有用。我不知道为什么人们会投票反对。我遇到了完全相同的问题,这个解决方案非常有用。