Downloads · 30 days
0
mahfuj735/chemical-ocsr
chemical-ocsr is a image-to-text model from mahfuj735. Use it when you need a caption or text from an image. The card lists the license as mit.
Official model repository for Chemical AI Studio (cicapp) — a two-stage hierarchical deep learning pipeline for real-time on-device chemical diagram classification and structure translation into SMILES representations.
Downloads · 30 days
0
Access
Public
Updated Sep 4, 2026
Repo size
68.5 MB
Likes
0
Public
Click a slice to open those files.
.onnx68.5 MB · 100%
From the Hugging Face model README
Official model repository for Chemical AI Studio (cicapp) — a two-stage hierarchical deep learning pipeline for real-time on-device chemical diagram classification and structure translation into SMILES representations.
[ Input Chemical Image ]
│
▼
[ Stage 1: ConvNeXt-V2-Nano Classifier (60 MB) ]
├── one_molecule (99.31% F1) ──► Route to Stage 2 OCSR
├── reactions ──► Reaction Scheme Panel
├── several_molecules ──► Multi-Molecule Parsing
└── rest ──► Alert & Filter
│
▼ (if one_molecule)
[ Stage 2: Mobile OCSR with 2D Cross-Attention (8.47 MB) ]
├── MobileNetV3-Large Encoder (7x7 spatial feature grid)
├── Bahdanau 2D Cross-Attention Mechanism
└── 2-Layer Autoregressive GRU Decoder
│
▼
[ Output Canonical SMILES ]
convnextv2_nano.onnx)99.31%99.31%30.8 msmobile_ocsr_full.onnx)99.90%97.40%99.71%8.47 MB (Mobile ONNX)~14 - 35 ms (Edge NPU/CPU)mobile_ocsr_full.onnx: End-to-end monolithic Mobile OCSR graph (Image tensor $\to$ SMILES token IDs).convnextv2_nano.onnx: 4-class chemical diagram router.molscribe_vocab.json: 61-token SMILES vocabulary with bidirectional stoi and itos mappings.export_summary.json: Complete precision and benchmarking logs.import json
import numpy as np
from PIL import Image
import onnxruntime as ort
from huggingface_hub import hf_hub_download
# Download artifacts
model_path = hf_hub_download("mahfuj735/chemical-ocsr", "mobile_ocsr_full.onnx")
vocab_path = hf_hub_download("mahfuj735/chemical-ocsr", "molscribe_vocab.json")
session = ort.InferenceSession(model_path)
with open(vocab_path, "r") as f:
vocab = json.load(f)
itos = {int(k): v for k, v in vocab["itos"].items()}
eos_idx = vocab["eos_idx"]
# Prepare image
img = Image.open("molecule.png").convert("RGB").resize((224, 224), Image.BILINEAR)
mean = np.array([0.485, 0.456, 0.406], dtype=np.float32)
std = np.array([0.229, 0.224, 0.225], dtype=np.float32)
arr = np.expand_dims(np.transpose((np.array(img, dtype=np.float32) / 255.0 - mean) / std, (2, 0, 1)), 0)
# Run Inference
pred_tokens = session.run(None, {"image": arr})[0][0]
smiles = "".join([itos.get(int(t), "") for t in pred_tokens if int(t) not in (vocab["pad_idx"], vocab["bos_idx"]) and int(t) != eos_idx])
print("Predicted SMILES:", smiles)
Models are designed for zero-cloud dependency, strictly bounded RSS memory (<450 MB), and real-time C++ inference on mobile hardware via flutter_onnxruntime.