H1merka commited on
Commit
aac32b4
·
verified ·
1 Parent(s): 776c831

Upload TIGAS model checkpoint (2025-12-21 19:32:48)

Browse files
Files changed (4) hide show
  1. LICENSE +21 -0
  2. README.md +282 -0
  3. best_model.pt +3 -0
  4. config.json +72 -0
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Morgenshtern Dmitrij
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
README.md CHANGED
@@ -1,3 +1,285 @@
1
  ---
2
  license: mit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: mit
3
+ language:
4
+ - en
5
+ library_name: pytorch
6
+ tags:
7
+ - image-classification
8
+ - computer-vision
9
+ - ai-detection
10
+ - deepfake-detection
11
+ - pytorch
12
+ - image-quality
13
+ datasets:
14
+ - custom
15
+ metrics:
16
+ - accuracy
17
+ pipeline_tag: image-classification
18
+ model-index:
19
+ - name: TIGAS
20
+ results:
21
+ - task:
22
+ type: image-classification
23
+ name: AI-Generated Image Detection
24
+ metrics:
25
+ - type: accuracy
26
+ value: 0.656
27
+ name: Validation Accuracy
28
+ - type: loss
29
+ value: 0.308
30
+ name: Validation Loss
31
  ---
32
+
33
+ # TIGAS - Trained Image Generation Authenticity Score
34
+
35
+ <div align="center">
36
+
37
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
38
+ [![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
39
+ [![PyTorch](https://img.shields.io/badge/PyTorch-2.0+-red.svg)](https://pytorch.org/)
40
+
41
+ **Neural network metric for detecting AI-generated images**
42
+
43
+ [GitHub Repository](https://github.com/H1merka/TIGAS) • [Documentation](https://github.com/H1merka/TIGAS/blob/main/README_eng.md)
44
+
45
+ </div>
46
+
47
+ ## Model Description
48
+
49
+ TIGAS (Trained Image Generation Authenticity Score) is a multi-branch neural network designed to distinguish between real/natural images and AI-generated/fake images. It provides a continuous score in the range [0, 1]:
50
+
51
+ - **1.0** — Natural/Real image
52
+ - **0.0** — AI-Generated/Fake image
53
+
54
+ ### Architecture
55
+
56
+ The model uses a **Full Mode** architecture with three complementary analysis branches:
57
+
58
+ 1. **Perceptual Features** — Multi-scale CNN extracting visual patterns at 1/2, 1/4, 1/8, 1/16 resolutions
59
+ 2. **Spectral Analysis** — FFT-based frequency domain analysis for detecting GAN artifacts
60
+ 3. **Statistical Consistency** — Distribution analysis and moment estimation
61
+ 4. **Cross-Modal Attention** — Fuses features from all branches for final prediction
62
+
63
+ ### Model Specifications
64
+
65
+ | Property | Value |
66
+ |----------|-------|
67
+ | **Parameters** | ~18.9M |
68
+ | **Input Size** | 256×256 RGB |
69
+ | **Output** | Single score [0, 1] |
70
+ | **Architecture** | TIGASModel (Full Mode) |
71
+ | **File Size** | ~217 MB |
72
+
73
+ ## Training Details
74
+
75
+ ### Dataset
76
+
77
+ - **Training samples**: 128,776 images
78
+ - **Validation samples**: 14,167 images
79
+ - **Test samples**: 14,126 images
80
+ - **Total**: 157,069 images
81
+ - **Class balance**: ~46% real, ~54% fake
82
+
83
+ ### Training Configuration
84
+
85
+ | Parameter | Value |
86
+ |-----------|-------|
87
+ | Epochs | 3 |
88
+ | Batch Size | 8 |
89
+ | Image Size | 256×256 |
90
+ | Learning Rate | 1e-4 (with warmup) |
91
+ | Optimizer | AdamW |
92
+ | Scheduler | Cosine Annealing |
93
+ | Mixed Precision | Enabled (AMP) |
94
+ | Hardware | NVIDIA RTX 3050 Ti (4GB VRAM) |
95
+
96
+ ### Training Results
97
+
98
+ | Epoch | Train Loss | Val Loss | Val Accuracy |
99
+ |-------|------------|----------|--------------|
100
+ | 0 | 0.4115 | 0.3262 | 61.46% |
101
+ | 1 | 0.3707 | 0.3099 | 65.09% |
102
+ | 2 | 0.3506 | **0.3079** | **65.55%** |
103
+
104
+ **Note**: This is an early checkpoint after 3 epochs of training. The model is still learning and accuracy will improve with more training epochs (recommended: 30-50 epochs for production use).
105
+
106
+ ## Usage
107
+
108
+ ### Installation
109
+
110
+ ```bash
111
+ pip install torch torchvision
112
+ pip install huggingface-hub
113
+
114
+ # Clone the TIGAS repository
115
+ git clone https://github.com/H1merka/TIGAS.git
116
+ cd TIGAS
117
+ pip install -e .
118
+ ```
119
+
120
+ ### Quick Start
121
+
122
+ ```python
123
+ from tigas import TIGAS
124
+
125
+ # Initialize with auto-download from HuggingFace Hub
126
+ tigas = TIGAS(auto_download=True)
127
+
128
+ # Evaluate single image
129
+ score = tigas('path/to/image.jpg')
130
+ print(f"Authenticity Score: {score:.4f}")
131
+
132
+ # Interpretation
133
+ if score > 0.7:
134
+ print("Likely REAL (High Confidence)")
135
+ elif score > 0.5:
136
+ print("Probably REAL (Medium Confidence)")
137
+ elif score > 0.3:
138
+ print("Probably FAKE (Medium Confidence)")
139
+ else:
140
+ print("Likely FAKE (High Confidence)")
141
+ ```
142
+
143
+ ### Batch Processing
144
+
145
+ ```python
146
+ import torch
147
+ from tigas import TIGAS
148
+
149
+ tigas = TIGAS(auto_download=True, device='cuda')
150
+
151
+ # Process batch of images
152
+ images = torch.randn(8, 3, 256, 256) # [B, C, H, W]
153
+ scores = tigas(images)
154
+ print(f"Mean score: {scores.mean():.4f}")
155
+ ```
156
+
157
+ ### Directory Processing
158
+
159
+ ```python
160
+ from tigas import TIGAS
161
+
162
+ tigas = TIGAS(auto_download=True)
163
+
164
+ # Evaluate all images in directory
165
+ results = tigas.compute_directory(
166
+ 'path/to/images/',
167
+ return_paths=True,
168
+ batch_size=32
169
+ )
170
+
171
+ for img_path, score in results.items():
172
+ print(f"{img_path}: {score:.4f}")
173
+ ```
174
+
175
+ ### As a Differentiable Loss Function
176
+
177
+ ```python
178
+ from tigas import TIGAS
179
+
180
+ tigas = TIGAS(auto_download=True)
181
+
182
+ # In generator training loop
183
+ generated_images = generator(noise)
184
+ authenticity_score = tigas(generated_images)
185
+
186
+ # Maximize authenticity (make images look more real)
187
+ loss = 1.0 - authenticity_score.mean()
188
+ loss.backward()
189
+ ```
190
+
191
+ ### Command Line
192
+
193
+ ```bash
194
+ # Single image evaluation
195
+ python scripts/evaluate.py --image test.jpg --auto_download
196
+
197
+ # Directory evaluation
198
+ python scripts/evaluate.py --image_dir images/ --auto_download --batch_size 32
199
+
200
+ # Save results
201
+ python scripts/evaluate.py --image_dir images/ --output results.json --plot
202
+ ```
203
+
204
+ ## Loading the Model Manually
205
+
206
+ ```python
207
+ import torch
208
+ from huggingface_hub import hf_hub_download
209
+
210
+ # Download checkpoint
211
+ checkpoint_path = hf_hub_download(
212
+ repo_id="H1merka/TIGAS",
213
+ filename="best_model.pt"
214
+ )
215
+
216
+ # Load checkpoint
217
+ checkpoint = torch.load(checkpoint_path, map_location='cpu')
218
+
219
+ # Access model weights
220
+ model_state_dict = checkpoint['model_state_dict']
221
+ epoch = checkpoint['epoch']
222
+ best_val_loss = checkpoint['best_val_loss']
223
+
224
+ print(f"Loaded model from epoch {epoch}")
225
+ print(f"Best validation loss: {best_val_loss:.4f}")
226
+ ```
227
+
228
+ ## Checkpoint Contents
229
+
230
+ The checkpoint file (`best_model.pt`) contains:
231
+
232
+ | Key | Description |
233
+ |-----|-------------|
234
+ | `model_state_dict` | Model weights |
235
+ | `optimizer_state_dict` | Optimizer state (for resume training) |
236
+ | `scheduler_state_dict` | LR scheduler state |
237
+ | `scaler_state_dict` | AMP GradScaler state |
238
+ | `epoch` | Training epoch number |
239
+ | `global_step` | Global training step |
240
+ | `best_val_loss` | Best validation loss achieved |
241
+ | `train_history` | Training loss history |
242
+ | `val_history` | Validation metrics history |
243
+
244
+ ## Limitations
245
+
246
+ - **Early Training Stage**: This checkpoint is from early training (3 epochs). For production use, train for 30-50+ epochs.
247
+ - **Dataset Bias**: Performance may vary on images from generators not represented in the training set.
248
+ - **Resolution Dependency**: Best results at 256×256. Other resolutions are automatically resized.
249
+ - **Adversarial Robustness**: Not specifically hardened against adversarial attacks.
250
+
251
+ ## Intended Use
252
+
253
+ ### Primary Use Cases
254
+
255
+ - Detecting AI-generated images in content moderation
256
+ - Evaluating quality of generative models
257
+ - Research on image authenticity
258
+ - Integration as a loss function for training more realistic generators
259
+
260
+ ### Out-of-Scope Use
261
+
262
+ - Legal evidence without human verification
263
+ - Sole basis for content removal decisions
264
+ - Real-time processing of high-volume streams (without optimization)
265
+
266
+ ## Citation
267
+
268
+ ```bibtex
269
+ @software{tigas2025,
270
+ title = {TIGAS: Trained Image Generation Authenticity Score},
271
+ author = {Morgenshtern, Dmitrij},
272
+ year = {2025},
273
+ url = {https://github.com/H1merka/TIGAS},
274
+ license = {MIT}
275
+ }
276
+ ```
277
+
278
+ ## License
279
+
280
+ This model is released under the [MIT License](LICENSE).
281
+
282
+ ## Contact
283
+
284
+ - **GitHub**: [H1merka/TIGAS](https://github.com/H1merka/TIGAS)
285
+ - **Issues**: [GitHub Issues](https://github.com/H1merka/TIGAS/issues)
best_model.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c263c630853cbcc15a2158f72439d3dcd20fbae6b008898bf8dd51be4a5f1ed8
3
+ size 227239163
config.json ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_type": "tigas",
3
+ "architectures": ["TIGASModel"],
4
+ "task_type": "image-classification",
5
+ "framework": "pytorch",
6
+ "model_config": {
7
+ "img_size": 256,
8
+ "in_channels": 3,
9
+ "feature_dim": 256,
10
+ "base_channels": 32,
11
+ "num_scales": 4,
12
+ "fast_mode": false
13
+ },
14
+ "training_config": {
15
+ "epochs_trained": 3,
16
+ "batch_size": 8,
17
+ "learning_rate": 0.0001,
18
+ "optimizer": "adamw",
19
+ "scheduler": "cosine",
20
+ "mixed_precision": true,
21
+ "warmup_epochs": 5
22
+ },
23
+ "dataset_info": {
24
+ "train_samples": 128776,
25
+ "val_samples": 14167,
26
+ "test_samples": 14126,
27
+ "total_samples": 157069,
28
+ "real_ratio": 0.458,
29
+ "fake_ratio": 0.542
30
+ },
31
+ "metrics": {
32
+ "best_val_loss": 0.3079,
33
+ "best_val_accuracy": 0.6555,
34
+ "final_train_loss": 0.3506
35
+ },
36
+ "input_spec": {
37
+ "type": "image",
38
+ "channels": 3,
39
+ "height": 256,
40
+ "width": 256,
41
+ "normalization": {
42
+ "mean": [0.5, 0.5, 0.5],
43
+ "std": [0.5, 0.5, 0.5],
44
+ "range": [-1, 1]
45
+ }
46
+ },
47
+ "output_spec": {
48
+ "type": "score",
49
+ "range": [0, 1],
50
+ "interpretation": {
51
+ "1.0": "real/natural image",
52
+ "0.0": "fake/generated image"
53
+ }
54
+ },
55
+ "checkpoint_info": {
56
+ "format": "pytorch",
57
+ "keys": [
58
+ "model_state_dict",
59
+ "optimizer_state_dict",
60
+ "scheduler_state_dict",
61
+ "scaler_state_dict",
62
+ "epoch",
63
+ "global_step",
64
+ "best_val_loss",
65
+ "train_history",
66
+ "val_history"
67
+ ]
68
+ },
69
+ "version": "0.1.0",
70
+ "library_name": "tigas",
71
+ "github_repo": "https://github.com/H1merka/TIGAS"
72
+ }