File size: 2,103 Bytes
c7d2a89
 
 
9727d96
 
 
 
 
c7d2a89
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1ae23f6
 
c7d2a89
 
9727d96
c7d2a89
 
 
 
 
 
 
 
 
 
9727d96
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
---
license: apache-2.0
tags:
- diffusion
- counting
- hallucination
- multi-target regression
- resnet
---

# CountHallu — ToyShape Counting Model

Counting model from **[Counting Hallucinations in Diffusion Models](https://arxiv.org/abs/2510.13080)**
(arXiv:2510.13080). It scores images generated by a diffusion model trained on
[ToyShape](https://huggingface.co/datasets/ShyFoo/CountHallu-dataset-ToyShape) to
decide whether each sample is counting-correct or a counting hallucination.

## Architecture & checkpoint

- **ResNet-50** (torchvision, ImageNet-1k V2 init) with the final layer replaced by
  a 3-output regression head — one predicted instance count per shape class
  `{triangle, square, pentagon}`.
- Ships a single `model.pth` (a plain `state_dict`).
- **Decision rule:** round the 3 predictions; a sample is a *hallucination* if any
  class ≥ 2 or all classes are 0 (valid ToyShape images have at most one instance
  per class and at least one shape).

## Usage

Inputs are RGB images normalised to `[-1, 1]` (`ToTensor` + `Normalize([0.5]*3,
[0.5]*3)`).

```python
import torch
from huggingface_hub import hf_hub_download
from counthallu.models.counting import CountingRegressor

ckpt = hf_hub_download("ShyFoo/CountHallu-counting_model-ToyShape", "model.pth")
model = CountingRegressor(num_classes=3)
model.load_state_dict(torch.load(ckpt, map_location="cpu"))
model.eval()
```

Or let the evaluation protocol fetch it for you:

```python
from counthallu.utils import load_counting_model
model, model_type, _, _ = load_counting_model(
    "toyshape", use_hub_model=True,
    repo_id="ShyFoo/CountHallu-counting_model-ToyShape"
)
```

See the [CountHallu repository](<https://github.com/ShyFoo/CountHallu-Diff>) for the full evaluation protocol.

## Citation

```bibtex
@article{fu2025counting,
  title={Counting Hallucinations in Diffusion Models},
  author={Fu, Shuai and Zhou, Jian and Chen, Qi and Jing, Huang and Nguyen, Huy Anh and Liu, Xiaohan and Zeng, Zhixiong and Ma, Lin and Zhang, Quanshi and Wu, Qi},
  journal={arXiv preprint arXiv:2510.13080},
  year={2025}
}
```