Upload 13 files
Browse files- README.md +91 -0
- checkpoint-600/config.json +32 -0
- checkpoint-600/model.safetensors +3 -0
- checkpoint-600/optimizer.pt +3 -0
- checkpoint-600/preprocessor_config.json +23 -0
- checkpoint-600/rng_state.pth +3 -0
- checkpoint-600/scheduler.pt +3 -0
- checkpoint-600/trainer_state.json +80 -0
- checkpoint-600/training_args.bin +3 -0
- config.json +32 -0
- model.safetensors +3 -0
- preprocessor_config.json +23 -0
- training_args.bin +3 -0
README.md
ADDED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
datasets:
|
4 |
+
- prithivMLmods/Deepfake-vs-Real
|
5 |
+
language:
|
6 |
+
- en
|
7 |
+
pipeline_tag: image-classification
|
8 |
+
library_name: transformers
|
9 |
+
tags:
|
10 |
+
- Deepfake
|
11 |
+
base_model:
|
12 |
+
- google/vit-base-patch32-224-in21k
|
13 |
+
---
|
14 |
+

|
15 |
+
|
16 |
+
# **Deepfake-Detection-Exp-02-22**
|
17 |
+
|
18 |
+
Deepfake-Detection-Exp-02-22 is a minimalist, high-quality dataset trained on a ViT-based model for image classification, distinguishing between deepfake and real images. The model is based on Google's **`google/vit-base-patch32-224-in21k`**.
|
19 |
+
|
20 |
+
```bitex
|
21 |
+
Mapping of IDs to Labels: {0: 'Deepfake', 1: 'Real'}
|
22 |
+
|
23 |
+
Mapping of Labels to IDs: {'Deepfake': 0, 'Real': 1}
|
24 |
+
```
|
25 |
+
|
26 |
+
```python
|
27 |
+
Classification report:
|
28 |
+
|
29 |
+
precision recall f1-score support
|
30 |
+
|
31 |
+
Deepfake 0.9833 0.9187 0.9499 1600
|
32 |
+
Real 0.9238 0.9844 0.9531 1600
|
33 |
+
|
34 |
+
accuracy 0.9516 3200
|
35 |
+
macro avg 0.9535 0.9516 0.9515 3200
|
36 |
+
weighted avg 0.9535 0.9516 0.9515 3200
|
37 |
+
```
|
38 |
+
|
39 |
+
|
40 |
+

