nhellyercreek commited on
Commit
0b8f939
·
verified ·
1 Parent(s): 3b6cafb

Upload model card

Browse files
Files changed (1) hide show
  1. README.md +90 -0
README.md ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ tags:
4
+ - image-to-text
5
+ - ocr
6
+ - cipher
7
+ - moon-cipher
8
+ - pytorch
9
+ - crnn
10
+ - cnn
11
+ ---
12
+
13
+ # Moon Cipher Detector
14
+
15
+ Deep learning models for detecting and decoding **moon cipher** glyphs from images (A–Z plus `~`).
16
+
17
+ ## Model variants
18
+
19
+ | File | Description |
20
+ |------|-------------|
21
+ | `best_end_to_end.pth` | End-to-end CRNN: full image → decoded text (recommended for full-page decoding). |
22
+ | `best_classifier.pth` | CNN classifier for single glyphs (used with a separate detector in two-stage decoding). |
23
+
24
+ Use **end-to-end** for full image decoding; use **classifier** if you already have cropped glyphs or use the two-stage pipeline (detect then classify).
25
+
26
+ ## Model metadata
27
+
28
+ | Model | Format | Size | Params | Tensor type |
29
+ |-------|--------|------|--------|--------------|
30
+ | End-to-end (`best_end_to_end.pth`) | PyTorch .pth (state_dict) | 30.0 MB | 7,856,348 params | F32 |
31
+ | Classifier (`best_classifier.pth`) | PyTorch .pth (state_dict) | 51.98 MB | 13,616,347 params | F32 |
32
+
33
+ Weights are saved as **PyTorch state dict** (`.pth`), not Safetensors. Load with `torch.load(..., weights_only=True)`.
34
+
35
+ ## Usage
36
+
37
+ ### 1. Install
38
+
39
+ ```bash
40
+ pip install torch torchvision huggingface_hub
41
+ ```
42
+
43
+ ### 2. Download from Hugging Face
44
+
45
+ ```python
46
+ from huggingface_hub import hf_hub_download
47
+
48
+ # End-to-end model (full image → text)
49
+ model_path = hf_hub_download(
50
+ repo_id="nhellyercreek/moon-cipher-detector",
51
+ filename="best_end_to_end.pth"
52
+ )
53
+ mappings_path = hf_hub_download(
54
+ repo_id="nhellyercreek/moon-cipher-detector",
55
+ filename="mappings.json"
56
+ )
57
+ ```
58
+
59
+ ### 3. Load and decode (end-to-end)
60
+
61
+ Use the same architecture as in this repo’s `models/end_to_end_decoder.py`:
62
+
63
+ ```python
64
+ import torch
65
+ import json
66
+ from pathlib import Path
67
+
68
+ # Add the Moon-Cipher-Detector repo to path, then:
69
+ # from models.end_to_end_decoder import EndToEndMoonCipherDecoder
70
+
71
+ # decoder = EndToEndMoonCipherDecoder(
72
+ # model_path=model_path,
73
+ # model_type="crnn",
74
+ # mappings_path=mappings_path,
75
+ # device="cuda" if torch.cuda.is_available() else "cpu"
76
+ # )
77
+ # result = decoder.decode_with_confidence(your_grayscale_image)
78
+ # print(result["text"])
79
+ ```
80
+
81
+ For the **classifier**, use `models/moon_classifier.MoonClassifier` and load `best_classifier.pth`; see the project’s `models/sequence_decoder.py` and `backend/main.py` for the full pipeline.
82
+
83
+ ## Config
84
+
85
+ - **Classes**: 27 (A–Z + `~`)
86
+ - **End-to-end**: Deep CRNN (CNN + bidirectional LSTM, CTC).
87
+ - **Classifier**: Custom CNN, 128×128 input, 27 classes.
88
+ - **Weight format**: PyTorch `.pth` (state_dict), **tensor type**: F32.
89
+
90
+ See `config.json` in this repo for machine-readable settings (params, size, format).