Update README.md
Browse files
README.md
CHANGED
|
@@ -3,4 +3,119 @@ license: mit
|
|
| 3 |
base_model:
|
| 4 |
- google/efficientnet-b1
|
| 5 |
pipeline_tag: image-classification
|
| 6 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
base_model:
|
| 4 |
- google/efficientnet-b1
|
| 5 |
pipeline_tag: image-classification
|
| 6 |
+
---
|
| 7 |
+
|
| 8 |
+
# 🖼️ RateBooru Efficient - Danbooru Rating Classifier
|
| 9 |
+
|
| 10 |
+
This is a simple image classification model fine-tuned from **EfficientNetB1** to classify Danbooru-style image ratings into 3 categories:
|
| 11 |
+
|
| 12 |
+
- `general`
|
| 13 |
+
- `questionable`
|
| 14 |
+
- `explicit`
|
| 15 |
+
|
| 16 |
+
## 🎯 Purpose
|
| 17 |
+
|
| 18 |
+
This model was created as a **learning project** and also intended for **basic NSFW moderation tasks** based on Danbooru rating style.
|
| 19 |
+
|
| 20 |
+
## 📊 Dataset
|
| 21 |
+
|
| 22 |
+
- Total images: **6,000**
|
| 23 |
+
- Training: 4,800
|
| 24 |
+
- Validation: 1,200
|
| 25 |
+
- All images are tagged with **rating metadata** from Danbooru.
|
| 26 |
+
- The dataset is private / custom-collected, not provided here.
|
| 27 |
+
|
| 28 |
+
## 🧠 Model Details
|
| 29 |
+
|
| 30 |
+
- Base model: `EfficientNetB1` from TensorFlow/Keras
|
| 31 |
+
- Fine-tuned for 50 epochs
|
| 32 |
+
- Input size: 240x240 RGB
|
| 33 |
+
- Output: Softmax classification (3 classes)
|
| 34 |
+
|
| 35 |
+
## 📈 Final Training Metrics
|
| 36 |
+
|
| 37 |
+
| Metric | Training | Validation |
|
| 38 |
+
|---------------|----------|------------|
|
| 39 |
+
| Accuracy | 75.24% | 70.42% |
|
| 40 |
+
| Loss | 0.5916 | 0.6452 |
|
| 41 |
+
| Precision | 79.07% | 72.93% |
|
| 42 |
+
| Recall | 69.09% | 67.58% |
|
| 43 |
+
| Learning Rate | 2e-6 | - |
|
| 44 |
+
|
| 45 |
+
## 🚀 Usage (TensorFlow)
|
| 46 |
+
|
| 47 |
+
```python
|
| 48 |
+
import tensorflow as tf
|
| 49 |
+
import numpy as np
|
| 50 |
+
from PIL import Image
|
| 51 |
+
import os
|
| 52 |
+
|
| 53 |
+
# === Configuration ===
|
| 54 |
+
MODEL_PATH = 'ratebooru_efficientnetb1.keras'
|
| 55 |
+
IMAGE_PATH = 'example.jpg' # Change this to your image file path
|
| 56 |
+
IMG_SIZE = (240, 240)
|
| 57 |
+
CLASS_NAMES = ['explicit', 'general', 'questionable']
|
| 58 |
+
|
| 59 |
+
# === Load & Preprocess Image ===
|
| 60 |
+
def preprocess_image(image_path):
|
| 61 |
+
try:
|
| 62 |
+
img = Image.open(image_path).convert('RGB')
|
| 63 |
+
img = img.resize(IMG_SIZE)
|
| 64 |
+
img_array = tf.keras.utils.img_to_array(img)
|
| 65 |
+
return tf.expand_dims(img_array, 0)
|
| 66 |
+
except Exception as e:
|
| 67 |
+
print(f"Error loading image: {e}")
|
| 68 |
+
return None
|
| 69 |
+
|
| 70 |
+
# === Predict ===
|
| 71 |
+
def predict(model, image_tensor):
|
| 72 |
+
predictions = model.predict(image_tensor)
|
| 73 |
+
score = tf.nn.softmax(predictions[0])
|
| 74 |
+
return {CLASS_NAMES[i]: float(score[i]) for i in range(len(CLASS_NAMES))}
|
| 75 |
+
|
| 76 |
+
# === Main ===
|
| 77 |
+
if not os.path.exists(MODEL_PATH):
|
| 78 |
+
print(f"Model not found at '{MODEL_PATH}'")
|
| 79 |
+
exit()
|
| 80 |
+
|
| 81 |
+
if not os.path.exists(IMAGE_PATH):
|
| 82 |
+
print(f"Image not found at '{IMAGE_PATH}'")
|
| 83 |
+
exit()
|
| 84 |
+
|
| 85 |
+
print("Loading model...")
|
| 86 |
+
model = tf.keras.models.load_model(MODEL_PATH)
|
| 87 |
+
print("Model loaded.")
|
| 88 |
+
|
| 89 |
+
print(f"Predicting image: {IMAGE_PATH}")
|
| 90 |
+
image_tensor = preprocess_image(IMAGE_PATH)
|
| 91 |
+
if image_tensor is None:
|
| 92 |
+
exit()
|
| 93 |
+
|
| 94 |
+
results = predict(model, image_tensor)
|
| 95 |
+
|
| 96 |
+
print("\\n--- Prediction Result ---")
|
| 97 |
+
for class_name, confidence in sorted(results.items(), key=lambda x: x[1], reverse=True):
|
| 98 |
+
print(f"{class_name:<15}: {confidence * 100:.2f}%")
|
| 99 |
+
```
|
| 100 |
+
|
| 101 |
+
```bash
|
| 102 |
+
Loading model...
|
| 103 |
+
Model loaded.
|
| 104 |
+
Predicting image: example.png
|
| 105 |
+
|
| 106 |
+
--- Prediction Result ---
|
| 107 |
+
general : 54.99%
|
| 108 |
+
questionable : 22.57%
|
| 109 |
+
explicit : 22.44%
|
| 110 |
+
|
| 111 |
+
```
|
| 112 |
+
|
| 113 |
+
## ⚠️ Disclaimer
|
| 114 |
+
|
| 115 |
+
- This model is not perfect and might misclassify borderline content.
|
| 116 |
+
- **Do not** use it for serious moderation or legal filtering without thorough evaluation.
|
| 117 |
+
- Dataset is based on subjective human tagging (Danbooru), which may include biases.
|
| 118 |
+
|
| 119 |
+
## 📄 License
|
| 120 |
+
|
| 121 |
+
MIT License
|