SivaMallikarjun commited on
Commit
ac2f4c2
·
verified ·
1 Parent(s): 3b22c6e

Create inference.py

Browse files
Files changed (1) hide show
  1. 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'}")