Image Classification
Transformers
Safetensors
convnext
ai-generated-image-detection
image-forensics
mkk1135 commited on
Commit
37da0ae
·
verified ·
1 Parent(s): f62d9ff

Second round: training setting 5, decision threshold chosen on development data

Browse files
Files changed (3) hide show
  1. README.md +89 -83
  2. config.json +1 -2
  3. model.safetensors +1 -1
README.md CHANGED
@@ -1,83 +1,89 @@
1
- ---
2
- license: cc-by-nc-sa-4.0
3
- library_name: transformers
4
- pipeline_tag: image-classification
5
- base_model: facebook/convnext-tiny-224
6
- datasets:
7
- - OwensLab/CommunityForensics-Small
8
- - Dataseeds/DataSeeds.AI-Sample-Dataset-DSD
9
- tags:
10
- - ai-generated-image-detection
11
- - image-forensics
12
- metrics:
13
- - accuracy
14
- ---
15
-
16
- # AI-generated image detector (ConvNeXt-Tiny)
17
-
18
- A binary classifier that labels an image `real` (a photograph taken by a camera) or `ai` (AI-generated). It is a ConvNeXt-Tiny CNN fine-tuned from `facebook/convnext-tiny-224` for a Bachelor of Cybersecurity graduation project. Code, a small web interface, the lists of test images and all results: https://github.com/mkk1135/graduation-project
19
-
20
- Try it in your browser: https://huggingface.co/spaces/mkk1135/ai-image-detector (the image is analysed on your own device and is not uploaded).
21
-
22
- **Read the limitations before relying on it.** On the project's main test set of 384 images it was wrong about one time in five, and a published detector, [OwensLab/commfor-model-384](https://huggingface.co/OwensLab/commfor-model-384), was more accurate on unedited image files.
23
-
24
- ## Use
25
-
26
- ```python
27
- from transformers import pipeline
28
-
29
- detector = pipeline("image-classification", model="mkk1135/ai-image-detector")
30
- print(detector("photo.jpg"))
31
- ```
32
-
33
- The processor does not resize: the model looks at the whole image at its original resolution, because shrinking an image removes the fine traces that generators leave. Very large images need more memory and time. The score is not a calibrated probability; treat a score below 0.75 as "undetermined".
34
-
35
- ## Training data
36
-
37
- 36,562 images, of which a random 10% was held out for validation.
38
-
39
- | Class | Source | Images |
40
- |---|---|---|
41
- | Generated | [Community Forensics-Small](https://huggingface.co/datasets/OwensLab/CommunityForensics-Small): 377 community Stable Diffusion models (latent diffusion) | 14,592 |
42
- | Generated | Community Forensics-Small: GLIDE, DeepFloyd IF (pixel diffusion), BigGAN | 2,992 |
43
- | Real | Community Forensics-Small: COCO (4,831), VISION (1,153), Landscapes HQ (2,992), FFHQ (2,992) | 11,968 |
44
- | Real | [DataSeeds.AI Sample Dataset](https://huggingface.co/datasets/Dataseeds/DataSeeds.AI-Sample-Dataset-DSD): peer-ranked photographs of varied subjects | 7,010 |
45
-
46
- Images flagged NSFW by Community Forensics were removed.
47
-
48
- ## Training
49
-
50
- Three epochs, AdamW, learning rate 5e-5, batch size 32, on 256 x 256 crops taken at the images' original resolution. Augmentation: random downscaling by up to 2x, horizontal flip, Gaussian blur (radius 0.3 to 1.2 px, probability 0.3), Gaussian noise (standard deviation 1 to 5, probability 0.3), and JPEG re-compression applied zero, one or two times at quality 30 to 95. The generated training images are uncompressed PNG and most real ones are JPEG, so the augmentation is there to keep the model from using an image's processing history or sharpness as the answer.
51
-
52
- ## Results
53
-
54
- "Real" is the positive class. None of the generators in the evaluation sets is in the training data. The training settings were chosen on the check set; the model was published before it was scored on the main test set.
55
-
56
- | Set | Images | Accuracy | Real correct | AI correct |
57
- |---|---|---|---|---|
58
- | Held-out validation (same sources as training) | 3,657 | 97.0% | | |
59
- | Check set, used to choose the training settings | 157 | 89.2% | 59 / 69 | 81 / 88 |
60
- | Check set, every image re-compressed as JPEG quality 90 | 157 | 87.3% | 60 / 69 | 77 / 88 |
61
- | **Main test set** | 384 | **80.0%** (95% CI 75.7 to 83.6) | 139 / 192 | 168 / 192 |
62
- | Main test set, every image re-compressed as JPEG quality 90 | 384 | 81.8% | 150 / 192 | 164 / 192 |
63
- | Pilot test set | 48 | 87.5% | 21 / 26 | 21 / 22 |
64
-
65
- The main test set holds 192 photographs (Wikimedia Commons, Unsplash and Open Images, 64 each) and 192 images from the [Community Forensics evaluation set](https://huggingface.co/datasets/OwensLab/CommunityForensics-Eval): 132 from 11 commercial generators (Midjourney v5.2 and v6.1, DALL-E 2 and 3, Firefly Image 2 and 3, Imagen 3, Ideogram v1 and v2, FLUX dev and schnell) and 60 from 10 open-source generators. The check set and the pilot test set hold Wikimedia Commons photographs and images from the 11 commercial generators only, which are the kinds of image this model handles best; their scores overstate its accuracy.
66
-
67
- By source on the main test set: Wikimedia Commons 54 / 64, Unsplash 54 / 64, Open Images 31 / 64, commercial generators 122 / 132, open-source generators 46 / 60.
68
-
69
- Compared on the same 384 images: Claude Sonnet 5.5 (asked in a blind test) 97.4%, `OwensLab/commfor-model-384` 89.6%, this model 80.0%, four other public detectors 48.2% to 74.5%. After JPEG re-compression at quality 90, `OwensLab/commfor-model-384` scores 81.0% and this model 81.8%; the difference is not significant.
70
-
71
- ## Limitations
72
-
73
- - Treat its answer as a hint, not as proof that an image is real or generated. About one answer in five was wrong on the main test set.
74
- - Its main error is calling a real photograph generated. It recognised fewer than half of the small, strongly downscaled web photographs from Open Images (31 of 64).
75
- - It is sensitive to blur and resizing. On the check set a slight Gaussian blur (radius 0.6 px) cut the real photographs it recognised from 59 to 40 of 69, and downscaling to half size cut them to 41. Photographs that are small, blurred or strongly resized are likely to be labelled `ai`.
76
- - Among the generated images it most often missed those from Adobe Firefly (7 of 24), GALIP (4 of 6), DF-GAN (3 of 6) and LCM-LoRA SDXL (3 of 6).
77
- - Its score is not a calibrated probability. Of its decisions below 0.75, 61% were right; of those at 0.90 or more, 85% were right.
78
- - It was trained and tested on photographs and on unedited generator output. Screenshots, scans, drawings, heavily edited photographs, and generated images that were resized or filtered afterwards are untested.
79
- - Generators released after the training data was collected may not be detected.
80
-
81
- ## Licence
82
-
83
- CC BY-NC-SA 4.0, following the licence of the Community Forensics training data: non-commercial use only.
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc-by-nc-sa-4.0
3
+ library_name: transformers
4
+ pipeline_tag: image-classification
5
+ base_model: facebook/convnext-tiny-224
6
+ datasets:
7
+ - OwensLab/CommunityForensics-Small
8
+ - Dataseeds/DataSeeds.AI-Sample-Dataset-DSD
9
+ tags:
10
+ - ai-generated-image-detection
11
+ - image-forensics
12
+ metrics:
13
+ - accuracy
14
+ ---
15
+
16
+ # AI-generated image detector (ConvNeXt-Tiny)
17
+
18
+ A binary classifier that labels an image `real` (a photograph taken by a camera) or `ai` (AI-generated). It is a ConvNeXt-Tiny CNN fine-tuned from `facebook/convnext-tiny-224` for a Bachelor of Cybersecurity graduation project. Code, a small web interface, the lists of test images, every prediction and the evaluation protocol: https://github.com/mkk1135/graduation-project
19
+
20
+ Try it in your browser: https://huggingface.co/spaces/mkk1135/ai-image-detector (the image is analysed on your own device and is not uploaded).
21
+
22
+ **Read the limitations before relying on it.** On a held-out test set of 384 images it classified 81.5% correctly, and its answer is an indication, not proof.
23
+
24
+ ## Use
25
+
26
+ ```python
27
+ from transformers import pipeline
28
+
29
+ detector = pipeline("image-classification", model="mkk1135/ai-image-detector")
30
+ print(detector("photo.jpg"))
31
+ ```
32
+
33
+ The processor does not resize: the model looks at the whole image at its original resolution, because shrinking an image removes the fine traces that generators leave. Very large images need more memory and time; the project's interface analyses at most the central 2048 x 2048 pixels. The decision threshold that was chosen on development images is built into the model, so the label with the higher score is the model's answer. The score is not a calibrated probability; treat a score below 0.75 as "undetermined".
34
+
35
+ The project's repository also contains a combination of this model with the published detector [OwensLab/commfor-model-384](https://huggingface.co/OwensLab/commfor-model-384) (`fusion.py`), which was more accurate than either part on the held-out test set (95.3% against 81.5% and 92.2%).
36
+
37
+ ## Training data
38
+
39
+ 36,562 images, of which a random 10% was held out for validation.
40
+
41
+ | Class | Source | Images |
42
+ |---|---|---|
43
+ | Generated | [Community Forensics-Small](https://huggingface.co/datasets/OwensLab/CommunityForensics-Small): 377 community Stable Diffusion models (latent diffusion) | 14,592 |
44
+ | Generated | Community Forensics-Small: GLIDE, DeepFloyd IF (pixel diffusion), BigGAN | 2,992 |
45
+ | Real | Community Forensics-Small: COCO (4,831), VISION (1,153), Landscapes HQ (2,992), FFHQ (2,992) | 11,968 |
46
+ | Real | [DataSeeds.AI Sample Dataset](https://huggingface.co/datasets/Dataseeds/DataSeeds.AI-Sample-Dataset-DSD): peer-ranked photographs of varied subjects | 7,010 |
47
+
48
+ Images flagged NSFW by Community Forensics were removed.
49
+
50
+ ## Training
51
+
52
+ Three epochs, AdamW, learning rate 5e-5, batch size 32, seed 42, on 256 x 256 crops taken at the images' original resolution. Augmentation: random shrinking (seven times in ten, by any factor down to the crop size), horizontal flip, Gaussian blur (radius 0.3 to 1.2 px, probability 0.3), Gaussian noise (standard deviation 1 to 5, probability 0.3), and JPEG re-compression applied zero, one or two times at quality 30 to 95. The generated training images are uncompressed PNG and most real ones are JPEG, so the augmentation is there to keep the model from using an image's size, sharpness or compression history as the answer.
53
+
54
+ This is the fifth training setting of the project. The model published before it (setting 4) called small, lightly compressed photographs generated; the strong shrinking was added to remove that shortcut. After training, the decision threshold was set to 0.69 on the "AI" score, the value with the highest accuracy on 541 development images.
55
+
56
+ ## Results
57
+
58
+ "Real" is the positive class. None of the generators in the evaluation sets is in the training data. The training setting and the threshold were chosen on development images only; the three held-out sets were scored once, after all decisions had been committed to the public repository.
59
+
60
+ | Set | Images | Accuracy | Real correct | AI correct |
61
+ |---|---|---|---|---|
62
+ | Validation split (same sources as training; default threshold) | 3,657 | 95.3% | | |
63
+ | Check set (development) | 157 | 88.5% | 66 / 69 | 73 / 88 |
64
+ | Development test set | 384 | 82.6% | 167 / 192 | 150 / 192 |
65
+ | **Final test set (held out)** | 384 | **81.5%** (95% CI 77.3 to 85.1) | 171 / 192 | 142 / 192 |
66
+ | Final test set, every image re-compressed as JPEG quality 90 | 384 | 78.1% | 174 / 192 | 126 / 192 |
67
+ | ChatGPT and Gemini set (held out) | 168 | 68.5% | 61 / 72 | 54 / 96 |
68
+ | Reddit set (held out; labels may be wrong in some cases) | 120 | 68.3% | 56 / 60 | 26 / 60 |
69
+
70
+ The final test set holds 192 photographs (Wikimedia Commons, Unsplash and Open Images, 64 each) and 192 images from the [Community Forensics evaluation set](https://huggingface.co/datasets/OwensLab/CommunityForensics-Eval): 132 from 11 commercial generators (Midjourney v5.2 and v6.1, DALL-E 2 and 3, Firefly Image 2 and 3, Imagen 3, Ideogram v1 and v2, FLUX dev and schnell) and 60 from 10 open-source generators. By source: Wikimedia Commons 56 / 64, Unsplash 62 / 64, Open Images 53 / 64, commercial generators 105 / 132, open-source generators 37 / 60.
71
+
72
+ Compared on the same 384 held-out images: Claude Sonnet 5.5 (asked in a blind test) 96.6%, the combination of this model with `OwensLab/commfor-model-384` 95.3%, `OwensLab/commfor-model-384` alone 92.2%, this model 81.5%, the model published before it (setting 4) 82.3%, and the four other public detectors between 50.0% and 75.8%.
73
+
74
+
75
+ ## Limitations
76
+
77
+ - Treat its answer as a hint, not as proof that an image is real or generated. On the held-out final test set 71 of 384 answers were wrong.
78
+ - Its main error is missing generated images: on the final test set it called 50 of the 192 generated images real, and 21 of the 192 photographs generated.
79
+ - It is weak on images from the generators of current chat assistants. On the held-out ChatGPT and Gemini set it recognised 12 of 24 images from GPT Image 2, 10 of 24 from GPT Image 1.5, 23 of 24 from Nano Banana and 9 of 24 from Nano Banana Pro.
80
+ - JPEG re-compression lowers its accuracy on the final test set from 81.5% to 78.1%: of the 192 generated images it then recognises 126.
81
+ - It still reacts to processing. On the check set a slight Gaussian blur (radius 0.6 px) changed the photographs it recognised from 66 to 58 of 69, and the generated images it recognised from 73 to 73 of 88.
82
+ - Its score is not a calibrated probability. On the final test set, answers with a score of 0.75 or more were right in 86.4% of 324 cases, answers with a lower score in 55.0% of 60.
83
+ - **This model is not better than the one published here before it (training setting 4, default threshold), and on some images it is worse.** On the final test set the two cannot be told apart (81.5% against 82.3%). On the ChatGPT and Gemini set the earlier model scored 73.2% against 68.5%, and on the Reddit set 79.2% against 68.3%: the stronger shrinking and the tuned threshold make this model slower to call an image generated. This model was published because the rule for choosing it had been fixed before the held-out sets were scored. For images from recent generators or from social media, prefer the earlier model, which is kept in this repository under the tag `round-1`: `pipeline("image-classification", model="mkk1135/ai-image-detector", revision="round-1")`.
84
+ - It was trained and tested on photographs and on unedited generator output. Screenshots, scans, drawings, heavily edited photographs, and partly synthetic images are untested.
85
+ - Generators released after the training data was collected may not be detected.
86
+
87
+ ## Licence
88
+
89
+ CC BY-NC-SA 4.0, following the licence of the Community Forensics training data: non-commercial use only.
config.json CHANGED
@@ -47,6 +47,5 @@
47
  "stage3",
48
  "stage4"
49
  ],
50
- "transformers_version": "5.23.0",
51
- "use_cache": false
52
  }
 
47
  "stage3",
48
  "stage4"
49
  ],
50
+ "transformers_version": "5.23.0"
 
51
  }
model.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:28f95e25b502a1fa9f1b671fea22758d93ee3bc23557bca82478db61b117a6be
3
  size 111307920
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d5beb54ae2f74b3df9f0e1bef9d73817318808b1c94b54c22718403bbb5f2adb
3
  size 111307920