tensorflow服务:功能配置数据格式混乱

tensorflow服务:功能配置数据格式混乱,tensorflow,deep-learning,tensorflow-serving,Tensorflow,Deep Learning,Tensorflow Serving,我遵循了tensorflow服务教程 并尝试训练和导出文本cnn分类器模型 管道是 *embedding layer -> cnn -> maxpool -> cnn -> dropout -> output layer Tensorflow数据输入: data\u-in=tf.placeholder(tf.int32,[None,sequence\u-length],name='data\u-in') 转化为 serialized_tf_exampl

我遵循了tensorflow服务教程 并尝试训练和导出文本cnn分类器模型 管道是

*embedding layer -> cnn -> maxpool -> cnn -> dropout -> output layer     
Tensorflow数据输入:

data\u-in=tf.placeholder(tf.int32,[None,sequence\u-length],name='data\u-in')
转化为

serialized_tf_example=tf.placeholder(tf.string,name='tf_example')
feature_configs={'x':tf.FixedLenFeature(shape=[sequence_length],
dtype=tf.int64),}
tf\u example=tf.parse\u示例(序列化的\u tf\u示例,功能\u配置)
#使用tf.identity()分配名称
data_in=tf.identity(tf_示例['x'],name='x')
这适用于培训阶段 但在测试时间 它告诉我们 AbortionError(code=StatusCode.INVALID_参数,details=“预期arg[0]为int64,但提供了字符串”)

我对上面这句话感到困惑

feature\u configs={'x':tf.FixedLenFeature(shape=[sequence\u length],
dtype=tf.int64),}
我把电话换成了

feature\u configs={'x':tf.FixedLenFeature(shape=[sequence\u length],
dtype=tf.string),}
但在训练时会出现以下错误:

Traceback (most recent call last):
  File "/serving/bazel-bin/tensorflow_serving/example/twitter-sentiment-cnn_saved_model.runfiles/tf_serving/tensorflow_serving/example/twitter-sentiment-cnn_saved_model.py", line 222, in <module>
    embedded_chars = tf.nn.embedding_lookup(W, data_in)
  File "/serving/bazel-bin/tensorflow_serving/example/twitter-sentiment-cnn_saved_model.runfiles/org_tensorflow/tensorflow/python/ops/embedding_ops.py", line 122, in embedding_lookup
    return maybe_normalize(_do_gather(params[0], ids, name=name))
  File "/serving/bazel-bin/tensorflow_serving/example/twitter-sentiment-cnn_saved_model.runfiles/org_tensorflow/tensorflow/python/ops/embedding_ops.py", line 42, in _do_gather
    return array_ops.gather(params, ids, name=name)
  File "/serving/bazel-bin/tensorflow_serving/example/twitter-sentiment-cnn_saved_model.runfiles/org_tensorflow/tensorflow/python/ops/gen_array_ops.py", line 1179, in gather
    validate_indices=validate_indices, name=name)
  File "/serving/bazel-bin/tensorflow_serving/example/twitter-sentiment-cnn_saved_model.runfiles/org_tensorflow/tensorflow/python/framework/op_def_library.py", line 589, in apply_op
    param_name=input_name)
  File "/serving/bazel-bin/tensorflow_serving/example/twitter-sentiment-cnn_saved_model.runfiles/org_tensorflow/tensorflow/python/framework/op_def_library.py", line 60, in _SatisfiesTypeConstraint
    ", ".join(dtypes.as_dtype(x).name for x in allowed_list)))
TypeError: Value passed to parameter 'indices' has DataType string not in list of allowed values: int32, int64
回溯(最近一次呼叫最后一次):
文件“/serving/bazel-bin/tensorflow_-serving/example/twitter-emotional-cnn_-saved_model.runfiles/tf_-serving/tensorflow_-serving/example/twitter-emotional-cnn_-saved_model.py”,第222行,在
embedded_chars=tf.nn.embedded_lookup(W,data_in)
文件“/serving/bazel-bin/tensorflow\u serving/example/twitter-emotation-cnn\u saved\u model.runfiles/org\u tensorflow/tensorflow/python/ops/embedded\u ops.py”,嵌入查找中的第122行
返回可能的规格化(_do_gather(参数[0],id,name=name))
文件“/serving/bazel-bin/tensorflow\u serving/example/twitter-emotation-cnn\u saved\u model.runfiles/org\u tensorflow/tensorflow/python/ops/embedded\u ops.py”,第42行,在“收集”
返回数组_ops.gather(参数,ID,name=name)
文件“/serving/bazel-bin/tensorflow\u serving/example/twitter-emotional-cnn\u saved\u model.runfiles/org\u tensorflow/tensorflow/python/ops/gen\u array\u ops.py”,第1179行,聚集
验证索引=验证索引,名称=名称)
文件“/serving/bazel-bin/tensorflow_-serving/example/twitter-emotation-cnn_-saved_model.runfiles/org_tensorflow/tensorflow/python/framework/op_def_library.py”,第589行,在apply_op中
参数名称=输入名称)
文件“/serving/bazel-bin/tensorflow_-serving/example/twitter-emotation-cnn_saved_model.runfiles/org_tensorflow/tensorflow/python/framework/op_def_library.py”,第60行,在满足类型约束中
“,”.join(数据类型.as_数据类型(x).x在允许的_列表中的名称)))
TypeError:传递给参数“Indexes”的值的数据类型字符串不在允许值列表中:int32、int64
您的代码错误:

serialized_tf_example=tf.placeholder(tf.string,name='tf_example')
这意味着您的输入是一个
字符串
,例如句子的单词。因此:

feature\u configs={'x':tf.FixedLenFeature(shape=[sequence\u length],
dtype=tf.int64),}
tf\u example=tf.parse\u示例(序列化的\u tf\u示例,功能\u配置)
在我看来,这并不意味着什么,因为你不会通过词汇表把
string
转换成
int
。您需要加载列车数据的vocab以获取单词索引