kaykyramos commited on
Commit
9104dbe
·
1 Parent(s): 57cf9f8

Initial commit

Browse files
Files changed (5) hide show
  1. README.md +4 -3
  2. config.json +63 -0
  3. detector.py +32 -0
  4. model.safetensors +3 -0
  5. preprocessor_config.json +22 -0
README.md CHANGED
@@ -1,3 +1,4 @@
1
- ---
2
- license: mit
3
- ---
 
 
1
+ # Usage:
2
+ ```bash
3
+ python detector.py --image "path_to_image.png|.jpg|.jpeg"
4
+ ```
config.json ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "../models/checkpoint-4266",
3
+ "_num_labels": 2,
4
+ "architectures": [
5
+ "SwinForImageClassification"
6
+ ],
7
+ "attention_probs_dropout_prob": 0.0,
8
+ "depths": [
9
+ 2,
10
+ 2,
11
+ 18,
12
+ 2
13
+ ],
14
+ "drop_path_rate": 0.1,
15
+ "embed_dim": 128,
16
+ "encoder_stride": 32,
17
+ "hidden_act": "gelu",
18
+ "hidden_dropout_prob": 0.0,
19
+ "hidden_size": 1024,
20
+ "id2label": {
21
+ "0": "artificial",
22
+ "1": "human"
23
+ },
24
+ "image_size": 224,
25
+ "initializer_range": 0.02,
26
+ "label2id": {
27
+ "artificial": 0,
28
+ "human": 1
29
+ },
30
+ "layer_norm_eps": 1e-05,
31
+ "mlp_ratio": 4.0,
32
+ "model_type": "swin",
33
+ "num_channels": 3,
34
+ "num_heads": [
35
+ 4,
36
+ 8,
37
+ 16,
38
+ 32
39
+ ],
40
+ "num_layers": 4,
41
+ "out_features": [
42
+ "stage4"
43
+ ],
44
+ "out_indices": [
45
+ 4
46
+ ],
47
+ "padding": "max_length",
48
+ "patch_size": 4,
49
+ "path_norm": true,
50
+ "problem_type": "single_label_classification",
51
+ "qkv_bias": true,
52
+ "stage_names": [
53
+ "stem",
54
+ "stage1",
55
+ "stage2",
56
+ "stage3",
57
+ "stage4"
58
+ ],
59
+ "torch_dtype": "float32",
60
+ "transformers_version": "4.46.2",
61
+ "use_absolute_embeddings": false,
62
+ "window_size": 7
63
+ }
detector.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import argparse
2
+ import os
3
+ import warnings
4
+ from transformers import SwinForImageClassification, AutoImageProcessor
5
+ from PIL import Image
6
+ import torch
7
+
8
+ warnings.filterwarnings("ignore")
9
+ os.environ["TRANSFORMERS_VERBOSITY"] = "error"
10
+
11
+ def classify_image(image_path):
12
+ model = SwinForImageClassification.from_pretrained("./")
13
+ processor = AutoImageProcessor.from_pretrained("./", use_fast=False)
14
+
15
+ image = Image.open(image_path).convert("RGB")
16
+ inputs = processor(images=image, return_tensors="pt")
17
+
18
+ with torch.no_grad():
19
+ outputs = model(**inputs)
20
+ logits = outputs.logits
21
+ predicted_class = torch.argmax(logits, dim=1).item()
22
+
23
+ label = model.config.id2label[predicted_class]
24
+ return "Real" if label == "human" else "Fake"
25
+
26
+ if __name__ == "__main__":
27
+ parser = argparse.ArgumentParser(description="Detecta se uma imagem é real ou gerada por IA.")
28
+ parser.add_argument("--image", type=str, required=True, help="Caminho para a imagem a ser analisada.")
29
+
30
+ args = parser.parse_args()
31
+ result = classify_image(args.image)
32
+ print(result)
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7076a3794f258075c499156c3f44d0d2528426694e74993549270d5d362b413b
3
+ size 347498816
preprocessor_config.json ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "do_normalize": true,
3
+ "do_rescale": true,
4
+ "do_resize": true,
5
+ "image_mean": [
6
+ 0.485,
7
+ 0.456,
8
+ 0.406
9
+ ],
10
+ "image_processor_type": "ViTImageProcessor",
11
+ "image_std": [
12
+ 0.229,
13
+ 0.224,
14
+ 0.225
15
+ ],
16
+ "resample": 3,
17
+ "rescale_factor": 0.00392156862745098,
18
+ "size": {
19
+ "height": 224,
20
+ "width": 224
21
+ }
22
+ }