Ateeqq commited on
Commit
7707aa5
·
verified ·
1 Parent(s): 2b7d051

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +45 -55
README.md CHANGED
@@ -11,57 +11,60 @@ tags:
11
  - exnrt.com
12
  ---
13
 
14
- # Nsfw Image Detection
15
 
16
- This model is a fine-tuned for **nsfw image classification**. It has been trained to classify images into three safety-related categories, making it suitable for content moderation, filtering, or safety-aware applications.
17
 
18
  <p>
19
  <a href="https://exnrt.com/blog/ai/fine-tuning-siglip2/" target="_blank">
20
  <img src="https://img.shields.io/badge/View%20Training%20Code-blue?style=for-the-badge&logo=readthedocs"/>
21
  </a>
 
22
  </p>
23
 
 
 
24
  ## 🧠 Model Details
25
 
26
  * **Base model**: `google/siglip2-base-patch16-224`
27
- * **Task**: Image Classification (Safety Filtering)
28
- * **Framework**: PyTorch
29
- * **Fine-tuned on**: Custom dataset with 3 safety-related categories
30
- * **Selected checkpoint**: Epoch 3
31
  * **Batch size**: 64
32
- * **Epochs**: 7
33
 
34
- ### 🏷️ Categories
35
-
36
- The model classifies images into the following categories:
37
 
38
- | ID | Label |
39
- | -- | --------------------- |
40
- | 0 | `graphically_violent` |
41
- | 1 | `nudity_pornography` |
42
- | 2 | `safe_normal` |
43
 
44
- ### 🧾 Label Mapping
45
 
46
- ```python
47
- label2id = {'graphically_violent': 0, 'nudity_pornography': 1, 'safe_normal': 2}
48
- id2label = {0: 'graphically_violent', 1: 'nudity_pornography', 2: 'safe_normal'}
49
- ```
50
 
 
51
 
52
- ## 📈 Visual Results
53
 
54
- ### 📌 Epoch Training Results
55
 
