由于无法通过TensorFlow服务API提供服务,因此已从导出中排除

戈加斯卡

Tensorflow版本1.10

使用:DNNClassifiertf.estimator.FinalExporter

我正在使用TF博客中的Iris示例我定义了以下代码:

# The CSV features in our training & test data.
COLUMN_NAMES = ['SepalLength',
                'SepalWidth',
                'PetalLength',
                'PetalWidth',
                'Species']
FEATURE_COLUMNS = COLUMN_NAMES[:4]
INPUT_COLUMNS = [
    tf.feature_column.numeric_column(column) for column in COLUMN_NAMES
]

def serving_input_receiver_fn():
  """Build the serving inputs."""
  inputs = {}
  for feat in INPUT_COLUMNS:
    inputs[feat.name] = tf.placeholder(shape=[None], dtype=feat.dtype)
  return tf.estimator.export.ServingInputReceiver(inputs, inputs)

这就是我调用函数的方式:

  train_spec = tf.estimator.TrainSpec(
      train_input, max_steps=hparams.train_steps)
  exporter = tf.estimator.FinalExporter(
      'iris', serving_input_receiver_fn)
  eval_spec = tf.estimator.EvalSpec(
      eval_input,
      steps=hparams.eval_steps,
      exporters=[exporter],
      name='iris-eval')
  run_config = tf.estimator.RunConfig(
      session_config=_get_session_config_from_env_var())
  run_config = run_config.replace(model_dir=hparams.job_dir)
  print('Model dir: %s', run_config.model_dir)
  estimator = model.build_estimator(
      # Construct layers sizes.
      config=run_config,
      hidden_units=[10, 20, 10],
      n_classes=3)
  tf.estimator.train_and_evaluate(estimator, train_spec, eval_spec)

我收到以下消息:

INFO:tensorflow:Done calling model_fn.
INFO:tensorflow:Signatures INCLUDED in export for Eval: None
INFO:tensorflow:Signatures INCLUDED in export for Classify: None
INFO:tensorflow:Signatures INCLUDED in export for Regress: None
INFO:tensorflow:Signatures INCLUDED in export for Predict: ['predict']
INFO:tensorflow:Signatures INCLUDED in export for Train: None
INFO:tensorflow:Signatures EXCLUDED from export because they cannot be be served via TensorFlow Serving APIs:
INFO:tensorflow:'serving_default' : Classification input must be a single string Tensor; got {'SepalLength': <tf.Tensor 'Placeholder:0' shape=(?,) dtype=float32>, 'PetalLength': <tf.Tensor 'Placeholder_2:0' shape=(?,) dtype=float32>, 'PetalWidth': <tf.Tensor 'Placeholder_3:0' shape=(?,) dtype=float32>, 'SepalWidth': <tf.Tensor 'Placeholder_1:0' shape=(?,) dtype=float32>, 'Species': <tf.Tensor 'Placeholder_4:0' shape=(?,) dtype=float32>}
INFO:tensorflow:'classification' : Classification input must be a single string Tensor; got {'SepalLength': <tf.Tensor 'Placeholder:0' shape=(?,) dtype=float32>, 'PetalLength': <tf.Tensor 'Placeholder_2:0' shape=(?,) dtype=float32>, 'PetalWidth': <tf.Tensor 'Placeholder_3:0' shape=(?,) dtype=float32>, 'SepalWidth': <tf.Tensor 'Placeholder_1:0' shape=(?,) dtype=float32>, 'Species': <tf.Tensor 'Placeholder_4:0' shape=(?,) dtype=float32>}
WARNING:tensorflow:Export includes no default signature!

当我打印时,serving_input_receiver_fn我得到:

ServingInputReceiver(features={'sepal_width': <tf.Tensor 'Placeholder_1:0' shape=(?, 1) dtype=float32>, 'petal_width': <tf.Tensor 'Placeholder_3:0' shape=(?, 1) dtype=float32>, 'sepal_length': <tf.Tensor 'Placeholder:0' shape=(?, 1) dtype=float32>, 'petal_length': <tf.Tensor 'Placeholder_2:0' shape=(?, 1) dtype=float32>}, receiver_tensors={'sepal_width': <tf.Tensor 'Placeholder_1:0' shape=(?, 1) dtype=float32>, 'petal_width': <tf.Tensor 'Placeholder_3:0' shape=(?, 1) dtype=float32>, 'sepal_length': <tf.Tensor 'Placeholder:0' shape=(?, 1) dtype=float32>, 'petal_length': <tf.Tensor 'Placeholder_2:0' shape=(?, 1) dtype=float32>}, receiver_tensors_alternatives=None)

