Create inference.py
Browse files- inference.py +17 -0
inference.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from transformers import AutoModelForImageClassification, AutoFeatureExtractor
|
3 |
+
from PIL import Image
|
4 |
+
|
5 |
+
# Load model and feature extractor
|
6 |
+
model = AutoModelForImageClassification.from_pretrained("your-username/deepfake-recognition")
|
7 |
+
feature_extractor = AutoFeatureExtractor.from_pretrained("your-username/deepfake-recognition")
|
8 |
+
|
9 |
+
# Load an image
|
10 |
+
image = Image.open("sample_image.jpg")
|
11 |
+
inputs = feature_extractor(images=image, return_tensors="pt")
|
12 |
+
|
13 |
+
# Predict
|
14 |
+
outputs = model(**inputs)
|
15 |
+
predicted_class = torch.argmax(outputs.logits, dim=1).item()
|
16 |
+
|
17 |
+
print(f"Predicted Class: {'Deepfake' if predicted_class == 1 else 'Real'}")
|