SAM3 Python preprocessing pipeline.
(image_path, img_size=1008)
| 56 | |
| 57 | |
| 58 | def python_preprocess(image_path, img_size=1008): |
| 59 | """SAM3 Python preprocessing pipeline.""" |
| 60 | img = Image.open(image_path).convert("RGB") |
| 61 | transform = v2.Compose([ |
| 62 | v2.ToDtype(torch.uint8, scale=True), |
| 63 | v2.Resize(size=(img_size, img_size)), |
| 64 | v2.ToDtype(torch.float32, scale=True), |
| 65 | v2.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]), |
| 66 | ]) |
| 67 | img_tensor = v2.functional.to_image(img) |
| 68 | return transform(img_tensor).numpy() # [3, H, W] |
| 69 | |
| 70 | |
| 71 | if __name__ == "__main__": |
no outgoing calls
no test coverage detected