I've optimized the image loading logic

This commit is contained in:
Your Name
2025-12-26 23:39:03 +07:00
parent e40ad68b9b
commit f22e40674c
2 changed files with 4 additions and 4 deletions
+2 -2
View File
@@ -10,8 +10,8 @@ def load_image(path: str) -> torch.Tensor:
Shape: [1, H, W, 3], float32 0..1
"""
img = Image.open(path).convert("RGB")
arr = np.array(img).astype(np.float32) / 255.0
return torch.from_numpy(arr)[None,]
# Optimize: Direct to tensor -> float conversion (avoids intermediate float64 numpy array)
return torch.from_numpy(np.array(img)).float().div_(255.0)[None,]
class BatchLoadImageList:
+2 -2
View File
@@ -10,8 +10,8 @@ def load_image(path: str) -> torch.Tensor:
Shape: [1, H, W, 3], float32 0..1
"""
img = Image.open(path).convert("RGB")
arr = np.array(img).astype(np.float32) / 255.0
return torch.from_numpy(arr)[None,]
# Optimize: Direct to tensor -> float conversion (avoids intermediate float64 numpy array)
return torch.from_numpy(np.array(img)).float().div_(255.0)[None,]
class BatchLoadImageSequence: