Tensorflow tf.lookup.StaticVocabularyTable与num#oov#u bucket不';我不在工作

Tensorflow tf.lookup.StaticVocabularyTable与num#oov#u bucket不';我不在工作,tensorflow,tensorflow-serving,Tensorflow,Tensorflow Serving,我创建了一个TF模型,它使用TF.lookup.StaticVocabularyTable在TF图中创建vocab映射。它从文本文件读取映射,并指定num\u oov\u bucket=500。以下是守则的一部分— num\u oov\u bucket=500 table_init=tf.lookup.TextFileInitializer('resmap.txt',tf.int64,0,tf.int64,1,delimiter=”“) table=tf.lookup.StaticVocabul

我创建了一个TF模型,它使用
TF.lookup.StaticVocabularyTable
在TF图中创建vocab映射。它从文本文件读取映射,并指定
num\u oov\u bucket=500
。以下是守则的一部分—

num\u oov\u bucket=500
table_init=tf.lookup.TextFileInitializer('resmap.txt',tf.int64,0,tf.int64,1,delimiter=”“)
table=tf.lookup.StaticVocabularyTable(table_init,num_oov_bucket)
使用此功能,它在训练和预测时运行良好。
我使用以下代码将TF模型转换为Tensorflow服务-

从模型导入模型WDN
使用tf.Session()作为sess:
tf.app.flags.DEFINE_字符串('f','kernel'))
tf.app.flags.DEFINE_integer('model_version',1,'模型的版本号')
tf.app.flags.DEFINE_字符串('save_dir','/home/abhilash','Saving directory'))
FLAGS=tf.app.FLAGS.FLAGS
export_path=os.path.join(tf.compat.as_字节(FLAGS.save_dir),tf.compat.as_字节(str(FLAGS.model_版本)))
打印(“将训练模型导出到”,导出路径)
#创建模型对象并初始化TF图中的所有全局变量。
型号=ModelWDN(分辨率=21663)
sess.run(tf.global\u variables\u initializer())
sess.run(tf.local\u variables\u initializer())
sess.run(tf.tables\u初始值设定项())
tf.train.Saver().restore(sess,os.path.join('/home/abhilash','wdn'))
打印(“模型已还原”)
#SavedModelBuilder对象
builder=tf.saved\u model.builder.SavedModelBuilder(导出路径)
#将张量转换为TensorInfo对象,以便在SignatureDefs中使用
tensor\u info\u click\u hist\u str=tf.saved\u model.utils.build\u tensor\u info(model.click\u hist\u str)
tensor\u info\u res\u to\u predict\u str=tf.saved\u model.utils.build\u tensor\u info(model.res\u to\u predict\u str)
tensor\u info\u prob=tf.saved\u model.utils.build\u tensor\u info(model.logits\u all)
#签名道夫
预测\u签名=(
tf.saved_model.signature_def_utils.build_signature_def(
输入={'click\u hist\u str':张量信息\u click\u hist\u str,
“res-to-predict-str”:张量-info-res-to-predict-str},
输出={'probs':张量_info_prob},
方法\名称=tf.保存的\模型.签名\常数.预测\方法\名称)
builder.add_meta_graph_和_变量(
sess=sess,
tags=[tf.saved_model.tag_constants.service],
signature_def_map={'predict_ad_view_prob':prediction_signature},
main_op=tf.tables_initializer(),
strip\u default\u attrs=False,
)
#导出模型
builder.save()
打印('已完成将TF模型导出为SavedModel格式!')
当我提供在定义
tf.lookup.TextFileInitializer
时提供的
resmap.txt
中存在的任何值时,它被转换而没有任何错误,并给出正确的预测。此映射中不存在的任何值都会在执行curl请求时给出服务错误,但在其他情况下不会给出任何错误(即在会话内从TF模型进行预测时)。 卷曲请求-

curl -X POST http://localhost:8501/v1/models/1:predict -d '{"signature_name": "predict_ad_view_prob", "inputs":{"res_to_predict_str": ["9 18788418 19039855 18771619"], "click_hist_str": ["18198449 18656271 18198449"]}}'
{ "error": "indices[0] = 21748 is not in [0, 21663)\n\t [[{{node GatherV2_5}}]]" }
这里的
9
resmap.txt

下面是我在执行curl请求时遇到的错误-

curl -X POST http://localhost:8501/v1/models/1:predict -d '{"signature_name": "predict_ad_view_prob", "inputs":{"res_to_predict_str": ["9 18788418 19039855 18771619"], "click_hist_str": ["18198449 18656271 18198449"]}}'
{ "error": "indices[0] = 21748 is not in [0, 21663)\n\t [[{{node GatherV2_5}}]]" }
resmap.txt
有21663个键值,并且
num_oov_bucket
设置为500

在TF会话内预测时,相同的输入会给出正确的结果-

[[0.10621755 0.50749264 0.08582641 0.00173556]]
因此,显然
num\u oov\u bucket
有一些问题&服务中没有正确实现这一点,或者如果我遗漏了什么/不正确地构建
TF SavedModel
,请告诉我

更新-添加保存的\u model\u cli显示和运行命令

saved_model_cli show --dir 1 --all
2019-07-18 10:18:54.805220:I tensorflow/stream_executor/platform/default/dso_loader.cc:42]已成功打开动态库libcuda.so.1
2019-07-18 10:18:54.810121:I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005]从SysFS读取的成功NUMA节点的值为负值(-1),但必须至少有一个NUMA节点,因此返回NUMA节点零
2019-07-18 10:18:54.811041:I tensorflow/core/common_runtime/gpu/gpu_device.cc:1640]找到了具有以下属性的设备0:
名称:特斯拉K80大调:3小调:7 memoryClockRate(GHz):0.8235
pciBusID:0000:00:1e.0
2019-07-18 10:18:54.811492:I tensorflow/stream_executor/platform/default/dso_loader.cc:42]成功打开动态库libcudart.so.10.0
2019-07-18 10:18:54.813643:I tensorflow/stream_executor/platform/default/dso_loader.cc:42]成功打开动态库libcublas.so.10.0
2019-07-18 10:18:54.815415:I tensorflow/stream_executor/platform/default/dso_loader.cc:42]已成功打开动态库libcuft.so.10.0
2019-07-18 10:18:54.815914:I tensorflow/stream_executor/platform/default/dso_loader.cc:42]已成功打开动态库libcurand.so.10.0
2019-07-18 10:18:54.818528:I tensorflow/stream_executor/platform/default/dso_loader.cc:42]成功打开动态库libcusolver.so.10.0
2019-07-18 10:18:54.820856:I tensorflow/stream_executor/platform/default/dso_loader.cc:42]已成功打开动态库libcusparse.so.10.0
2019-07-18 10:18:54.826085:I tensorflow/stream_executor/platform/default/dso_loader.cc:42]已成功打开动态库libcudnn.so.7
2019-07-18 10:18:54.826234:I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005]从SysFS读取的成功NUMA节点的值为负值(-1),但必须至少有一个NUMA节点,因此返回NUMA节点零
2019-07-18 10:18:54.827152:I tensorflow/streamāu executor/cuda/cudaāu gpuāexecutor.cc:1005]从SysFS读取的成功NUMA节点的值为负值(-1),但必须至少有一个NUMA节点,因此返回NUMA节点零
2019-07-18 10:18:54.827807:I tensorflow/core/common_runtime/gpu/gpu_设备。cc:1763]添加可见gpu设备:0
2019-07-18 10:18:54.805220: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcuda.so.1
2019-07-18 10:18:54.810121: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2019-07-18 10:18:54.811041: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1640] Found device 0 with properties: 
name: Tesla K80 major: 3 minor: 7 memoryClockRate(GHz): 0.8235
pciBusID: 0000:00:1e.0
2019-07-18 10:18:54.811492: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudart.so.10.0
2019-07-18 10:18:54.813643: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcublas.so.10.0
2019-07-18 10:18:54.815415: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcufft.so.10.0
2019-07-18 10:18:54.815914: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcurand.so.10.0
2019-07-18 10:18:54.818528: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcusolver.so.10.0
2019-07-18 10:18:54.820856: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcusparse.so.10.0
2019-07-18 10:18:54.826085: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudnn.so.7
2019-07-18 10:18:54.826234: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2019-07-18 10:18:54.827152: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2019-07-18 10:18:54.827807: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1763] Adding visible gpu devices: 0
2019-07-18 10:18:54.828138: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2019-07-18 10:18:54.856561: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2300065000 Hz
2019-07-18 10:18:54.857004: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x5635e1749450 executing computations on platform Host. Devices:
2019-07-18 10:18:54.857037: I tensorflow/compiler/xla/service/service.cc:175]   StreamExecutor device (0): <undefined>, <undefined>
2019-07-18 10:18:54.984822: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2019-07-18 10:18:54.985784: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x5635e36188b0 executing computations on platform CUDA. Devices:
2019-07-18 10:18:54.985823: I tensorflow/compiler/xla/service/service.cc:175]   StreamExecutor device (0): Tesla K80, Compute Capability 3.7
2019-07-18 10:18:54.986072: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2019-07-18 10:18:54.987021: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1640] Found device 0 with properties: 
name: Tesla K80 major: 3 minor: 7 memoryClockRate(GHz): 0.8235
pciBusID: 0000:00:1e.0
2019-07-18 10:18:54.987099: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudart.so.10.0
2019-07-18 10:18:54.987152: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcublas.so.10.0
2019-07-18 10:18:54.987202: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcufft.so.10.0
2019-07-18 10:18:54.987250: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcurand.so.10.0
2019-07-18 10:18:54.987300: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcusolver.so.10.0
2019-07-18 10:18:54.987362: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcusparse.so.10.0
2019-07-18 10:18:54.987413: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudnn.so.7
2019-07-18 10:18:54.987554: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2019-07-18 10:18:54.988526: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2019-07-18 10:18:54.989347: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1763] Adding visible gpu devices: 0
2019-07-18 10:18:54.989418: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudart.so.10.0
2019-07-18 10:18:54.995160: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1181] Device interconnect StreamExecutor with strength 1 edge matrix:
2019-07-18 10:18:54.995475: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1187]      0 
2019-07-18 10:18:54.995629: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1200] 0:   N 
2019-07-18 10:18:54.995938: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2019-07-18 10:18:54.996963: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2019-07-18 10:18:54.997884: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1326] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 8895 MB memory) -> physical GPU (device: 0, name: Tesla K80, pci bus id: 0000:00:1e.0, compute capability: 3.7)
WARNING: Logging before flag parsing goes to stderr.
W0718 10:18:54.999173 140274532570944 deprecation.py:323] From /home/ubuntu/anaconda3/lib/python3.7/site-packages/tensorflow/python/tools/saved_model_cli.py:339: load (from tensorflow.python.saved_model.loader_impl) is deprecated and will be removed in a future version.
Instructions for updating:
This function will only be available through the v1 compatibility library as tf.compat.v1.saved_model.loader.load or tf.compat.v1.saved_model.load. There will be a new function for importing SavedModels in Tensorflow 2.0.
W0718 10:18:55.271977 140274532570944 deprecation.py:323] From /home/ubuntu/anaconda3/lib/python3.7/site-packages/tensorflow/python/training/saver.py:1276: checkpoint_exists (from tensorflow.python.training.checkpoint_management) is deprecated and will be removed in a future version.
Instructions for updating:
Use standard file APIs to check for files with this prefix.
2019-07-18 10:18:56.953677: W tensorflow/compiler/jit/mark_for_compilation_pass.cc:1412] (One-time warning): Not using XLA:CPU for cluster because envvar TF_XLA_FLAGS=--tf_xla_cpu_global_jit was not set.  If you want XLA:CPU, either set that envvar, or use experimental_jit_scope to enable XLA:CPU.  To confirm that XLA is active, pass --vmodule=xla_compilation_cache=1 (as a proper command-line flag, not via TF_XLA_FLAGS) or set the envvar XLA_FLAGS=--xla_hlo_profile.
2019-07-18 10:18:56.979903: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcublas.so.10.0
Result for output key probs:
[[0.14920072 0.07349582 0.12342736 0.12342736]]
curl -d '{"signature_name": "predict_ad_view_prob", "inputs":{"res_to_predict_str": ["9 18788418 19039855 18771619"], "click_hist_str": ["18198449 18656271 18198449"]}}' -X POST http://localhost:8501/v1/models/abhilash:predict