deepfake-detector / python convert_model.py
yaya36095's picture
Create python convert_model.py
b25f77f verified
raw
history blame contribute delete
684 Bytes
import torch
from transformers import AutoConfig
# تحميل النموذج الأصلي
model_path = "best_model_improved.pth"
model = torch.load(model_path)
# إنشاء ملف التكوين إذا لم يكن موجوداً
config = AutoConfig.for_model("efficientnet-b0",
num_labels=2, # عدد الفئات (حقيقي/مزيف)
label2id={"real": 0, "fake": 1},
id2label={0: "real", 1: "fake"})
config.save_pretrained("./")
# حفظ النموذج بصيغة pytorch_model.bin
torch.save(model.state_dict(), "pytorch_model.bin")
print("تم تحويل النموذج بنجاح!")