tensorflow / tensorflow/java

Unexpected behavior from `tf.math.greaterEqual`

未关闭
#177 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Java
星标
928
派生
227
PR 合并指标
30 天内没有已合并 PR

描述

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow):
    Custom code
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04):
    macOS BigSur 11.1
  • TensorFlow installed from (source or binary):
    TensorFlow Java latest GitHub, based on karl/tensor-ttype

I have the following code snippet.

       Operand<TFloat32> r = tf.random.randomUniform(tf.constant(Shape.of(3,2)), TFloat32.class,   
                                                         RandomUniform.seed(1001L));
      Operand<TFloat32> rate1 = tf.constant(0.5f);
      Operand<TBool> mask = tf.math.greaterEqual(r, rate1);

The generated random sequence (shape 3,2) is:

0,0). 0.028465
0,1). 0.936395
1.0). 0.035310
1,1). 0.230565
2,0). 0.269415
2,1). 0.145439

Describe the current behavior
When I run this code, I get mask values of:

0,0). false
0,1). true
1,0). false
1,1). false
2,0). false
2,1). true

Describe the expected behavior
I expected mask values to be:

0,0). false
0,1). true
1,0). false
1,1). false
2,0). false
2,1). false

The last random number, 0.145439, is less than 0.5.

Code to reproduce the issue
Provide a reproducible test case that is the bare minimum necessary to generate the problem.

try (TestSession session = TestSession.createTestSession(TestSession.Mode.GRAPH)) {
      Ops tf = session.getTF();
       Operand<TFloat32> random = tf.random.randomUniform(tf.constant(Shape.of(3,2), TFloat32.class,   
                                                         RandomUniform.seed(1001L));
      Operand<TFloat32> rate = tf.constant(0.5f);
      Operand<TBool> mask = tf.math.greaterEqual(r, rate);

      System.out.println("******** MASK ***************");
      System.out.println("random:");
      session.print(random);
      System.out.println("rate1:");
      session.print(rate1);
      System.out.println("mask:");
      session.print(mask);
      System.out.println("******** MASK ***************");
}

If I do this code in Python it works as expected:

import tensorflow as tf
a = [
    [0.028465 ,  0.936395],
    [0.035310 , 0.230565],
    [0.269415 , 0.145439]
]
print(a);
rate = 0.5
b = tf.math.greater_equal(a, rate);
print(b)

Output:

[[0.028465, 0.936395], [0.03531, 0.230565], [0.269415, 0.145439]]
tf.Tensor(
[[False  True]
 [False False]
 [False False]], shape=(3, 2), dtype=bool)

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

先从 Java 代码片段和 GRAPH 模式下的 TestSession 开始,然后将生成的张量和 tf.math.greaterEqual 的结果与 Python 示例进行比较。重现所报告的最后一个元素不匹配问题,并确定该问题是由 Java binding 还是测试设置产生的;完成的标准是解释清楚该行为,并验证 regression test 或修复性更改。

由索引模型根据 Issue 内容生成。

评估

技术栈
java, tensorflow
领域
machine-learning
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
38/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。