Views
No views yet
| Component | Input | Outputs | Parameters |
|---|---|---|---|
hand_detector.mlpackage | image: 1 × 3 × 256 × 256 FP32 RGB | box_coords: 1 × 2944 × 18; box_scores: 1 × 2944 × 1 | 1.76M |
hand_landmark_detector.mlpackage | image: 1 × 3 × 256 × 256 FP32 RGB crop | scores: 1; lr: 1; landmarks: 1 × 21 × 3 | 2.01M |
1from pathlib import Path
2
3import coremltools as ct
4import numpy as np
5from huggingface_hub import snapshot_download
6from PIL import Image, ImageOps
7
8root = Path(snapshot_download(
9 repo_id="hugging-mac/mediapipe-hand-coreml",
10 allow_patterns=["coreml/**"],
11)) / "coreml"
12
13detector = ct.models.MLModel(
14 root / "hand_detector.mlpackage",
15 compute_units=ct.ComputeUnit.ALL,
16)
17image = ImageOps.pad(Image.open("hand.jpg").convert("RGB"), (256, 256))
18value = np.asarray(image, dtype=np.float32) / 255.0
19tensor = np.ascontiguousarray(value.transpose(2, 0, 1))[None]
20outputs = detector.predict({"image": tensor})
21
22print(outputs["box_coords"].shape) # (1, 2944, 18)
23print(outputs["box_scores"].shape) # (1, 2944, 1)6.866e-51.526e-43.92e-84.59e-64.47e-7013e27b599e37c3b4c69439de15de53cc5b5708ev0.60.0, ONNX floathand_detector.mlpackage SHA-256: a81143ef0bfa896d4206caf226697141ab8c052d57ba5e95fc7c7ac2660dc83dhand_landmark_detector.mlpackage SHA-256: d4049538d8fe4b4ffa77f71e1efa43705fc010e721c0456a95d9c97453c137165432c988be7ed2fd6847097f823e0d813f97be7dc7a7d6587129386dbcd75929