Convert Apple NeuralHash model for CSAM Detection to ONNX.
AsuharietYgvar/AppleNeuralHash2ONNX is ranked 10,067 with 1,534 stars.
Same-category comparison
AsuharietYgvar/AppleNeuralHash2ONNX is ranked 10,067 among these 8 peers; BennyKok/comfyui-deploy is ranked 10,070.
Same-category comparison| Name | Rank | Metrics |
|---|
| pytorch/QNNPACK | 10,021 | - Language:
- C
- Stars:
- 1,552
- Forks:
- 223
- Description:
- Quantized Neural Network PACKage - mobile-optimized implementation of quantized neural network operators.
|
|---|
| Tencent/TurboTransformers | 10,023 | - Language:
- C++
- Stars:
- 1,551
- Forks:
- 208
- Description:
- a fast and user-friendly runtime for transformer inference (Bert, Albert, GPT2, Decoders, etc) on CPU and GPU.
|
|---|
| disler/claude-code-hooks-multi-agent-observability | 10,032 | - Language:
- Python
- Stars:
- 1,548
- Forks:
- 385
- Description:
- Real-time monitoring for Claude Code agents through simple hook event tracking.
|
|---|
| combust/mleap | 10,038 | - Language:
- Scala
- Stars:
- 1,546
- Forks:
- 313
- Description:
- MLeap: Deploy ML Pipelines to Production.
|
|---|
| BennyKok/comfyui-deploy | 10,070 | - Language:
- TypeScript
- Stars:
- 1,533
- Forks:
- 222
- Description:
- An open source `vercel` like deployment platform for Comfy UI.
|
|---|
| e2b-dev/desktop | 10,076 | - Language:
- Python
- Stars:
- 1,532
- Forks:
- 186
- Description:
- E2B Desktop Sandbox for LLMs. E2B Sandbox with desktop graphical environment that you can connect to any LLM for secure computer use.
|
|---|
| mxsm/rocketmq-rust | 10,084 | - Language:
- Rust
- Stars:
- 1,529
- Forks:
- 289
|
|---|
| o19s/elasticsearch-learning-to-rank | 10,106 | - Language:
- Java
- Stars:
- 1,520
- Forks:
- 373
- Description:
- Plugin to integrate Learning to Rank (aka machine learning for better relevance) with Elasticsearch.
|
|---|
Key parameters and specifications
Key parameters and specifications| Parameter | Value |
|---|
| Language | Python |
|---|
| Category | Infrastructure |
|---|
| Subcategory | Model optimization |
|---|
| Stars | 1,534 |
|---|
| Forks | 124 |
|---|
| Contributors | 1 |
|---|
| Created date | 2021-08-15 |
|---|
| Updated date | 2026-10-13 |
|---|
| Stars in 1 day | 0 |
|---|
| Stars in 7 days | 2 |
|---|
| Rank | 10,067 |
|---|
| Previous rank | 10,087 |
|---|
| Rank change | 20 |
|---|
| 7-day stars rank | 8,025 |
|---|
| Previous 7-day stars rank | 8,060 |
|---|
| 7-day stars rank change | 35 |
|---|
| Total stars rank | 7,949 |
|---|
| Previous total stars rank | 7,940 |
|---|
| Total stars rank change | -9 |
|---|
README summary
AppleNeuralHash2ONNX Convert Apple NeuralHash model for CSAM Detection to ONNX. Intro Apple NeuralHash is a perceptual hashing method for images based on neural networks. It can tolerate image resize and compression. The steps of hashing is as the following: 1. Perform inference on the NeuralHash model. Calculate dot product of a matrix with the resulting vector of 128 floats. Apply binary step to the resulting 96 float vector. 0 to bits, resulting in 96-bit binary data. In this project
, we convert Apple's NeuralHash model to ONNX format. A demo script for testing the model is also included. Prerequisite OS Both macOS and Linux will work. In the following sections Debian is used for Linux example. LZFSE decoder macOS: Install by running . Linux: Build and install from lzfse source. Install the following dependencies: Conversion Guide Step 1: Get NeuralHash model You will need 4 files from a recent macOS or iOS build: neuralhash_128x96_seed1. weights **Option 1: From macOS
or jailbroken iOS device (Recommended)** If you have a recent version of macOS (11. 7+) installed, simply grab these files from (on macOS) or (on iOS). Option 2: From iOS IPSW (click to reveal) 1. Locate system image: What you need is the largest file, for example . On macOS simply open the file in Finder. On Linux run the following commands: Required files are under in mounted path. Put them under the same directory: Step 2: Decode model structure and
shapes Normally compiled Core ML models store structure in and shapes in , both in JSON. It's the same for NeuralHash model but compressed with LZFSE. Step 3: Convert model to ONNX The resulting model is . Usage Inspect model Netron is a perfect tool for this purpose. Calculate neural hash with onnxruntime 1. Run on an image: Example output: **Note:** Neural hash generated here might be a few bits off from one generated on an iOS device. This is expected since
different iOS devices generate slightly different hashes anyway. The reason is that neural networks are based on floating-point calculations. The accuracy is highly dependent on the hardware. For smaller networks it won't make any difference. But NeuralHash has 200+ layers, resulting in significant cumulative errors. 5-inch| | |M1 Mac| | |iOS Simulator| | |ONNX Runtime| | Credits nhcalc for uncovering NeuralHash private API. TNN for compiled Core ML to ONNX script.
Frequently asked questions
How many stars and forks are recorded?
AsuharietYgvar/AppleNeuralHash2ONNX has 1,534 stars and 124 forks.
What is the repository rank?
AsuharietYgvar/AppleNeuralHash2ONNX is ranked 10,067.
What language and category are recorded?
AsuharietYgvar/AppleNeuralHash2ONNX has 1,534 stars, uses Python and belongs to Infrastructure.
Which repository is closest in rank?
AsuharietYgvar/AppleNeuralHash2ONNX is compared with BennyKok/comfyui-deploy, ranked 10,070 with 1,533 stars.
AppleNeuralHash2ONNX
Convert Apple NeuralHash model for CSAM Detection to ONNX.
Intro
Apple NeuralHash is a perceptual hashing method for images based on neural networks. It can tolerate image resize and compression. The steps of hashing is as the following:
- Convert image to RGB.
- Resize image to
360x360.
- Normalize RGB values to
[-1, 1] range.
- Perform inference on the NeuralHash model.
- Calculate dot product of a
96x128 matrix with the resulting vector of 128 floats.
- Apply binary step to the resulting 96 float vector.
- Convert the vector of 1.0 and 0.0 to bits, resulting in 96-bit binary data.
In this project, we convert Apple's NeuralHash model to ONNX format. A demo script for testing the model is also included.
Prerequisite
OS
Both macOS and Linux will work. In the following sections Debian is used for Linux example.
LZFSE decoder
- macOS: Install by running
brew install lzfse.
- Linux: Build and install from lzfse source.
Python
Python 3.6 and above should work. Install the following dependencies:
pip install onnx coremltools
Conversion Guide
Step 1: Get NeuralHash model
You will need 4 files from a recent macOS or iOS build:
Option 1: From macOS or jailbroken iOS device (Recommended)
If you have a recent version of macOS (11.4+) or jailbroken iOS (14.7+) installed, simply grab these files from /System/Library/Frameworks/Vision.framework/Resources/ (on macOS) or /System/Library/Frameworks/Vision.framework/ (on iOS).
Option 2: From iOS IPSW (click to reveal)
- Download any
.ipsw of a recent iOS build (14.7+) from ipsw.me.
- Unpack the file:
cd /path/to/ipsw/file
mkdir unpacked_ipsw
cd unpacked_ipsw
unzip ../*.ipsw
- Locate system image:
ls -lh
What you need is the largest .dmg file, for example 018-63036-003.dmg.
- Mount system image. On macOS simply open the file in Finder. On Linux run the following commands:
# Build and install apfs-fuse
sudo apt install fuse libfuse3-dev bzip2 libbz2-dev cmake g++ git libattr1-dev zlib1g-dev
git clone https://github.com/sgan81/apfs-fuse.git
cd apfs-fuse
git submodule init
git submodule update
mkdir build
cd build
cmake ..
make
sudo make install
sudo ln -s /bin/fusermount /bin/fusermount3
# Mount image
mkdir rootfs
apfs-fuse 018-63036-003.dmg rootfs
Required files are under /System/Library/Frameworks/Vision.framework/ in mounted path.
Put them under the same directory:
mkdir NeuralHash
cd NeuralHash
cp /System/Library/Frameworks/Vision.framework/Resources/NeuralHashv3b-current.espresso.* .
cp /System/Library/Frameworks/Vision.framework/Resources/neuralhash_128x96_seed1.dat .
Step 2: Decode model structure and shapes
Normally compiled Core ML models store structure in model.espresso.net and shapes in model.espresso.shape, both in JSON. It's the same for NeuralHash model but compressed with LZFSE.
dd if=NeuralHashv3b-current.espresso.net bs=4 skip=7 | lzfse -decode -o model.espresso.net
dd if=NeuralHashv3b-current.espresso.shape bs=4 skip=7 | lzfse -decode -o model.espresso.shape
cp NeuralHashv3b-current.espresso.weights model.espresso.weights
Step 3: Convert model to ONNX
cd ..
git clone https://github.com/AsuharietYgvar/TNN.git
cd TNN
python3 tools/onnx2tnn/onnx-coreml/coreml2onnx.py ../NeuralHash
The resulting model is NeuralHash/model.onnx.
Usage
Inspect model
Netron is a perfect tool for this purpose.
Calculate neural hash with onnxruntime
- Install required libraries:
pip install onnxruntime pillow
- Run
nnhash.py on an image:
python3 nnhash.py /path/to/model.onnx /path/to/neuralhash_128x96_seed1.dat image.jpg
Example output:
ab14febaa837b6c1484c35e6
Note: Neural hash generated here might be a few bits off from one generated on an iOS device. This is expected since different iOS devices generate slightly different hashes anyway. The reason is that neural networks are based on floating-point calculations. The accuracy is highly dependent on the hardware. For smaller networks it won't make any difference. But NeuralHash has 200+ layers, resulting in significant cumulative errors.
| Device |
Hash |
| iPad Pro 10.5-inch |
2b186faa6b36ffcc4c4635e1 |
| M1 Mac |
2b5c6faa6bb7bdcc4c4731a1 |
| iOS Simulator |
2b5c6faa6bb6bdcc4c4731a1 |
| ONNX Runtime |
2b5c6faa6bb6bdcc4c4735a1 |
Credits
- nhcalc for uncovering NeuralHash private API.
- TNN for compiled Core ML to ONNX script.