Realcat commited on
Commit
a93c459
Β·
verified Β·
1 Parent(s): 6a41936

Update README with onnx/coreml structure

Browse files
Files changed (1) hide show
  1. megaloc/README.md +80 -0
megaloc/README.md ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # MegaLoc Quantized Models
2
+
3
+ Quantized ONNX and CoreML models for [MegaLoc](https://arxiv.org/abs/2502.17237) β€” SOTA visual place recognition.
4
+
5
+ ## Directory
6
+
7
+ ```
8
+ megaloc/
9
+ β”œβ”€β”€ onnx/ # ONNX models (cross-platform)
10
+ β”‚ β”œβ”€β”€ megaloc.onnx # FP32 (873 MB, batch=1)
11
+ β”‚ β”œβ”€β”€ megaloc_fp16.onnx # FP16 (437 MB, dynamic batch)
12
+ β”‚ └── megaloc_int8.onnx # INT8 (223 MB, batch=1)
13
+ └── coreml/ # CoreML models (macOS / Apple Silicon, all multi-batch)
14
+ β”œβ”€β”€ megaloc_coreml_fp32.mlpackage # FP32 (873 MB)
15
+ β”œβ”€β”€ megaloc_coreml_fp16.mlpackage # FP16 (437 MB)
16
+ └── megaloc_coreml_int8.mlpackage # INT8 (219 MB)
17
+ ```
18
+
19
+ ## Benchmark (MacBook Pro M-series, 518Γ—518 input)
20
+
21
+ ### ONNX (CPU)
22
+
23
+ | Model | Size | CosSim | B=1 | B=2 | B=4 | B=8 |
24
+ |-------|------|--------|-----|-----|-----|-----|
25
+ | FP32 | 873 MB | 1.000000 | 399ms / 2.5fps | 872ms / 2.3fps | 1514ms / 2.6fps | 2699ms / 3.0fps |
26
+ | FP16 | 437 MB | 0.999989 | 400ms / 2.5fps | 850ms / 2.4fps | 1602ms / 2.5fps | 2876ms / 2.8fps |
27
+ | INT8 | 223 MB | 0.996453 | 475ms / 2.1fps | β€” | β€” | β€” |
28
+
29
+ FP16 is near-lossless at all batch sizes. INT8 preserves Recall@1 = 100% in retrieval tasks.
30
+
31
+ ### CoreML (Apple Silicon GPU, multi-batch)
32
+
33
+ | Model | Size | CosSim | B=1 latency | Notes |
34
+ |-------|------|--------|-------------|-------|
35
+ | FP32 | 873 MB | 1.000000 | ~74ms / 13fps | RangeDim(1,16) dynamic batch |
36
+ | FP16 | 437 MB | TBD | TBD | RangeDim(1,16) dynamic batch |
37
+ | INT8 | 219 MB | TBD | TBD | RangeDim(1,16) dynamic batch |
38
+
39
+ CoreML is ~5Γ— faster than ONNX Runtime (GPU vs CPU). All CoreML models support dynamic batch via `RangeDim(1, 16)`.
40
+
41
+ ## Usage
42
+
43
+ ### ONNX
44
+
45
+ ```python
46
+ import onnxruntime as ort, numpy as np
47
+ from PIL import Image
48
+
49
+ sess = ort.InferenceSession('megaloc_fp16.onnx', providers=['CPUExecutionProvider'])
50
+
51
+ img = Image.open('image.jpg').convert('RGB').resize((518, 518), Image.LANCZOS)
52
+ data = np.expand_dims(np.array(img).astype(np.float32).transpose(2,0,1)/255.0, 0)
53
+
54
+ descriptor = sess.run(None, {'images': data})[0] # [B, 8448]
55
+ ```
56
+
57
+ ### CoreML (macOS only)
58
+
59
+ ```python
60
+ import coremltools as ct, numpy as np
61
+ from PIL import Image
62
+
63
+ model = ct.models.MLModel('megaloc_coreml_fp16.mlpackage')
64
+
65
+ img = Image.open('image.jpg').convert('RGB').resize((518, 518), Image.LANCZOS)
66
+ data = np.expand_dims(np.array(img).astype(np.float32).transpose(2,0,1)/255.0, 0)
67
+
68
+ descriptor = list(model.predict({'images': data}).values())[0] # [B, 8448]
69
+ ```
70
+
71
+ ## Reference
72
+
73
+ ```bibtex
74
+ @inproceedings{Berton_2025_MegaLoc,
75
+ author = {Berton, Gabriele and Masone, Carlo},
76
+ title = {MegaLoc: One Retrieval to Place Them All},
77
+ booktitle = {CVPR Workshops},
78
+ year = {2025},
79
+ }
80
+ ```