tensorflow - 如何在高级 Estimator api 中使用 tf.print(不是 tf.Print)
问题描述
目前,我正在使用tf.Print
在估计器中打印(调试)张量,但是这个 api 被标记为不推荐使用,并建议我使用 tf.print 代替。根据RFC,通过使用 tf.print,我需要控制正在运行的会话,但Estimator
旨在对用户隐藏会话和图形。那么,如何tf.print
在 Estimator 中使用呢?
解决方案
为了tf.print
在图形模式下使用,这就是tf.estimator
工作原理,您可以直接tf.print
用作 的替代品tf.Print
,您只需在tf.print
执行 model_fn 中的张量之前强制执行操作,因此,给定输入张量,input_
你的model_fn,你可以:
print_op = tf.print(tensor_to_log)
with tf.control_dependencies([print_op]):
first_layer_output = first_inpyt_layer(input_)
甚至
print_op = tf.print(tensor_to_log)
with tf.control_dependencies([print_op]):
input_ = tf.identity(input_)
# define your model using input_ as usual
推荐阅读
- r - 在 rstudio 中重新排序箱线图
- firebase - 使用 Firebase 后端 Flutter 流式购物车总价
- python - 如何在 Python 中从 FTPS 中列出和下载文件
- scheme - 如何跳过方案中的 if 语句
- docker - 是否可以将环境变量从主机传递到托管的 blazor wasm 应用程序?
- android - Sucuri Web 应用程序防火墙是否会在旧版 Android 上阻止来自 Instagram 的链接?
- arrays - 如何修复 Zapier 不显示 JSON Array GET API Repsonse 中显示的所有动态下拉选项?
- java - onGenericMotionEvent 在后台
- ruby-on-rails - 使用 dropzone JS 上传图像时出现“无法验证 CSRF 令牌真实性”和“422”错误的原因是什么?
- ethereum - 如何为 fork Pancakeswap 配置 deploy_contract