|
41 |
+
|
42 |
+
# **Inference with Hugging Face Pipeline**
|
43 |
+
```python
|
44 |
+
from transformers import pipeline
|
45 |
+
|
46 |
+
# Load the model
|
47 |
+
pipe = pipeline('image-classification', model="prithivMLmods/Deepfake-Detection-Exp-02-22", device=0)
|
48 |
+
|
49 |
+
# Predict on an image
|
50 |
+
result = pipe("path_to_image.jpg")
|
51 |
+
print(result)
|
52 |
+
```
|
53 |
+
|
54 |
+
# **Inference with PyTorch**
|
55 |
+
```python
|
56 |
+
from transformers import ViTForImageClassification, ViTImageProcessor
|
57 |
+
from PIL import Image
|
58 |
+
import torch
|
59 |
+
|
60 |
+
# Load the model and processor
|
61 |
+
model = ViTForImageClassification.from_pretrained("prithivMLmods/Deepfake-Detection-Exp-02-22")
|
62 |
+
processor = ViTImageProcessor.from_pretrained("prithivMLmods/Deepfake-Detection-Exp-02-22")
|
63 |
+
|
64 |
+
# Load and preprocess the image
|
65 |
+
image = Image.open("path_to_image.jpg").convert("RGB")
|
66 |
+
inputs = processor(images=image, return_tensors="pt")
|
67 |
+
|
68 |
+
# Perform inference
|
69 |
+
with torch.no_grad():
|
70 |
+
outputs = model(**inputs)
|
71 |
+
logits = outputs.logits
|
72 |
+
predicted_class = torch.argmax(logits, dim=1).item()
|
73 |
+
|
74 |
+
# Map class index to label
|
75 |
+
label = model.config.id2label[predicted_class]
|
76 |
+
print(f"Predicted Label: {label}")
|
77 |
+
```
|
78 |
+
|
79 |
+
# **Limitations**
|
80 |
+
1. **Generalization Issues** – The model may not perform well on deepfake images generated by unseen or novel deepfake techniques.
|
81 |
+
2. **Dataset Bias** – The training data might not cover all variations of real and fake images, leading to biased predictions.
|
82 |
+
3. **Resolution Constraints** – Since the model is based on `vit-base-patch32-224-in21k`, it is optimized for 224x224 image resolution, which may limit its effectiveness on high-resolution images.
|
83 |
+
4. **Adversarial Vulnerabilities** – The model may be susceptible to adversarial attacks designed to fool vision transformers.
|
84 |
+
5. **False Positives & False Negatives** – The model may occasionally misclassify real images as deepfake and vice versa, requiring human validation in critical applications.
|
85 |
+
|
86 |
+
# **Intended Use**
|
87 |
+
1. **Deepfake Detection** – Designed for identifying deepfake images in media, social platforms, and forensic analysis.
|
88 |
+
2. **Research & Development** – Useful for researchers studying deepfake detection and improving ViT-based classification models.
|
89 |
+
3. **Content Moderation** – Can be integrated into platforms to detect and flag manipulated images.
|
90 |
+
4. **Security & Forensics** – Assists in cybersecurity applications where verifying the authenticity of images is crucial.
|
91 |
+
5. **Educational Purposes** – Can be used in training AI practitioners and students in the field of computer vision and deepfake detection.
|
checkpoint-600/config.json
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "google/vit-base-patch32-224-in21k",
|
3 |
+
"architectures": [
|
4 |
+
"ViTForImageClassification"
|
5 |
+
],
|
6 |
+
"attention_probs_dropout_prob": 0.0,
|
7 |
+
"encoder_stride": 16,
|
8 |
+
"hidden_act": "gelu",
|
9 |
+
"hidden_dropout_prob": 0.0,
|
10 |
+
"hidden_size": 768,
|
11 |
+
"id2label": {
|
12 |
+
"0": "Deepfake",
|
13 |
+
"1": "Real"
|
14 |
+
},
|
15 |
+
"image_size": 224,
|
16 |
+
"initializer_range": 0.02,
|
17 |
+
"intermediate_size": 3072,
|
18 |
+
"label2id": {
|
19 |
+
"Deepfake": 0,
|
20 |
+
"Real": 1
|
21 |
+
},
|
22 |
+
"layer_norm_eps": 1e-12,
|
23 |
+
"model_type": "vit",
|
24 |
+
"num_attention_heads": 12,
|
25 |
+
"num_channels": 3,
|
26 |
+
"num_hidden_layers": 12,
|
27 |
+
"patch_size": 32,
|
28 |
+
"problem_type": "single_label_classification",
|
29 |
+
"qkv_bias": true,
|
30 |
+
"torch_dtype": "float32",
|
31 |
+
"transformers_version": "4.47.1"
|
32 |
+
}
|
checkpoint-600/model.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:73a60bf9aec06941615d1a2b697736d7fb7ad07c150cf434dfbc09550328e16a
|
3 |
+
size 349850288
|
checkpoint-600/optimizer.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:52cc7200995d9b23db3901761e5ddbea13a0960a155caef18f7cf98315584581
|
3 |
+
size 699821498
|
checkpoint-600/preprocessor_config.json
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"do_convert_rgb": null,
|
3 |
+
"do_normalize": true,
|
4 |
+
"do_rescale": true,
|
5 |
+
"do_resize": true,
|
6 |
+
"image_mean": [
|
7 |
+
0.5,
|
8 |
+
0.5,
|
9 |
+
0.5
|
10 |
+
],
|
11 |
+
"image_processor_type": "ViTImageProcessor",
|
12 |
+
"image_std": [
|
13 |
+
0.5,
|
14 |
+
0.5,
|
15 |
+
0.5
|
16 |
+
],
|
17 |
+
"resample": 2,
|
18 |
+
"rescale_factor": 0.00392156862745098,
|
19 |
+
"size": {
|
20 |
+
"height": 224,
|
21 |
+
"width": 224
|
22 |
+
}
|
23 |
+
}
|
checkpoint-600/rng_state.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:58d3089cecf8afe9057a8e31154c498a9495581a3deafc501f8af896fb94a8dc
|
3 |
+
size 14244
|
checkpoint-600/scheduler.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:52486668edafef828135459be62f8fb60a1c8ac03ea0cc68c8e5fca33899a5e8
|
3 |
+
size 1064
|
checkpoint-600/trainer_state.json
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"best_metric": 0.5417714715003967,
|
3 |
+
"best_model_checkpoint": "DP32/checkpoint-600",
|
4 |
+
"epoch": 4.0,
|
5 |
+
"eval_steps": 500,
|
6 |
+
"global_step": 600,
|
7 |
+
"is_hyper_param_search": false,
|
8 |
+
"is_local_process_zero": true,
|
9 |
+
"is_world_process_zero": true,
|
10 |
+
"log_history": [
|
11 |
+
{
|
12 |
+
"epoch": 1.0,
|
13 |
+
"eval_accuracy": 0.841875,
|
14 |
+
"eval_loss": 0.6350374221801758,
|
15 |
+
"eval_model_preparation_time": 0.0045,
|
16 |
+
"eval_runtime": 64.618,
|
17 |
+
"eval_samples_per_second": 49.522,
|
18 |
+
"eval_steps_per_second": 6.19,
|
19 |
+
"step": 150
|
20 |
+
},
|
21 |
+
{
|
22 |
+
"epoch": 2.0,
|
23 |
+
"eval_accuracy": 0.925,
|
24 |
+
"eval_loss": 0.5866522192955017,
|
25 |
+
"eval_model_preparation_time": 0.0045,
|
26 |
+
"eval_runtime": 62.9502,
|
27 |
+
"eval_samples_per_second": 50.834,
|
28 |
+
"eval_steps_per_second": 6.354,
|
29 |
+
"step": 300
|
30 |
+
},
|
31 |
+
{
|
32 |
+
"epoch": 3.0,
|
33 |
+
"eval_accuracy": 0.94625,
|
34 |
+
"eval_loss": 0.5532988905906677,
|
35 |
+
"eval_model_preparation_time": 0.0045,
|
36 |
+
"eval_runtime": 63.0217,
|
37 |
+
"eval_samples_per_second": 50.776,
|
38 |
+
"eval_steps_per_second": 6.347,
|
39 |
+
"step": 450
|
40 |
+
},
|
41 |
+
{
|
42 |
+
"epoch": 3.3333333333333335,
|
43 |
+
"grad_norm": 2.095505475997925,
|
44 |
+
"learning_rate": 1.818181818181818e-07,
|
45 |
+
"loss": 0.5872,
|
46 |
+
"step": 500
|
47 |
+
},
|
48 |
+
{
|
49 |
+
"epoch": 4.0,
|
50 |
+
"eval_accuracy": 0.9515625,
|
51 |
+
"eval_loss": 0.5417714715003967,
|
52 |
+
"eval_model_preparation_time": 0.0045,
|
53 |
+
"eval_runtime": 62.7241,
|
54 |
+
"eval_samples_per_second": 51.017,
|
55 |
+
"eval_steps_per_second": 6.377,
|
56 |
+
"step": 600
|
57 |
+
}
|
58 |
+
],
|
59 |
+
"logging_steps": 500,
|
60 |
+
"max_steps": 600,
|
61 |
+
"num_input_tokens_seen": 0,
|
62 |
+
"num_train_epochs": 4,
|
63 |
+
"save_steps": 500,
|
64 |
+
"stateful_callbacks": {
|
65 |
+
"TrainerControl": {
|
66 |
+
"args": {
|
67 |
+
"should_epoch_stop": false,
|
68 |
+
"should_evaluate": false,
|
69 |
+
"should_log": false,
|
70 |
+
"should_save": true,
|
71 |
+
"should_training_stop": true
|
72 |
+
},
|
73 |
+
"attributes": {}
|
74 |
+
}
|
75 |
+
},
|
76 |
+
"total_flos": 1.516572596109312e+18,
|
77 |
+
"train_batch_size": 32,
|
78 |
+
"trial_name": null,
|
79 |
+
"trial_params": null
|
80 |
+
}
|
checkpoint-600/training_args.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a8b821a7a428ff1821b122e8796fde5b3b9a37a81fff0d4beb6b58653fc2d842
|
3 |
+
size 5240
|
config.json
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "google/vit-base-patch32-224-in21k",
|
3 |
+
"architectures": [
|
4 |
+
"ViTForImageClassification"
|
5 |
+
],
|
6 |
+
"attention_probs_dropout_prob": 0.0,
|
7 |
+
"encoder_stride": 16,
|
8 |
+
"hidden_act": "gelu",
|
9 |
+
"hidden_dropout_prob": 0.0,
|
10 |
+
"hidden_size": 768,
|
11 |
+
"id2label": {
|
12 |
+
"0": "Deepfake",
|
13 |
+
"1": "Real"
|
14 |
+
},
|
15 |
+
"image_size": 224,
|
16 |
+
"initializer_range": 0.02,
|
17 |
+
"intermediate_size": 3072,
|
18 |
+
"label2id": {
|
19 |
+
"Deepfake": 0,
|
20 |
+
"Real": 1
|
21 |
+
},
|
22 |
+
"layer_norm_eps": 1e-12,
|
23 |
+
"model_type": "vit",
|
24 |
+
"num_attention_heads": 12,
|
25 |
+
"num_channels": 3,
|
26 |
+
"num_hidden_layers": 12,
|
27 |
+
"patch_size": 32,
|
28 |
+
"problem_type": "single_label_classification",
|
29 |
+
"qkv_bias": true,
|
30 |
+
"torch_dtype": "float32",
|
31 |
+
"transformers_version": "4.47.1"
|
32 |
+
}
|
model.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:73a60bf9aec06941615d1a2b697736d7fb7ad07c150cf434dfbc09550328e16a
|
3 |
+
size 349850288
|
preprocessor_config.json
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"do_convert_rgb": null,
|
3 |
+
"do_normalize": true,
|
4 |
+
"do_rescale": true,
|
5 |
+
"do_resize": true,
|
6 |
+
"image_mean": [
|
7 |
+
0.5,
|
8 |
+
0.5,
|
9 |
+
0.5
|
10 |
+
],
|
11 |
+
"image_processor_type": "ViTImageProcessor",
|
12 |
+
"image_std": [
|
13 |
+
0.5,
|
14 |
+
0.5,
|
15 |
+
0.5
|
16 |
+
],
|
17 |
+
"resample": 2,
|
18 |
+
"rescale_factor": 0.00392156862745098,
|
19 |
+
"size": {
|
20 |
+
"height": 224,
|
21 |
+
"width": 224
|
22 |
+
}
|
23 |
+
}
|
training_args.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a8b821a7a428ff1821b122e8796fde5b3b9a37a81fff0d4beb6b58653fc2d842
|
3 |
+
size 5240
|