Skip to content

Commit

Permalink
Merge pull request #31 from deepghs/dev/nsfw
Browse files Browse the repository at this point in the history
dev(narugo): add nsfw prediction from nsfwjs library in javascript
  • Loading branch information
narugo1992 authored Jun 26, 2023
2 parents 5b318d1 + c671c37 commit 3347abe
Show file tree
Hide file tree
Showing 69 changed files with 4,206 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/source/api_doc/validate/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ imgutils.validate
classify
color
monochrome
nsfw
rating
truncate
16 changes: 16 additions & 0 deletions docs/source/api_doc/validate/nsfw.plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import glob
import os.path

from natsort import natsorted

from plot import image_plot

if __name__ == '__main__':
image_plot(
*natsorted(glob.glob(os.path.join('nsfw', 'drawings', '*.jpg'))),
*natsorted(glob.glob(os.path.join('nsfw', 'hentai', '*.jpg'))),
*natsorted(glob.glob(os.path.join('nsfw', 'neutral', '*.jpg'))),
*natsorted(glob.glob(os.path.join('nsfw', 'porn', '*.jpg'))),
*natsorted(glob.glob(os.path.join('nsfw', 'sexy', '*.jpg'))),
columns=4, figsize=(10, 18.5),
)
1,497 changes: 1,497 additions & 0 deletions docs/source/api_doc/validate/nsfw.plot.py.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions docs/source/api_doc/validate/nsfw.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
imgutils.validate.nsfw
=============================================

.. currentmodule:: imgutils.validate.nsfw

.. automodule:: imgutils.validate.nsfw


nsfw_pred_score
----------------------------------------

.. autofunction:: nsfw_pred_score



nsfw_pred
----------------------------------------

.. autofunction:: nsfw_pred



Binary file added docs/source/api_doc/validate/nsfw/drawings/1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/api_doc/validate/nsfw/drawings/2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/api_doc/validate/nsfw/drawings/3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/api_doc/validate/nsfw/drawings/4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/api_doc/validate/nsfw/hentai/5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/api_doc/validate/nsfw/hentai/6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/api_doc/validate/nsfw/hentai/7.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/api_doc/validate/nsfw/hentai/8.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/api_doc/validate/nsfw/neutral/10.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/api_doc/validate/nsfw/neutral/11.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/api_doc/validate/nsfw/neutral/12.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/api_doc/validate/nsfw/neutral/9.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/api_doc/validate/nsfw/porn/13.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/api_doc/validate/nsfw/porn/14.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/api_doc/validate/nsfw/porn/15.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/api_doc/validate/nsfw/porn/16.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/api_doc/validate/nsfw/sexy/17.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/api_doc/validate/nsfw/sexy/18.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/api_doc/validate/nsfw/sexy/19.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/api_doc/validate/nsfw/sexy/20.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions docs/source/api_doc/validate/nsfw_benchmark.plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import random

from benchmark import BaseBenchmark, create_plot_cli
from imgutils.validate import nsfw_pred_score
from imgutils.validate.nsfw import _MODEL_NAMES


class AnimeNSFWBenchmark(BaseBenchmark):
def __init__(self, model):
BaseBenchmark.__init__(self)
self.model = model

def load(self):
from imgutils.validate.nsfw import _open_nsfw_model
_ = _open_nsfw_model(self.model)

def unload(self):
from imgutils.validate.nsfw import _open_nsfw_model
_open_nsfw_model.cache_clear()

def run(self):
image_file = random.choice(self.all_images)
_ = nsfw_pred_score(image_file, self.model)


if __name__ == '__main__':
create_plot_cli(
[
(name, AnimeNSFWBenchmark(name))
for name in _MODEL_NAMES
],
title='Benchmark for NSFW Models',
run_times=10,
try_times=20,
)()
Loading

0 comments on commit 3347abe

Please sign in to comment.