CoolFace
Modelpublic

Nhatminh1234/siglip-so400m-ppe-fp16

sourceHugging Faceapache-2.0updated 5mo agoView on Hugging Face
0likes
Model Card

SigLIP SO400M — PPE Detection ONNX INT8

Dynamic INT8 quantization of the SigLIP SO400M image encoder, optimized for CPU inference in the PPE Detection pipeline.

Only the image tower is exported. Text embeddings are pre-computed at startup from the original PyTorch weights and cached in memory.

Model details

PropertyValue
Base modelViT-SO400M-14-SigLIP (webli pretrained, open_clip)
Input size224 × 224
Embedding dim1152
QuantizationDynamic INT8 (MatMul/Gemm), opset 17
FP32 size1632 MB
INT8 size411 MB
Cosine similarity vs FP320.994 (random image)
Decision flip rate5.3% (19 real PPE crops)

Intended use

Zero-shot PPE classification in the PPE Detection system:

  • —Hardhat detection: head region crop → cosine similarity against positive/negative text prompts
  • —Safety vest detection: torso region crop → cosine similarity against positive/negative text prompts

Not intended as a standalone model — requires the text embeddings and logit_scale from the full pipeline.

Usage

python
import onnxruntime as ort
import numpy as np
from huggingface_hub import hf_hub_download

path = hf_hub_download("Nhatminh1234/siglip-so400m-ppe-int8", "siglip_image_encoder.onnx")
session = ort.InferenceSession(path, providers=["CPUExecutionProvider"])

# Input: preprocessed image batch (B, 3, 224, 224) float32, normalized per open_clip preprocess
pixel_values = np.random.randn(1, 3, 224, 224).astype(np.float32)
image_features = session.run(None, {"pixel_values": pixel_values})[0]  # (B, 1152)

# Normalize before cosine similarity
image_features /= np.linalg.norm(image_features, axis=-1, keepdims=True)

Performance notes

Dynamic INT8 quantizes only MatMul/Gemm layers (~80% of ViT compute). LayerNorm, softmax, and attention scores remain FP32. Expected cosine similarity vs FP32: 0.990–0.998 for large ViT models.

The logit_scale for this model is 111.54 (i.e., exp(4.714)).

Regenerating

bash
git clone https://github.com/nhatminh-115/PPE-Detection
cd PPE-Detection
python scripts/export_siglip_onnx.py --upload