بنقرة واحدة
onnx-export
Convert JAX/Python ML models to ONNX format following the Hope:RE notebook pipeline for Google Colab
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Convert JAX/Python ML models to ONNX format following the Hope:RE notebook pipeline for Google Colab
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Primary skill for the Hope:RE AI art protection desktop application. Covers project overview, Zen design language, key conventions, and common workflows.
UI/UX design intelligence for web and mobile. Includes 50+ styles, 161 color palettes, 57 font pairings, 161 product types, 99 UX guidelines, and 25 chart types across 10 stacks (React, Next.js, Vue, Svelte, SwiftUI, React Native, Flutter, Tailwind, shadcn/ui, and HTML/CSS). Actions: plan, build, create, design, implement, review, fix, improve, optimize, enhance, refactor, and check UI/UX code. Projects: website, landing page, dashboard, admin panel, e-commerce, SaaS, portfolio, blog, and mobile app. Elements: button, modal, navbar, sidebar, card, table, form, and chart. Styles: glassmorphism, claymorphism, minimalism, brutalism, neumorphism, bento grid, dark mode, responsive, skeuomorphism, and flat design. Topics: color systems, accessibility, animation, layout, typography, font pairing, spacing, interaction states, shadow, and gradient. Integrations: shadcn/ui MCP for component search and examples.
Handle ONNX model distribution via Git LFS, GitHub Releases, and runtime downloading in Hope:RE
Load and run ONNX models in the Rust Tauri backend using the ort crate with platform-specific execution providers
Implement the SPSA-PGD adversarial perturbation pipeline for image protection in Rust
Create a new Svelte 5 component following Hope:RE conventions with runes, Tailwind CSS, and proper barrel exports
| name | onnx-export |
| description | Convert JAX/Python ML models to ONNX format following the Hope:RE notebook pipeline for Google Colab |
When creating or modifying the ML training-to-ONNX export pipeline in Hope:RE, follow these conventions:
0_setup_colab.ipynb -> GPU check, JAX+CUDA install
1_clip_to_jax.ipynb -> PyTorch CLIP weights -> numpy, pre-compute text embeddings
2_noise_algorithm.ipynb -> JAX PGD noise protection, export to .pkl
3_glaze_algorithm.ipynb -> JAX PGD style cloaking, export to .pkl
4_nightshade_algorithm.ipynb -> JAX PGD data poisoning, export to .pkl
5_export_onnx.ipynb -> Convert all .pkl -> ONNX, consolidate, simplify, validate
1_clip_to_jax.ipynb)Extract PyTorch CLIP ViT-B/32 weights to numpy and pre-compute text embeddings:
openai/clip-vit-base-patch32 from HuggingFaceclip_jax_weights.pklEach algorithm notebook builds a JAX model that:
(1, 224, 224, 3) in [0.0, 1.0] range{algorithm}_state.pklLoss functions:
cosine_similarity(image_features, chaos_embedding) - cosine_similarity(image_features, normal_embedding)cosine_similarity(image_features, style_embedding[style_index])cosine_similarity(image_features, target_embedding[target_index])5_export_onnx.ipynb)import jax
import jax.numpy as jnp
import jax2onnx
import onnx
from onnxsim import simplify
def export_algorithm(name, apply_fn, params, input_specs):
model = jax2onnx.to_onnx(
apply_fn,
params,
input_specs=input_specs,
model_name=name,
)
onnx.save(model, f"{name}_raw.onnx")
model = onnx.load(f"{name}_raw.onnx")
onnx.save(
model,
f"{name}_consolidated.onnx",
save_as_external_data=False,
)
model = onnx.load(f"{name}_consolidated.onnx")
model_simplified, check = simplify(model)
assert check, f"Simplification failed for {name}"
from onnxconverter_common import float16
# Keep as float32 -- do NOT convert to float16 for Rust ort compatibility
onnx.save(model_simplified, f"{name}.onnx")
noise_input_specs = [
("input", jnp.float32, (1, 224, 224, 3)),
]
glaze_input_specs = [
("input", jnp.float32, (1, 224, 224, 3)),
("style_index", jnp.int32, (1,)),
]
nightshade_input_specs = [
("input", jnp.float32, (1, 224, 224, 3)),
("target_index", jnp.int32, (1,)),
]
After export, validate ONNX output matches JAX within tolerance:
import onnxruntime as ort
import numpy as np
def validate_onnx(onnx_path, jax_fn, jax_params, test_input):
session = ort.InferenceSession(onnx_path)
onnx_result = session.run(None, {"input": test_input})[0]
jax_result = jax_fn(jax_params, test_input)
jax_result = np.array(jax_result)
max_diff = np.max(np.abs(onnx_result - jax_result))
assert max_diff < 1e-4, f"ONNX/JAX mismatch: max diff {max_diff}"
ort crate expects float32onnxsim simplification on each modelsave_as_external_data=False).onnx files in src-models/models/.gitattributes already configured)hope_config.json if input/output specs changedjax[cuda12]
jaxlib
jax2onnx
onnx
onnxsim
onnxruntime
transformers
torch
numpy
src-models/models/hope_config.json contains:
ort crate and SPSA optimization require float32[0.0, 1.0] pixels(1, 224, 224, 3), not NCHWpublish.yml and downloaded at runtime