Instructions to use msssingh/drift-sense-localization with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use msssingh/drift-sense-localization with MLX:
# Download the model from the Hub pip install huggingface_hub[hf_xet] huggingface-cli download --local-dir drift-sense-localization msssingh/drift-sense-localization
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Atomic Chat
Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
base_model: mlx-community/Qwen3.5-4B-MLX-4bit
|
| 4 |
+
tags:
|
| 5 |
+
- image-localization
|
| 6 |
+
- template-matching
|
| 7 |
+
- semiconductor
|
| 8 |
+
- sem
|
| 9 |
+
- siamese-network
|
| 10 |
+
- lora
|
| 11 |
+
- mlx
|
| 12 |
+
library_name: pytorch
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
# Drift-Sense Localization
|
| 16 |
+
|
| 17 |
+
Models that find a zoomed-in SEM reference pattern (100x, 1 nm/px) inside a
|
| 18 |
+
zoomed-out search image (10x, 10 nm/px) and return its pixel location.
|
| 19 |
+
Trained on 400 synthetic FinFET SEM pairs (IRDS 2024 geometry) with
|
| 20 |
+
realistic noise, blur, rotation (±2°), and stage drift (100–500 nm).
|
| 21 |
+
|
| 22 |
+
## Files
|
| 23 |
+
|
| 24 |
+
| file | what it is |
|
| 25 |
+
|---|---|
|
| 26 |
+
| `cnn/best.pt` | Siamese correlation CNN (PyTorch state_dict, ~6M params) |
|
| 27 |
+
| `lora/adapters.safetensors` | LoRA adapter (rank 8) for Qwen3.5-4B |
|
| 28 |
+
| `lora/adapter_config.json` | Adapter config for mlx-vlm |
|
| 29 |
+
|
| 30 |
+
## Results (held-out test split, 50 pairs)
|
| 31 |
+
|
| 32 |
+
| model | mean err (px) | ≤5 px | ≤10 px | s/pair |
|
| 33 |
+
|---|---|---|---|---|
|
| 34 |
+
| Siamese CNN | 2.51 | 96% | 100% | 0.04 |
|
| 35 |
+
| Qwen3.5-4B LoRA | 35.79 | 0% | 4% | 1.83 |
|
| 36 |
+
|
| 37 |
+
1 px = 10 nm. The CNN localizes to ~25 nm on average.
|
| 38 |
+
|
| 39 |
+
## Usage
|
| 40 |
+
|
| 41 |
+
CNN (needs the [training repo](https://github.com/bardrop/drift-sense) on PYTHONPATH):
|
| 42 |
+
|
| 43 |
+
```python
|
| 44 |
+
import torch
|
| 45 |
+
from drift_sense.model import SiameseLocator
|
| 46 |
+
from drift_sense.predict import predict
|
| 47 |
+
|
| 48 |
+
out = predict("ref.png", "search.png", ckpt="best.pt")
|
| 49 |
+
# {'x': 273.1, 'y': 262.4, 'confidence': 0.77, 'found': True,
|
| 50 |
+
# 'message': 'Pattern found at (273, 262) in the search image. Confidence: 77%.'}
|
| 51 |
+
```
|
| 52 |
+
|
| 53 |
+
VLM adapter (with [mlx-vlm](https://github.com/Blaizzy/mlx-vlm)):
|
| 54 |
+
|
| 55 |
+
```bash
|
| 56 |
+
python -m mlx_vlm.generate \
|
| 57 |
+
--model mlx-community/Qwen3.5-4B-MLX-4bit \
|
| 58 |
+
--adapter-path lora \
|
| 59 |
+
--image ref.png search.png \
|
| 60 |
+
--prompt "The first image is a zoomed-in reference pattern. The second image is a zoomed-out search image (1000x1000 pixels). Find the reference pattern in the search image. If several matches exist, pick the one closest to the centre. Answer exactly: Pattern found at (x, y). Confidence: high." \
|
| 61 |
+
--max-tokens 40
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
## Design notes
|
| 65 |
+
|
| 66 |
+
- The die is periodic (9 identical rail crossings), so pure correlation is
|
| 67 |
+
ambiguous. The CNN adds a learnable position-prior bias map and trains
|
| 68 |
+
with softmax cross-entropy over the full heatmap so peaks compete.
|
| 69 |
+
- Confidence = probability mass near the chosen peak; ambiguous matches
|
| 70 |
+
score low. Ties break toward the image centre.
|
| 71 |
+
- The VLM run is an honest negative result: it learns the output format
|
| 72 |
+
(0% parse failures) but not pixel-level precision.
|
| 73 |
+
|
| 74 |
+
## Limitations
|
| 75 |
+
|
| 76 |
+
- Trained on synthetic SEM images only; not validated on real SEM data.
|
| 77 |
+
- Assumes drift within ~±50 px of the nominal position (as generated).
|
| 78 |
+
- Rotation handled implicitly up to ±2°; no rotation estimate is output.
|