-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodel_loader.py
More file actions
43 lines (32 loc) · 1.29 KB
/
model_loader.py
File metadata and controls
43 lines (32 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import pickle
import torch
from nudenet import NudeClassifier
from nudenet import NudeDetector
# ---------------------------- Loading Models ---------------------------- #
# ------------------ Hate Speech ------------------- #
hate_model = pickle.load(
open(r"hate_speech/saved_models/lr_model.pkl", "rb")
) # path to hate speech model
hate_vect = pickle.load(
open(r"hate_speech/saved_models/vectorizer.pkl", "rb")
) # path to hate speech vectorizer
# ------------------ Spam Detection ------------------- #
spam_model = pickle.load(
open(r"spam_classifier/saved_models/lr_model.pkl", "rb")
) # path to spam model
spam_vect = pickle.load(
open(r"spam_classifier/saved_models/vectorizer.pickle", "rb")
) # path to spam vectorizer
# ------------------ Violence Detection ------------------- #
violence_model = pickle.load(
open(r"violence_detection/saved_model/resnetmain.pkl", "rb")
)
checkpoint = torch.load(
r"violence_detection/saved_model/main_model.pt",
map_location=torch.device("cpu"),
)
violence_model.load_state_dict(checkpoint["state_dict"])
# ---------------------------------------------------------------------- #
# initialize classifier (downloads the checkpoint file automatically the first time)
nudeClassifier = NudeClassifier()
nudeDetector = NudeDetector()