56
- ![Epoch Results](https://huggingface.co/Ateeqq/nsfw-image-detection/resolve/main/nsfw-epochs-results.png)
57
 
58
- ### 📌 Final Metrics & Confusion Matrix
 
 
 
 
59
 
60
- ![Metrics](https://huggingface.co/Ateeqq/nsfw-image-detection/resolve/main/nsfw-training-results.png)
61
 
 
 
 
 
62
  ---
63
 
64
- ## 🚀 Usage
65
 
66
  ```python
67
  import torch
@@ -73,46 +76,33 @@ model_path = "Ateeqq/nsfw-image-detection"
73
  processor = AutoImageProcessor.from_pretrained(model_path)
74
  model = SiglipForImageClassification.from_pretrained(model_path)
75
 
76
- image_path = r"your_image_path.jpg"
77
- image = Image.open(image_path).convert("RGB")
78
  inputs = processor(images=image, return_tensors="pt")
79
 
80
  with torch.no_grad():
81
  logits = model(**inputs).logits
82
- probabilities = F.softmax(logits, dim=1)
83
 
84
  predicted_class_id = logits.argmax().item()
85
- predicted_class_label = model.config.id2label[predicted_class_id]
86
- confidence_scores = probabilities[0].tolist()
87
-
88
- print(f"Predicted class ID: {predicted_class_id}")
89
- print(f"Predicted class label: {predicted_class_label}\n")
90
- for i, score in enumerate(confidence_scores):
91
- label = model.config.id2label[i]
92
- print(f"Confidence for '{label}': {score:.6f}")
93
- ```
94
-
95
- ### Output
96
-
97
- ```
98
- Predicted class ID: 0
99
- Predicted class label: graphically_violent
100
 
101
- Confidence for 'graphically_violent': 0.999988
102
- Confidence for 'nudity_pornography': 0.000004
103
- Confidence for 'safe_normal': 0.000008
104
  ```
105
 
106
  ---
107
 
108
- ## 📊 Training Metrics (Epoch 3 Selected ✅)
109
 
110
  | Epoch | Training Loss | Validation Loss | Accuracy |
111
  | ----- | ------------- | --------------- | ---------- |
112
- | 1 | 0.1086 | 0.0817 | 97.05% |
113
- | 2 | 0.0415 | 0.1233 | 95.50% |
114
- | 3| 0.0302 | 0.0516 | **98.45%** |
115
- | 4 | 0.0271 | 0.0799 | 97.89% |
116
- | 5 | 0.0222 | 0.1015 | 98.03% |
117
- | 6 | 0.0026 | 0.0707 | 98.45% |
118
- | 7 | 0.0178 | 0.0665 | 98.59% |
 
 
 
11
  - exnrt.com
12
  ---
13
 
14
+ # NSFW Image Detection
15
 
16
+ This model is fine-tuned for **NSFW image classification**. It classifies content into three safety-critical categories, making it useful for moderation, safety filtering, and compliant content handling systems.
17
 
18
  <p>
19
  <a href="https://exnrt.com/blog/ai/fine-tuning-siglip2/" target="_blank">
20
  <img src="https://img.shields.io/badge/View%20Training%20Code-blue?style=for-the-badge&logo=readthedocs"/>
21
  </a>
22
+ <a href="https://exnrt.com/blog/ai/fine-tuning-siglip2/" target="_blank">https://exnrt.com/blog/ai/fine-tuning-siglip2/</a>
23
  </p>
24
 
25
+ ---
26
+
27
  ## 🧠 Model Details
28
 
29
  * **Base model**: `google/siglip2-base-patch16-224`
30
+ * **Task**: Image Classification (NSFW/Safe detection)
31
+ * **Framework**: PyTorch / Hugging Face Transformers
32
+ * **Fine-tuned on**: Custom dataset with 3 content categories
33
+ * **Selected checkpoint**: Epoch 5
34
  * **Batch size**: 64
35
+ * **Epochs trained**: 5
36
 
37
+ ---
 
 
38
 
39
+ ### 📌 Epoch Training Results
 
 
 
 
40
 
41
+ ![Epoch Results](https://huggingface.co/Ateeqq/nsfw-image-detection/resolve/main/all-epochs-results.png)
42
 
43
+ ### 📌 Confusion Matrix
 
 
 
44
 
45
+ ![Metrics](https://huggingface.co/Ateeqq/nsfw-image-detection/resolve/main/final-epoch-results.png)
46
 
47
+ ![Confusion Matrix](https://huggingface.co/Ateeqq/nsfw-image-detection/resolve/main/confusion_matrix.png)
48
 
49
+ ---
50
 
51
+ ### 🏷️ Categories
52
 
53
+ | ID | Label |
54
+ | -- | ------------------------ |
55
+ | 0 | `gore_bloodshed_violent` |
56
+ | 1 | `nudity_pornography` |
57
+ | 2 | `safe_normal` |
58
 
59
+ ### 🧾 Label Mapping
60
 
61
+ ```python
62
+ label2id = {'gore_bloodshed_violent': 0, 'nudity_pornography': 1, 'safe_normal': 2}
63
+ id2label = {0: 'gore_bloodshed_violent', 1: 'nudity_pornography', 2: 'safe_normal'}
64
+ ```
65
  ---
66
 
67
+ ## 🚀 Usage Example
68
 
69
  ```python
70
  import torch
 
76
  processor = AutoImageProcessor.from_pretrained(model_path)
77
  model = SiglipForImageClassification.from_pretrained(model_path)
78
 
79
+ image = Image.open("your_image_path.jpg").convert("RGB")
 
80
  inputs = processor(images=image, return_tensors="pt")
81
 
82
  with torch.no_grad():
83
  logits = model(**inputs).logits
84
+ probs = F.softmax(logits, dim=1)
85
 
86
  predicted_class_id = logits.argmax().item()
87
+ predicted_class = model.config.id2label[predicted_class_id]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
 
89
+ print(f"Predicted class: {predicted_class}")
90
+ for i, score in enumerate(probs[0]):
91
+ print(f"{model.config.id2label[i]}: {score:.4f}")
92
  ```
93
 
94
  ---
95
 
96
+ ## 📊 Training Metrics (Epoch 5 Selected ✅)
97
 
98
  | Epoch | Training Loss | Validation Loss | Accuracy |
99
  | ----- | ------------- | --------------- | ---------- |
100
+ | 1 | 0.0765 | 0.1166 | 95.70% |
101
+ | 2 | 0.0719 | 0.0477 | 98.34% |
102
+ | 3 | 0.0089 | 0.0634 | 98.05% |
103
+ | 4 | 0.0109 | 0.0437 | 98.61% |
104
+ | 5| 0.0001 | 0.0389 | **99.02%** |
105
+
106
+ - **Training runtime**: 1h 21m 40s
107
+ - **Final Training Loss**: 0.0727
108
+ - **Steps/sec**: 0.11 | **Samples/sec**: 6.99