在导出文件夹中没有任何内容(CSV,JSON等):

gs://<my-bucket>/iris/iris_20181014_214916/export/:
gs://<my-bucket>/iris/iris_20181014_214916/export/
戈加斯卡

我在这里找到了解决方案

def _make_input_parser(with_target=True):
  """Returns a parser func according to file_type, task_type and target.
  Need to set record_default for last column to integer instead of float in
  case of classification tasks.
  Args:
    with_target (boolean): Pass label or not.
  Returns:
    It returns a parser.
  """

  def _decode_csv(line):
    """Takes the string input tensor and parses it to feature dict and target.
    All the columns except the first one are treated as feature column. The
    first column is expected to be the target.
    Only returns target for if with_target is True.
    Args:
      line: csv rows in tensor format.
    Returns:
      features: A dictionary of features with key as "column_names" from
        self._column_header.
      target: tensor of target values which is the first column of the file.
        This will only be returned if with_target==True.
    """
    column_header = column_names if with_target else column_names[:4]
    record_defaults = [[0.] for _ in xrange(len(column_names) - 1)]
    # Pass label as integer.
    if with_target:
      record_defaults.append([0])
    columns = tf.decode_csv(line, record_defaults=record_defaults)
    features = dict(zip(column_header, columns))
    target = features.pop(column_names[4]) if with_target else None
    return features, target

  return _decode_csv


def serving_input_receiver_fn():
  """This is used to define inputs to serve the model.
  Returns:
    A ServingInputReciever object.
  """
  csv_row = tf.placeholder(shape=[None], dtype=tf.string)
  features, _ = _make_input_parser(with_target=False)(csv_row)
  return tf.estimator.export.ServingInputReceiver(features,
                                                  {'csv_row': csv_row})

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

“由于路径/价格的集成格式错误,因此无法解析API定义。(服务:AmazonApiGateway;状态代码:400;

由于链接服务器的OLE DB提供程序“ SQLNCLI11”无法开始分布式事务,因此无法执行该操作

由于无法使用身份验证服务,因此无法安装或删除软件

Laravel 5 View Composer服务提供商,从通配符中排除前缀

Jupyter Notebook:由于Websocket连接失败,因此无法连接到服务器

由于该文件已在Windows Defender服务中打开,因此无法完成该操作

由于服务器拒绝了连接,因此无法部署到Heroku

由于一个或多个端口无效,因此服务器无法启动[Eclipse中的Tomcat]

由于端口3306在本地被阻止,因此无法访问远程MySQL服务

从ng服务中排除文件夹

由于错误提示我必须提供请求正文,因此无法发布到商家 API

通过Express服务React应用时,从express.static中排除index.html

由于Windows服务导致错误,因此运行ruby exe文件

由于Windows服务导致错误,因此运行ruby exe文件

JPA:由于不正确的值从客户端传递到服务器,因此无法持久记录

由于服务帐户没有必要的权限,因此无法在Firebase云功能中创建自定义令牌

由于出现意外的令牌ILLEGAL,因此无法在JavaScript中使用服务器端变量

由于类类型的转换错误,因此无法通过

如何解决此错误(服务器繁忙,记录已保存。但是,由于服务器繁忙,因此无法显示数据)

从域范围的授权(服务帐户)中排除用户的子集

如何从@WebMvcTest中排除@SpringBootApplication中有线的服务

WCF服务-哪些部分可以从源代码管理中排除?

通过Python Flask服务器提供服务时,Vue应用无法加载

使用ClientsModule.registerAsync()时,无法访问从共享模块提供的模块导出的服务

POSTMAN 无法通过 Azure API 管理服务访问 API

nginx通过套接字配置向json api服务提供服务请求

由于服务器无法连接到ClearDB MySQL,因此无法在Bluemix Build&Deploy Pipeline中运行单元测试

由于出现“无法创建项目锁实体”错误,因此无法将helloworld应用部署到mobilefirst开发服务器(7.0)

由于权限原因,logstash服务无法启动