File size: 2,079 Bytes
4257e6e
 
 
2e31130
 
 
 
 
4257e6e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4ffd450
 
4257e6e
 
92e710a
4257e6e
 
 
 
 
 
 
 
 
 
2e31130
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
---
license: apache-2.0
tags:
- diffusion
- counting
- hallucination
- multi-target regression
- resnet
---

# CountHallu — SimObject 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
[SimObject](https://huggingface.co/datasets/ShyFoo/CountHallu-dataset-SimObject) 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 object class.
- 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 SimObject images have at most one instance
  per class and at least one object).

## 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-SimObject", "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(
    "simobject", use_hub_model=True,
    repo_id="ShyFoo/CountHallu-counting_model-SimObject"
)
```

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}
}
```