作用

是一个class(类),是定义在model_fn中的,并且model_fn返回的也是它的一个实例,这个实例是用来初始化Estimator类的
(Ops and objects returned from a model_fn and passed to an Estimator.)

具体细节

Creates a validated EstimatorSpec instance.

@staticmethod
__new__(cls,mode,predictions=None,loss=None,train_op=None,eval_metric_ops=None,export_outputs=None,training_chief_hooks=None,training_hooks=None,scaffold=None,evaluation_hooks=None,prediction_hooks=None
)
'''
Args:mode: A ModeKeys. Specifies if this is training, evaluation or prediction.predictions: Predictions Tensor or dict of Tensor.loss: Training loss Tensor. Must be either scalar, or with shape [1].train_op: Op for the training step.eval_metric_ops: Dict of metric results keyed by name. The values of the dict can be one of the following: (1) instance of Metric class. (2) Results of calling a metric function, namely a (metric_tensor, update_op) tuple. metric_tensor should be evaluated without any impact on state (typically is a pure computation results based on variables.). For example, it should not trigger the update_op or requires any input fetching.export_outputs: Describes the output signatures to be exported to SavedModel and used during serving. A dict {name: output} where:name: An arbitrary name for this output.output: an ExportOutput object such as ClassificationOutput, RegressionOutput, or PredictOutput. Single-headed models only need to specify one entry in this dictionary. Multi-headed models should specify one entry for each head, one of which must be named using signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY. If no entry is provided, a default PredictOutput mapping to predictions will be created.training_chief_hooks: Iterable of tf.train.SessionRunHook objects to run on the chief worker during training.training_hooks: Iterable of tf.train.SessionRunHook objects to run on all workers during training.scaffold: A tf.train.Scaffold object that can be used to set initialization, saver, and more to be used in training.evaluation_hooks: Iterable of tf.train.SessionRunHook objects to run during evaluation.prediction_hooks: Iterable of tf.train.SessionRunHook objects to run during predictions.Returns:A validated EstimatorSpec object.
'''

主要参数说明

predictions: Predictions Tensor or dict of Tensor.(模型的预测输出,主要是在infer阶段,在 分类是:预测的类别,在文本生成是:生成的文本)
loss:Training loss Tensor. Must be either scalar, or with shape [1]. 损失。主要用在train 和 dev中
train_op :Op for the training step.(是一个操作,用来训练)
eval_metric_ops:Dict of metric results keyed by name. The values of the dict can be one of the following: **(1) instance of Metric class **. (2): Results of calling a metric function, namely a (metric_tensor, update_op) tuple. metric_tensor should be evaluated without any impact on state (typically is a pure computation results based on variables.). For example, it should not trigger the update_op or requires any input fetching.例如 可以是 tf.metrics.accuracy(labels,predictions)

说明

创建一个可以利用的EstimatorSpec实例,其根据不同的mode值,需要不同的参数创建不同的实例(主要是 训练train,验证dev,测试test):

For mode==ModeKeys.TRAIN: 需要的参数是 loss and train_op.
For mode==ModeKeys.EVAL:  需要的参数是  loss.
For mode==ModeKeys.PREDICT: 需要的参数是 predictions.

其是定义在 一个名为mode_fn的方法中,这个mode_fn可以计算各个mode下的参数需求,定义好的EstimatorSpec 用来初始化 一个Estimator实例,同时Estimator实例可以根据mode的不同自动的忽视一些参数(操作),例如:train_op will be ignored in eval and infer modes.

官方给的例子

def my_model_fn(features, labels, mode):predictions = ...loss = ...train_op = ...return tf.estimator.EstimatorSpec(mode=mode,predictions=predictions,loss=loss,train_op=train_op)

