首页 > 解决方案 > TensorFlow op 属性的默认值可以是 NaN 还是 Inf?

问题描述

我的情况是向TensorFlow ImageSummary Opvmin添加和vmax属性。这是我用于此操作注册的代码:

REGISTER_OP("ImageSummary")
    .Input("tag: string")
    .Input("tensor: T")
    .Output("summary: string")
    .Attr("vmin: float = NaN")
    .Attr("vmax: float = NaN")
    .Attr("clip: bool = false")
    .Attr("max_images: int >= 1 = 3")
    .Attr("T: {uint8, float, half, float64} = DT_FLOAT")
    .Attr(
        "bad_color: tensor = { dtype: DT_UINT8 "
        "tensor_shape: { dim { size: 4 } } "
        "int_val: 255 int_val: 0 int_val: 0 int_val: 255 }")
    .SetShapeFn(shape_inference::ScalarShape);

虽然这适用于C++ 测试代码,但在构建整个项目时出现了一些错误:

bazel-out/darwin-opt/genfiles/tensorflow/cc/ops/logging_ops.h:237:19: error: cannot initialize a member subobject of type 'float' with an lvalue of type 'float (const char *)'
    float vmin_ = nanf;
                  ^~~~
bazel-out/darwin-opt/genfiles/tensorflow/cc/ops/logging_ops.h:238:19: error: cannot initialize a member subobject of type 'float' with an lvalue of type 'float (const char *)'
    float vmax_ = nanf;

我认为它应该是float vmin = nanf("")并且float vmax = nanf("")logging_ops.h. 这是 TensorFlow 编译器中的问题吗?或者我可能对设置默认值的语法有一些误解?

对我的案子有什么建议吗?

标签: pythonc++tensorflow

解决方案


推荐阅读