tensorflow / tensorflow/java

Unexpected behavior from `tf.math.greaterEqual`

Đang mở
#177 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
Java
Star
928
Fork
227
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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)

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với đoạn mã Java và TestSession ở chế độ GRAPH, sau đó so sánh tensor được tạo ra và kết quả của tf.math.greaterEqual với ví dụ Python. Tái hiện sai khác được báo cáo ở phần tử cuối cùng và xác định liệu sai khác đó do Java binding hay do thiết lập kiểm thử tạo ra; hoàn tất có nghĩa là hành vi đã được giải thích và một regression test hoặc thay đổi khắc phục đã được xác minh.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
java, tensorflow
Lĩnh vực
machine-learning
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
38/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.