Update README.md
Browse files
README.md
CHANGED
|
@@ -40,7 +40,36 @@ To load and use the model in your Python environment, use the standard `transfor
|
|
| 40 |
|
| 41 |
```bash
|
| 42 |
pip install transformers torch pillow
|
|
|
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
---
|
| 45 |
license: mit
|
| 46 |
---
|
|
|
|
| 40 |
|
| 41 |
```bash
|
| 42 |
pip install transformers torch pillow
|
| 43 |
+
```
|
| 44 |
|
| 45 |
+
```python
|
| 46 |
+
from transformers import AutoModelForImageClassification, AutoFeatureExtractor
|
| 47 |
+
from PIL import Image
|
| 48 |
+
import torch
|
| 49 |
+
|
| 50 |
+
image_path = 'path/to/your/image.jpg'
|
| 51 |
+
model_id = "SADRACODING/SDXL-Deepfake-Detector"
|
| 52 |
+
|
| 53 |
+
# Load Model and Feature Extractor
|
| 54 |
+
model = AutoModelForImageClassification.from_pretrained(model_id)
|
| 55 |
+
feature_extractor = AutoFeatureExtractor.from_pretrained(model_id)
|
| 56 |
+
|
| 57 |
+
# Preprocessing
|
| 58 |
+
image = Image.open(image_path).convert("RGB")
|
| 59 |
+
inputs = feature_extractor(images=image, return_tensors="pt")
|
| 60 |
+
|
| 61 |
+
# Inference
|
| 62 |
+
with torch.no_grad():
|
| 63 |
+
logits = model(**inputs).logits
|
| 64 |
+
|
| 65 |
+
# Post-processing and Prediction
|
| 66 |
+
predicted_class_id = logits.argmax().item()
|
| 67 |
+
labels = ["REAL", "FAKE"]
|
| 68 |
+
prediction = labels[predicted_class_id]
|
| 69 |
+
confidence = torch.nn.functional.softmax(logits, dim=-1)[0][predicted_class_id].item()
|
| 70 |
+
|
| 71 |
+
print(f"Prediction: {prediction} (Confidence: {confidence:.4f})")
|
| 72 |
+
```
|
| 73 |
---
|
| 74 |
license: mit
|
| 75 |
---
|