Aadhithya
commited on
Commit
·
2b0fbf3
1
Parent(s):
eb07ba9
Update roop/predicter.py
Browse files- roop/predicter.py +21 -8
roop/predicter.py
CHANGED
@@ -1,25 +1,38 @@
|
|
1 |
-
import
|
2 |
-
import
|
3 |
from PIL import Image
|
|
|
4 |
|
5 |
from roop.typing import Frame
|
6 |
|
|
|
|
|
7 |
MAX_PROBABILITY = 0.85
|
8 |
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
def predict_frame(target_frame: Frame) -> bool:
|
11 |
image = Image.fromarray(target_frame)
|
12 |
-
image =
|
13 |
-
|
14 |
-
|
15 |
-
_, probability = model.predict(views)[0]
|
16 |
return probability > MAX_PROBABILITY
|
17 |
|
18 |
|
19 |
def predict_image(target_path: str) -> bool:
|
20 |
-
return
|
21 |
|
22 |
|
23 |
def predict_video(target_path: str) -> bool:
|
24 |
-
_, probabilities =
|
25 |
return any(probability > MAX_PROBABILITY for probability in probabilities)
|
|
|
1 |
+
import threading
|
2 |
+
import numpy as np
|
3 |
from PIL import Image
|
4 |
+
from keras import Model
|
5 |
|
6 |
from roop.typing import Frame
|
7 |
|
8 |
+
PREDICTOR = None
|
9 |
+
THREAD_LOCK = threading.Lock()
|
10 |
MAX_PROBABILITY = 0.85
|
11 |
|
12 |
|
13 |
+
def get_predictor() -> None:
|
14 |
+
global PREDICTOR
|
15 |
+
|
16 |
+
PREDICTOR = None
|
17 |
+
|
18 |
+
def clear_predictor() -> None:
|
19 |
+
global PREDICTOR
|
20 |
+
|
21 |
+
PREDICTOR = None
|
22 |
+
|
23 |
+
|
24 |
def predict_frame(target_frame: Frame) -> bool:
|
25 |
image = Image.fromarray(target_frame)
|
26 |
+
image = preprocess_image(image) # Replace this with the code to preprocess your image
|
27 |
+
views = np.expand_dims(image, axis=0)
|
28 |
+
_, probability = get_predictor().predict(views)[0]
|
|
|
29 |
return probability > MAX_PROBABILITY
|
30 |
|
31 |
|
32 |
def predict_image(target_path: str) -> bool:
|
33 |
+
return predict_single_image(target_path) > MAX_PROBABILITY # Replace this with your image prediction logic
|
34 |
|
35 |
|
36 |
def predict_video(target_path: str) -> bool:
|
37 |
+
_, probabilities = predict_video_frames(video_path=target_path, frame_interval=100) # Replace this with your video prediction logic
|
38 |
return any(probability > MAX_PROBABILITY for probability in probabilities)
|