MCPcopy Create free account
hub / github.com/PABannier/sam3.cpp / python_preprocess

Function python_preprocess

tests/compare_preprocessing.py:58–68  ·  view source on GitHub ↗

SAM3 Python preprocessing pipeline.

(image_path, img_size=1008)

Source from the content-addressed store, hash-verified

56
57
58def 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
71if __name__ == "__main__":

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected