benjipeng commited on
Commit
0f5fa27
·
verified ·
1 Parent(s): 5d8c455

Add SHARP NDC ONNX FP32 (opset18) + external data

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ sharp_ndc_opset18.onnx.data filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ # Colab / notebooks
2
+ .ipynb_checkpoints/
3
+
4
+ # If you ever use upload_large_folder, it creates a local cache directory
5
+ cache/
6
+ **/cache/huggingface/
LICENSE ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Copyright (C) 2025 Apple Inc. All Rights Reserved.
2
+
3
+ Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
4
+ Inc. ("Apple") in consideration of your agreement to the following
5
+ terms, and your use, installation, modification or redistribution of
6
+ this Apple software constitutes acceptance of these terms. If you do
7
+ not agree with these terms, please do not use, install, modify or
8
+ redistribute this Apple software.
9
+
10
+ In consideration of your agreement to abide by the following terms, and
11
+ subject to these terms, Apple grants you a personal, non-exclusive
12
+ license, under Apple's copyrights in this original Apple software (the
13
+ "Apple Software"), to use, reproduce, modify and redistribute the Apple
14
+ Software, with or without modifications, in source and/or binary forms;
15
+ provided that if you redistribute the Apple Software in its entirety and
16
+ without modifications, you must retain this notice and the following
17
+ text and disclaimers in all such redistributions of the Apple Software.
18
+ Neither the name, trademarks, service marks or logos of Apple Inc. may
19
+ be used to endorse or promote products derived from the Apple Software
20
+ without specific prior written permission from Apple. Except as
21
+ expressly stated in this notice, no other rights or licenses, express or
22
+ implied, are granted by Apple herein, including but not limited to any
23
+ patent rights that may be infringed by your derivative works or by other
24
+ works in which the Apple Software may be incorporated.
25
+
26
+ The Apple Software is provided by Apple on an "AS IS" basis. APPLE
27
+ MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
28
+ THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
29
+ FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
30
+ OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
31
+
32
+ IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
33
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35
+ INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
36
+ MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
37
+ AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
38
+ STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
39
+ POSSIBILITY OF SUCH DAMAGE.
40
+
41
+
42
+ -------------------------------------------------------------------------------
43
+ SOFTWARE DISTRIBUTED IN THIS REPOSITORY:
44
+
45
+ This software includes a number of subcomponents with separate
46
+ copyright notices and license terms - please see the file ACKNOWLEDGEMENTS.
47
+ -------------------------------------------------------------------------------
README.md ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: onnxruntime
3
+ tags:
4
+ - onnx
5
+ - apple
6
+ - sharp
7
+ - view-synthesis
8
+ - 3d-gaussian-splatting
9
+ base_model: apple/Sharp
10
+ ---
11
+
12
+ # SHARP (NDC) — ONNX FP32 (opset 18)
13
+
14
+ This repository contains an **ONNX FP32** export of Apple's **SHARP** model ("Single-image view synthesis via 3D Gaussians"), exported from the official checkpoint **sharp_2572gikvuh.pt**.
15
+
16
+ ## What this ONNX contains (important)
17
+ This ONNX exports **only the core predictor network**:
18
+
19
+ `gaussians_ndc = predictor(image_resized_pt, disparity_factor)`
20
+
21
+ It outputs **3D Gaussians in NDC space**.
22
+ It does **NOT** include the NDC→metric unprojection step because Apple's unprojection path uses SVD + CPU fp64 conversions, which is not a good fit for ONNX portability.
23
+
24
+ If you want metric-space Gaussians and/or `.ply` export, do that step outside ONNX (e.g., reuse Apple’s `sharp.utils.gaussians.unproject_gaussians` in Python).
25
+
26
+ ## Files
27
+ - `sharp_ndc_opset18.onnx` (graph)
28
+ - `sharp_ndc_opset18.onnx.data` (external weights — required!)
29
+ - `export_config.json`, `run_manifest.json`, `parity_metrics.json` for reproducibility
30
+
31
+ ## Input contract
32
+ **Inputs**
33
+ - `image_resized_pt`: float32 tensor of shape **[1, 3, 1536, 1536]**
34
+ - RGB
35
+ - normalized to **[0, 1]** (divide by 255)
36
+ - resized with **bilinear** and **align_corners=True**
37
+ - layout **NCHW**
38
+ - `disparity_factor`: float32 tensor of shape **[1]**
39
+ - computed as: `disparity_factor = f_px / width_original`
40
+
41
+ Where:
42
+ - `width_original` is the input image width before resizing
43
+ - `f_px` is focal length in pixels (Apple code defaults if EXIF is missing)
44
+
45
+ **Outputs**
46
+ - `mean_vectors`: [1, 1179648, 3]
47
+ - `singular_values`: [1, 1179648, 3]
48
+ - `quaternions`: [1, 1179648, 4]
49
+ - `colors`: [1, 1179648, 3]
50
+ - `opacities`: [1, 1179648]
51
+
52
+ All outputs are float32.
53
+
54
+ ## Minimal ONNX Runtime example
55
+
56
+ ```python
57
+ import numpy as np
58
+ import onnxruntime as ort
59
+
60
+ sess = ort.InferenceSession(
61
+ "sharp_ndc_opset18.onnx",
62
+ providers=["CUDAExecutionProvider", "CPUExecutionProvider"],
63
+ )
64
+
65
+ # Provide:
66
+ # - image_resized_pt as np.float32 [1,3,1536,1536]
67
+ # - disparity_factor as np.float32 [1]
68
+ outputs = sess.run(
69
+ ["mean_vectors","singular_values","quaternions","colors","opacities"],
70
+ {"image_resized_pt": image_resized_pt, "disparity_factor": disparity_factor},
71
+ )
72
+ ```
73
+
74
+
export_config.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "onnx_path": "/content/sharp_work/phase3/onnx/sharp_ndc_opset18.onnx",
3
+ "opset_version": 18,
4
+ "inputs": {
5
+ "image_resized_pt": [
6
+ 1,
7
+ 3,
8
+ 1536,
9
+ 1536
10
+ ],
11
+ "disparity_factor": [
12
+ 1
13
+ ]
14
+ },
15
+ "outputs": [
16
+ "mean_vectors",
17
+ "singular_values",
18
+ "quaternions",
19
+ "colors",
20
+ "opacities"
21
+ ],
22
+ "external_data": true,
23
+ "dynamo": true
24
+ }
inference_onnx.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ from PIL import Image
3
+ import onnxruntime as ort
4
+
5
+ def preprocess(image_path: str, f_px: float) -> tuple[np.ndarray, np.ndarray]:
6
+ img = Image.open(image_path).convert("RGB")
7
+ w, h = img.size
8
+ x = np.asarray(img).astype(np.float32) / 255.0 # HWC [0,1]
9
+ x = np.transpose(x, (2, 0, 1))[None, ...] # NCHW
10
+ # Resize to 1536x1536 with bilinear + align_corners=True:
11
+ # For a minimal example, rely on ORT/consumer to match training preprocessing.
12
+ # (For exact match, use the same resize code as Apple.)
13
+ disparity_factor = np.array([f_px / float(w)], dtype=np.float32)
14
+ return x.astype(np.float32), disparity_factor
15
+
16
+ if __name__ == "__main__":
17
+ sess = ort.InferenceSession(
18
+ "sharp_ndc_opset18.onnx",
19
+ providers=["CUDAExecutionProvider", "CPUExecutionProvider"],
20
+ )
21
+ print("Providers:", sess.get_providers())
22
+ # Example usage requires you to supply f_px (or choose an approximate default).
23
+ # image_resized_pt should be [1,3,1536,1536] — see README for exact contract.
onnx_export_2026-01-11_23-38-28-892967_success.md ADDED
The diff for this file is too large to render. See raw diff
 
