This is an automated email from the ASF dual-hosted git repository.

vterentev pushed a commit to branch oss-image-cpu
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/oss-image-cpu by this push:
     new f773695c926 Fix float for imagenet rightfit
f773695c926 is described below

commit f773695c926fc9648fcf6fa0aac00f5925329a56
Author: Vitaly Terentyev <[email protected]>
AuthorDate: Thu Jan 29 16:10:43 2026 +0400

    Fix float for imagenet rightfit
---
 .../examples/inference/pytorch_imagenet_rightfit.py            | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git 
a/sdks/python/apache_beam/examples/inference/pytorch_imagenet_rightfit.py 
b/sdks/python/apache_beam/examples/inference/pytorch_imagenet_rightfit.py
index 76daded4f48..79e553c0652 100644
--- a/sdks/python/apache_beam/examples/inference/pytorch_imagenet_rightfit.py
+++ b/sdks/python/apache_beam/examples/inference/pytorch_imagenet_rightfit.py
@@ -88,12 +88,14 @@ def decode_and_preprocess(image_bytes: bytes, size: int = 
224) -> torch.Tensor:
 
     # To tensor [0..1]
     import numpy as np
+    mean = np.array(IMAGENET_MEAN, dtype=np.float32)
+    std = np.array(IMAGENET_STD, dtype=np.float32)
     arr = np.asarray(img).astype("float32") / 255.0  # H,W,3
     # Normalize
-    arr = (arr - IMAGENET_MEAN) / IMAGENET_STD
+    arr = (arr - mean) / std
     # HWC -> CHW
-    arr = np.transpose(arr, (2, 0, 1))
-    return torch.from_numpy(arr)  # float32, shape (3,224,224)
+    arr = np.transpose(arr, (2, 0, 1)).astype("float32")
+    return torch.from_numpy(arr).float()  # float32, shape (3,224,224)
 
 
 class RateLimitDoFn(beam.DoFn):
@@ -480,7 +482,7 @@ def run(
 
   to_infer = (
       preprocessed
-      | 'ToKeyedTensor' >> beam.Map(lambda kv: (kv[0], kv[1]["tensor"])))
+      | 'ToKeyedTensor' >> beam.Map(lambda kv: (kv[0], 
kv[1]["tensor"].float())))
 
   predictions = (
       to_infer

Reply via email to