Skip to content

Commit db4c207

Browse files
authored
Fix visual observation tensor indexing for Unity inference. (#6239)
This change corrects the tensor indexing calculation in TensorExtensions.Index() to properly support CHW (channels-height-width) format used by both Unity's observation writers and ONNX models during inference.
1 parent a83b3b8 commit db4c207

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

com.unity.ml-agents/Runtime/Inference/TensorExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ public static int Index(this TensorShape shape, int n, int c, int h, int w)
5757
{
5858
int index =
5959
n * shape.Height() * shape.Width() * shape.Channels() +
60-
h * shape.Width() * shape.Channels() +
61-
w * shape.Channels() +
62-
c;
60+
c * shape.Height() * shape.Width() +
61+
h * shape.Width() +
62+
w;
6363
return index;
6464
}
6565
}

0 commit comments

Comments
 (0)