Skip to content

Commit

Permalink
Merge pull request #62 from alganzory/feature/nsfw-only-mode
Browse files Browse the repository at this point in the history
allow nsfw only mode (no face detection)
  • Loading branch information
alganzory authored Feb 24, 2024
2 parents a988edc + 116d4e8 commit 3803b25
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
7 changes: 6 additions & 1 deletion src/modules/detector.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,11 @@ const containsGenderFace = (detections, detectMale, detectFemale) => {
}

const faces = detections.face;
if (detectMale && detectFemale)
return faces.some(
(face) =>
face.age > 20
);
if (detectMale || detectFemale)
return faces.some(
(face) =>
Expand All @@ -330,7 +335,7 @@ const containsGenderFace = (detections, detectMale, detectFemale) => {
detectFemale
)
);
else return true; // If no gender specified, return true cause there's a face
else return false;
};
// export the human variable and the HUMAN_CONFIG object
export {
Expand Down
7 changes: 1 addition & 6 deletions src/modules/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,7 @@ class Settings {

shouldDetect() {
if (!this._settings.status) return false;
if (!this.shouldDetectImages() && !this.shouldDetectVideos())
return false;

// at least 1 gender should be selected for detection to start,
// this could change in the future (if we wanna allow nsfw only detection)
return this.shouldDetectGender();
return (this.shouldDetectImages() || this.shouldDetectVideos());
}

isBlurryStartMode() {
Expand Down
1 change: 1 addition & 0 deletions src/offscreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ const runDetection = async (img, isVideo = false) => {
human.tf.dispose(tensor);
return "nsfw";
}
if (!settings.shouldDetectGender()) return false; // no need to run gender detection if it's not enabled
const predictions = await humanModelClassify(tensor);
// console.log("offscreen human result", predictions);
human.tf.dispose(tensor);
Expand Down

0 comments on commit 3803b25

Please sign in to comment.