Add model card and usage instructions
Browse files
README.md
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
- zh
|
| 5 |
+
library_name: pytorch
|
| 6 |
+
pipeline_tag: image-classification
|
| 7 |
+
tags:
|
| 8 |
+
- ltf
|
| 9 |
+
- ai-generated-image-detection
|
| 10 |
+
- clip
|
| 11 |
+
- multiple-instance-learning
|
| 12 |
+
metrics:
|
| 13 |
+
- accuracy
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
# LTF v3.3 — AI-generated image detection
|
| 17 |
+
|
| 18 |
+
This repository contains the **epoch 20 checkpoint** used in the historical
|
| 19 |
+
GenImage evaluation `20260326_012209_ViT-L-14_genimage_v3_v3_3`.
|
| 20 |
+
The model is also named HiDA v3.3 in the original experiment code.
|
| 21 |
+
|
| 22 |
+
LTF uses a frozen **CLIP ViT-L/14** backbone, two-level multiple-instance
|
| 23 |
+
learning (MIL), cross-shuffle during training, and pool-logit gated fusion.
|
| 24 |
+
The repository includes the custom PyTorch runtime and the frozen backbone.
|
| 25 |
+
It does not require conversion to a Transformers architecture.
|
| 26 |
+
|
| 27 |
+
## Historical results
|
| 28 |
+
|
| 29 |
+
Fixed threshold **0.5**, 8 GenImage subsets, **100,000 images**. Accuracy is the
|
| 30 |
+
unweighted mean across subsets, as recorded in the original rounded logs:
|
| 31 |
+
|
| 32 |
+
| Branch | Accuracy |
|
| 33 |
+
| --- | ---: |
|
| 34 |
+
| L1 | 95.26% |
|
| 35 |
+
| L2 | 97.39% |
|
| 36 |
+
| Fusion | **98.39%** |
|
| 37 |
+
|
| 38 |
+
Per-subset metrics are in `results/genimage8_logged_metrics.csv`.
|
| 39 |
+
These are historical logged results; uploading this repository did not rerun
|
| 40 |
+
the complete benchmark. SD1.4 official validation images were used during
|
| 41 |
+
training validation, so that subset overlaps model validation. These results
|
| 42 |
+
do not represent eight entirely held-out generators.
|
| 43 |
+
|
| 44 |
+
## Download and run
|
| 45 |
+
|
| 46 |
+
Use **Python 3.11**. Replace `MuskAI/LTF-v3.3` with this repository's ID.
|
| 47 |
+
|
| 48 |
+
```bash
|
| 49 |
+
python -m pip install -U huggingface_hub
|
| 50 |
+
hf download MuskAI/LTF-v3.3 --local-dir ./LTF-v3.3
|
| 51 |
+
cd LTF-v3.3
|
| 52 |
+
python -m pip install -r requirements.txt
|
| 53 |
+
python inference.py --input /path/to/image.jpg --device cpu
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
For GPU inference, use `--device cuda:0`. For larger images, lower the CLIP
|
| 57 |
+
forward chunk size without removing tiles:
|
| 58 |
+
|
| 59 |
+
```bash
|
| 60 |
+
python inference.py --input /path/to/image.jpg --device cuda:0 --chunk-size 8
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
## Python API
|
| 64 |
+
|
| 65 |
+
Run from the downloaded repository directory:
|
| 66 |
+
|
| 67 |
+
```python
|
| 68 |
+
from ltf_final import LTFDetector
|
| 69 |
+
|
| 70 |
+
detector = LTFDetector(device="auto", chunk_size=8)
|
| 71 |
+
result = detector.predict("image.jpg", branch="fusion", threshold=0.5)
|
| 72 |
+
print(result["prediction"], result["score_fake"])
|
| 73 |
+
print(result["probabilities"])
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
The image is decoded as RGB. All original edge-aligned 224×224 local tiles plus
|
| 77 |
+
a global view use the original CLIP preprocessing. Input files are not
|
| 78 |
+
recompressed. Test tiling depends on image size. Labels are **0=real, 1=fake**.
|
| 79 |
+
The API returns L1/L2/fusion scores, the selected label and the view count.
|
| 80 |
+
Loading the model does not download external weights after this repository
|
| 81 |
+
has been downloaded. It uses `backbones/ViT-L-14.pt`.
|
| 82 |
+
|
| 83 |
+
## Checkpoint identity and provenance
|
| 84 |
+
|
| 85 |
+
`weights/epoch_20.pth` is the original core state_dict (not `best.pth`):
|
| 86 |
+
|
| 87 |
+
```text
|
| 88 |
+
SHA256 32e9fa2e38e04d6d0221c844d650f0d45f7235bbf898b5ad665543d8be580031
|
| 89 |
+
```
|
| 90 |
+
|
| 91 |
+
Frozen CLIP backbone:
|
| 92 |
+
|
| 93 |
+
```text
|
| 94 |
+
SHA256 b8cca3fd41ae0c99ba7e8951adf17d267cdb84cd88be6f7c2e0eca1737a03836
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
`release_manifest.json` records checksums of every runtime file. The original
|
| 98 |
+
training and evaluation directories did not save training-day source snapshots.
|
| 99 |
+
The released core was recovered from git commit
|
| 100 |
+
`65c18ee5868ced87a27d048261e237632ad5d704`, with network naming adjusted to LTF.
|
| 101 |
+
This verifies checkpoint identity and runtime compatibility, not bit-for-bit
|
| 102 |
+
reproduction of the original training process. This Hub adaptation adds
|
| 103 |
+
tensor-only checkpoint loading and removes a machine-specific dataset path.
|
| 104 |
+
|
| 105 |
+
## Limitations
|
| 106 |
+
|
| 107 |
+
Scores are not calibrated authenticity probabilities. Predictions can change
|
| 108 |
+
with image content, generator, editing and compression. This model is a
|
| 109 |
+
research detector; an individual score does not prove image provenance.
|
| 110 |
+
|
| 111 |
+
The public demo uses configurable image-size limits for its available compute;
|
| 112 |
+
oversized uploads are rejected, not silently resized. CPU inference can be slow
|
| 113 |
+
for images containing many local tiles.
|
| 114 |
+
|
| 115 |
+
## License and citation
|
| 116 |
+
|
| 117 |
+
An author-selected license and final paper citation were not supplied in the
|
| 118 |
+
source bundle. This release does not invent a license or citation for LTF.
|
| 119 |
+
Contact the author about reuse permissions. The bundled CLIP components retain
|
| 120 |
+
their upstream terms: [OpenAI CLIP](https://github.com/openai/CLIP) and its
|
| 121 |
+
[MIT license](https://github.com/openai/CLIP/blob/main/LICENSE).
|