parity_metrics.json ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "providers": [
3
+ "CUDAExecutionProvider",
4
+ "CPUExecutionProvider"
5
+ ],
6
+ "outputs": {
7
+ "mean_vectors": {
8
+ "shape": [
9
+ 1,
10
+ 1179648,
11
+ 3
12
+ ],
13
+ "dtype": "float32",
14
+ "max_abs": 0.13911914825439453,
15
+ "mean_abs": 0.00018130234093405306,
16
+ "ref_max_abs": 6.372216701507568,
17
+ "nan_out": false,
18
+ "inf_out": false
19
+ },
20
+ "singular_values": {
21
+ "shape": [
22
+ 1,
23
+ 1179648,
24
+ 3
25
+ ],
26
+ "dtype": "float32",
27
+ "max_abs": 0.035487107932567596,
28
+ "mean_abs": 4.6182478399714455e-05,
29
+ "ref_max_abs": 0.07875056564807892,
30
+ "nan_out": false,
31
+ "inf_out": false
32
+ },
33
+ "quaternions": {
34
+ "shape": [
35
+ 1,
36
+ 1179648,
37
+ 4
38
+ ],
39
+ "dtype": "float32",
40
+ "max_abs": 13.2420015335083,
41
+ "mean_abs": 0.008916228078305721,
42
+ "ref_max_abs": 20.611085891723633,
43
+ "nan_out": false,
44
+ "inf_out": false
45
+ },
46
+ "colors": {
47
+ "shape": [
48
+ 1,
49
+ 1179648,
50
+ 3
51
+ ],
52
+ "dtype": "float32",
53
+ "max_abs": 0.06479707360267639,
54
+ "mean_abs": 0.0002580047002993524,
55
+ "ref_max_abs": 0.9927035570144653,
56
+ "nan_out": false,
57
+ "inf_out": false
58
+ },
59
+ "opacities": {
60
+ "shape": [
61
+ 1,
62
+ 1179648
63
+ ],
64
+ "dtype": "float32",
65
+ "max_abs": 0.6220522522926331,
66
+ "mean_abs": 0.008647891692817211,
67
+ "ref_max_abs": 1.0,
68
+ "nan_out": false,
69
+ "inf_out": false
70
+ }
71
+ }
72
+ }
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ numpy
2
+ pillow
3
+ onnxruntime-gpu
run_manifest.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "python": "3.12.12 (main, Oct 10 2025, 08:52:57) [GCC 11.4.0]",
3
+ "platform": "Linux-6.6.105+-x86_64-with-glibc2.35",
4
+ "torch": "2.9.0+cu126",
5
+ "torch_cuda": "12.6",
6
+ "cuda_available": true,
7
+ "gpu": "NVIDIA L4",
8
+ "checkpoint_path": "/content/sharp_work/weights/sharp_2572gikvuh.pt",
9
+ "checkpoint_sha256": "94211a75198c47f61fca7d739ba08a215418d8d398d48fddf023baccc24f073d"
10
+ }
sha256sums.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ 97c7c35a1e5ff1c1d0762556952cfeb5cc0ff3915cd0118b8c1c0359829b59de sharp_ndc_opset18.onnx
2
+ 23caa148af9590d4880c47fb69ba1dbd56dde91eab50e2c3d9254ddc1d001604 sharp_ndc_opset18.onnx.data
3
+ d5e13c449dd15f8538c26566bbbffa10172278b9d5f6e500a27c0c7c837f3d4f export_config.json
4
+ 5613ce0464dfbd2bc0902e2f874a836ea800dc6e2ec1a8e9213d98360e15bab7 run_manifest.json
5
+ 438d4881b4ece849eaea46065aeaa4243a260648a5619b330f31c30b730fbcf4 parity_metrics.json
sharp_ndc_opset18.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:97c7c35a1e5ff1c1d0762556952cfeb5cc0ff3915cd0118b8c1c0359829b59de
3
+ size 7279677
sharp_ndc_opset18.onnx.data ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:23caa148af9590d4880c47fb69ba1dbd56dde91eab50e2c3d9254ddc1d001604
3
+ size 2616066048