TF:tf.estimator

tf.estimator是比tf.contrib.slim更高级的API,能同时训练和验证模型。[更多]


  1. tf.estimator的有些参数是函数,但又不能带参数,如:
    run_config = tf.estimator.RunConfig().replace(save_checkpoints_secs=1e9)
    model = tf.estimator.Estimator(
          model_fn=deeplab_model.deeplabv3_plus_model_fn,
          model_dir=FLAGS.model_dir,
          config=run_config,
          params={...})

    其中model_fn就只是函数名,其参数在params中指定。

  2. tf.estimator.Estimator.train和tf.estimator.Estimator.evaluate的input_fn也不能带参数,如:
    tf.logging.info("Start training.")
    model.train(
          input_fn=lambda: input_fn(True, FLAGS.data_dir, FLAGS.batch_size, FLAGS.epochs_per_eval),
          hooks=train_hooks,
          # steps=1  # For debug
    )
    
    tf.logging.info("Start evaluation.")
    eval_results = model.evaluate(
          input_fn=lambda: input_fn(False, FLAGS.data_dir, 1),
          hooks=eval_hooks,
          # steps=1  # For debug
    )

    input_fn函数不能带参数,所以使用(1)lambda方式。此外还可以使用python的(2)functools.partial函数,如:

    model.train(
          input_fn=functools.partial(True, FLAGS.data_dir, FLAGS.batch_size, FLAGS.epochs_per_eval),
          hooks=train_hooks,
          # steps=1  # For debug
    )

    还可以向上面的model_fn那样,(2)单独定义函数,再传入函数名,或者使用(4)python wrapper修饰器

  3. 结束。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值