This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
Source du modèle
Description de la source
This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
Sources
1 sourceVérifié 17 sept.
Artefacts du modèle
1 artefactExtraits de sources
2 extraitsThe model is fine-tuned on ConvNext V2 model.
This finetuned model can be used for text classification. It has been trained to classify real and fake images.
import os
import torch
from PIL import Image
from transformers import AutoImageProcessor, AutoModelForImageClassification
MODEL_ID = "computervisionpro/convnextv2-real-fake"
def predict(image_path, model_id=MODEL_ID):
# device = "cuda" if torch.cuda.is_available() else "cpu"
device = "cpu"
# hf_token = os.getenv("HF_TOKEN") or None
processor = AutoImageProcessor.from_pretrained(model_id)
model = AutoModelForImageClassification.from_pretrained(model_id)
model.to(device)
model.eval()
image = Image.open(image_path).convert("RGB")
inputs = processor(images=image, return_tensors="pt")
inputs = {key: value.to(device) for key, value in inputs.items()}
with torch.inference_mode():
outputs = model(**inputs)
probs = torch.softmax(outputs.logits, dim=-1)[0]
pred_id = int(torch.argmax(probs).item())
label = model.config.id2label.get(pred_id, str(pred_id))
confidence = float(probs[pred_id].item())
return {
"image": image_path,
"model": model_id,
"prediction": label,
"confidence": confidence,
"probabilities": {
model.config.id2label.get(i, str(i)): float(prob.item())
for i, prob in enumerate(probs)
},
}
result = predict("./dataset/test/fake/fake_1006.jpg")
print()
print(result)
--- library_name: transformers tags: - classification - deepfake base_model: - facebook/convnextv2-tiny-1k-224 --- # Model Card for Model ID <!-- Provide a quick summary of what the model is/does. --> ## Model Details ### Model Description <!-- Provide a longer summary of what this model is. --> This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated. ### Model Sources [optional] <!-- Provide the basic links for the model. --> - **Repository:** [github](https://github.com/g25ait2119/mlops-pipeline-group30) - **Paper:** [ConvNeXt V2](https://arxiv.org/abs/2301.00808) ## Model Description The model is fine-tuned on ConvNext V2 model. ## Uses This finetuned model can be used for text classification. It has been trained to classify real and fake images. #### Hardware - **Hardware Type:** GPU T4 - **Hours used:** ~ 14 Minutes - **Cloud Provider:** Kaggle ### Inference code ```python import os import torch from PIL import Image from transformers import AutoImageProcessor, AutoModelForImageClassification MODEL_ID = "computervisionpro/convnextv2-real-fake" def predict(image_path, model_id=MODEL_ID): # device = "cuda" if torch.cuda.is_available() else "cpu" device = "cpu" # hf_token = os.getenv("HF_TOKEN") or None processor = AutoImageProcessor.from_pretrained(model_id) model = AutoModelForImageClassification.from_pretrained(model_id) model.to(device) model.eval() image = Image.open(image_path).convert("RGB") inputs = processor(images=image, return_tensors="pt") inputs = {key: value.to(device) for key, value in inputs.items()} with torch.inference_mode(): outputs = model(**inputs) probs = torch.softmax(outputs.logits, dim=-1)[0] pred_id = int(torch.argmax(probs).item()) label = model.config.id2label.get(pred_id, str(pred_id)) confidence = float(probs[pred_id].item()) return { "image": image_path, "model": model_id, "prediction": label, "confidence": confidence, "probabilities": { model.config.id2label.get(i, str(i)): float(prob.item()) for i, prob in enumerate(probs) }, } result = predict("./dataset/test/fake/fake_1006.jpg") print() print(result) ``` ### Results - [WandB](https://wandb.ai/computervisionpro-na/mlops-assignment3) ## Important Links - [Data](https://www.kaggle.com/datasets/manjilkarki/deepfake-and-real-images) - [Kaggle...
Source context: 48 downloads · 0 likes · Pipeline image-classification · Library transformers · Repo computervisionpro/convnextv2-real-fake