Create convert_model.py
Browse files- convert_model.py +18 -0
convert_model.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from transformers import AutoConfig
|
3 |
+
|
4 |
+
# تحميل النموذج الأصلي
|
5 |
+
model_path = "best_model_improved.pth"
|
6 |
+
model = torch.load(model_path)
|
7 |
+
|
8 |
+
# إنشاء ملف التكوين إذا لم يكن موجوداً
|
9 |
+
config = AutoConfig.for_model("efficientnet-b0",
|
10 |
+
num_labels=2, # عدد الفئات (حقيقي/مزيف)
|
11 |
+
label2id={"real": 0, "fake": 1},
|
12 |
+
id2label={0: "real", 1: "fake"})
|
13 |
+
config.save_pretrained("./")
|
14 |
+
|
15 |
+
# حفظ النموذج بصيغة pytorch_model.bin
|
16 |
+
torch.save(model.state_dict(), "pytorch_model.bin")
|
17 |
+
|
18 |
+
print("تم تحويل النموذج بنجاح!")
|