pyflink.multimodal.utils.batch_to_tensor#
- batch_to_tensor(batch, device=None)[source]#
Convert an ndarray batch to a PyTorch tensor.
Performs HWC -> CHW transposition (PyTorch convention) and optional device transfer. If the input is uint8, it is converted to float32 and scaled to [0, 1] first; float32 input is used as-is.
- Parameters
batch – np.ndarray with shape
(N, H, W, C).device – Target device (str or
torch.device), e.g."cuda:0".Nonemeans CPU.
- Returns
torch.Tensorwith shape(N, C, H, W), dtype float32.
Example:
batch = resize_batch(pixel_arrays, (224, 224)) normed = normalize_batch(batch) tensor = batch_to_tensor(normed, device="cuda:0") output = model(tensor)