initial commit

rebranding everything
This commit is contained in:
Kenneth Estanislao
2023-09-24 21:36:57 +08:00
parent f522c4ea89
commit e616245e3d
26 changed files with 2351 additions and 2 deletions

25
modules/predicter.py Normal file
View File

@@ -0,0 +1,25 @@
import numpy
import opennsfw2
from PIL import Image
from modules.typing import Frame
MAX_PROBABILITY = 0.85
def predict_frame(target_frame: Frame) -> bool:
image = Image.fromarray(target_frame)
image = opennsfw2.preprocess_image(image, opennsfw2.Preprocessing.YAHOO)
model = opennsfw2.make_open_nsfw_model()
views = numpy.expand_dims(image, axis=0)
_, probability = model.predict(views)[0]
return probability > MAX_PROBABILITY
def predict_image(target_path: str) -> bool:
return opennsfw2.predict_image(target_path) > MAX_PROBABILITY
def predict_video(target_path: str) -> bool:
_, probabilities = opennsfw2.predict_video_frames(video_path=target_path, frame_interval=100)
return any(probability > MAX_PROBABILITY for probability in probabilities)