下面是代码片段,我想在其中构建一个图像摘要。
import tensorflow as tf
from tensorflow.python.ops import gen_logging_ops
from tensorflow.python.framework import ops as _ops
def build_image_summary():
log_image_data = tf.placeholder(tf.uint8, [None, None, 3])
log_image_name = tf.placeholder(tf.string)
log_image = gen_logging_ops._image_summary(log_image_name, tf.expand_dims(log_image_data, 0), max_images=1)
_ops.add_to_collection(_ops.GraphKeys.SUMMARIES, log_image)
return log_image, log_image_data, log_image_name但执行上面的代码时,我的属性错误如下:
AttributeError: module 'tensorflow.python.ops.gen_logging_ops' has no attribute '_image_summary'我将gen_logging_ops._image_summary更改为gen_logging_ops.summary.image,但仍然收到新的错误!我使用的是tensorflow 1.15.2版。如何解决此错误?
发布于 2021-08-23 03:53:36
tf_op_gen_wrapper_py bazel规则是生成gen_文件的规则。如上所述,在此答案中,此规则生成此库中定义的ops的所有python包装器:
py_library(
name = "logging_ops",
srcs = ["ops/logging_ops.py"],
srcs_version = "PY2AND3",
deps = [
":framework_for_generated_wrappers",
":logging_ops_gen",
":util",
],
)在logging_ops的情况下有一个间接的原因:对tf_op_gen_wrapper_py的调用隐藏在tf_gen_op_wrapper_private_py中:
tf_gen_op_wrapper_private_py(
name = "logging_ops_gen",
visibility = [
"//learning/brain/python/ops:__pkg__",
"//tensorflow/python/kernel_tests:__pkg__",
],
)发布于 2021-08-23 04:34:27
从gen_logging_ops._image_summary替换为gen_logging_ops.image_summary。这解决了我的问题!
https://stackoverflow.com/questions/68887096
复制相似问题