tf.estimator.EstimatorSpec讲解相关推荐

  1. tf.estimator.Estimator讲解

    tf.estimator.Estimator 简单介绍 是一个class 所以需要初始化,作用是用来 训练和评价 tensorflow 模型的 Estimator对象包装由一个名为model_fn函数 ...

  2. tf.estimator的用法

    tf.estimator的用法 利用 tf.estimator 训练模型时需要写两个重要的函数,一个用于数据输入的函数(input_fn),另一个用于模型创建的函数(model_fn).下面逐一来说明 ...

  3. tf.estimator.Estimator的使用

    tf.estimator.Estimator是TF比较高级的接口. 最近在使用bert预训练模型的时候用到了tf.estimator.Estimator.使用该接口的时候需要开发者完成的工作比较少,一 ...

  4. 机器学习笔记5-Tensorflow高级API之tf.estimator

    前言 本文接着上一篇继续来聊Tensorflow的接口,上一篇中用较低层的接口实现了线性模型,本篇中将用更高级的API--tf.estimator来改写线性模型. 还记得之前的文章<机器学习笔记 ...

  5. tf.estimator用法

    estimator:估算器 tf.estimator -----一种高级TensorFlow API.估算器封装以下操作: 训练(training) 评价(evaluation) 预测(predict ...

  6. tf.estimator API技术手册(16)——自定义Estimator

    tf.estimator API技术手册(16)--自定义Estimator (一)前 言 (二)自定义estimator的一般步骤 (三)准备训练数据 (四)自定义estimator实践 (1)创建 ...

  7. [tensorflow]tf.estimator.Estimator构建tensorflow模型

    目录 一.Estimator简介 二.数据集 三.定义特征列 四.estimator创建模型 五.模型训练.评估和预测 六.模型保存和恢复 一.Estimator简介 Estimator是Tensor ...

  8. Tensorflow API 讲解——tf.estimator.Estimator

    class Estimator(builtins.object) #介绍 Estimator 类,用来训练和验证 TensorFlow 模型. Estimator 对象包含了一个模型 model_fn ...

  9. tf.estimator.Estimator解析

    Estimator类代表了一个模型,以及如何对这个模型进行训练和评估, class Estimator(builtins.object) 可以按照下面方式创建一个E def resnet_v1_10_ ...

最新文章

  1. 三、openstack安装之Glance篇
  2. 密歇根大学28页最新《GANs生成式对抗网络综述:算法、理论与应用》最新论文,带你全面了解GAN技术趋势...
  3. OSPF HELLO数据包
  4. 20171218-编程语言的介绍
  5. java注释详解--javadoc注释
  6. 方程AX=b的解的讨论(特解、通解、零空间向量等概念)及其MATLAB实现
  7. SAP Spartacus产品明细页面用Observable显示产品名称
  8. hadoop集群的搭建(分布式安装)
  9. JavaScript 设计模式核⼼原理与应⽤实践 之 创建型:工厂模式·抽象工厂——理解“开放封闭”
  10. ebpf深入理解和应用介绍
  11. jquery 自定义正方形图标_当你在玩 iOS14自定义图标时,有人用它赚了70万了!
  12. java应用中如何连接dbproxy_GitHub - alchemystar/hero: 用c语言写的dbproxy
  13. HFSS天线设计过程学习笔记
  14. 北京二手房上周成交环比增六成 个别业主涨价出售
  15. 自己小米4c 高通9008模式刷机 低版本 亲测有效
  16. 苹果自带相册打马赛克_一键消除“马赛克”,这个软件太牛了,网友:我有一个大胆的想法...
  17. win7家庭版计算机桌面,Win7 home basic家庭普通版显示桌面图标的方法
  18. kronecker引理证明_连续型Kronecker引理
  19. 用html实现彩虹动画
  20. 数据库课程设计:图书信息管理系统(Java+MySQL)(附程序)

热门文章

  1. java-php-python-科技专业师生沟通平台计算机毕业设计
  2. c语言游戏代码(c语言制作小游戏)
  3. 应急灯电源驱动方案:OC5205 30V/1.5A ,可完美替代PT4205/PT4115
  4. 物联网毕业设计 - 基于STM32的轮足两用可变形环境感知探测机器人
  5. 获取Shell命令执行错误结果
  6. 农历虎年快到了,我用 Python 写副春联恭祝大家幸福平安
  7. Java编程那些事儿69——抽象类和接口(二)
  8. jquery ajax,ashx,json用法小结
  9. 机器学习入门:准备知识笔记(seaborn及案例)
  10. linux下文件对比工具详解(diff、diff3、sdiff、vimdiff和comm)