NudeNet: Neural Nets for Nudity Classification, Detection and selective censoring

NudeNet: Neural Nets for Nudity Classification, Detection and selective censoring

DOI Upload Python package

Uncensored version of the following image can be found at https://i.imgur.com/rga6845.jpg (NSFW)

Classifier classes:

class name Description
safe Image/Video is not sexually explicit
unsafe Image/Video is sexually explicit

Default Detector classes:

class name Description
EXPOSED_ANUS Exposed Anus; Any gender
EXPOSED_ARMPITS Exposed Armpits; Any gender
COVERED_BELLY Provocative, but covered Belly; Any gender
EXPOSED_BELLY Exposed Belly; Any gender
COVERED_BUTTOCKS Provocative, but covered Buttocks; Any gender
EXPOSED_BUTTOCKS Exposed Buttocks; Any gender
FACE_F Female Face
FACE_M Male Face
COVERED_FEET Covered Feet; Any gender
EXPOSED_FEET Exposed Feet; Any gender
COVERED_BREAST_F Provocative, but covered Breast; Female
EXPOSED_BREAST_F Exposed Breast; Female
COVERED_GENITALIA_F Provocative, but covered Genitalia; Female
EXPOSED_GENITALIA_F Exposed Genitalia; Female
EXPOSED_BREAST_M Exposed Breast; Male
EXPOSED_GENITALIA_M Exposed Genitalia; Male

Base Detector classes:

class name Description
EXPOSED_BELLY Exposed Belly; Any gender
EXPOSED_BUTTOCKS Exposed Buttocks; Any gender
EXPOSED_BREAST_F Exposed Breast; Female
EXPOSED_GENITALIA_F Exposed Genitalia; Female
EXPOSED_GENITALIA_M Exposed Genitalia; Male
EXPOSED_BREAST_M Exposed Breast; Male

As self-hostable API service

# Classifier
docker run -it -p8080:8080 notaitech/nudenet:classifier

# Detector
docker run -it -p8080:8080 notaitech/nudenet:detector

# See fastDeploy-file_client.py for running predictions via fastDeploy's REST endpoints 
wget https://raw.githubusercontent.com/notAI-tech/fastDeploy/master/cli/fastDeploy-file_client.py
# Single input
python fastDeploy-file_client.py --file PATH_TO_YOUR_IMAGE

# Client side batching
python fastDeploy-file_client.py --dir PATH_TO_FOLDER --ext jpg

Note: golang example https://github.com/notAI-tech/NudeNet/issues/63#issuecomment-729555360, thanks to Preetham Kamidi

As Python module

Installation:

pip install --upgrade nudenet

Classifier Usage:

# Import module
from nudenet import NudeClassifier

# initialize classifier (downloads the checkpoint file automatically the first time)
classifier = NudeClassifier()

# Classify single image
classifier.classify('path_to_image_1')
# Returns {'path_to_image_1': {'safe': PROBABILITY, 'unsafe': PROBABILITY}}
# Classify multiple images (batch prediction)
# batch_size is optional; defaults to 4
classifier.classify(['path_to_image_1', 'path_to_image_2'], batch_size=BATCH_SIZE)
# Returns {'path_to_image_1': {'safe': PROBABILITY, 'unsafe': PROBABILITY},
#          'path_to_image_2': {'safe': PROBABILITY, 'unsafe': PROBABILITY}}

# Classify video
# batch_size is optional; defaults to 4
classifier.classify_video('path_to_video', batch_size=BATCH_SIZE)
# Returns {"metadata": {"fps": FPS, "video_length": TOTAL_N_FRAMES, "video_path": 'path_to_video'},
#          "preds": {frame_i: {'safe': PROBABILITY, 'unsafe': PROBABILITY}, ....}}

Thanks to Johnny Urosevic, NudeClassifier is also available in tflite.

TFLite Classifier Usage:

# Import module
from nudenet import NudeClassifierLite

# initialize classifier (downloads the checkpoint file automatically the first time)
classifier_lite = NudeClassifierLite()

# Classify single image
classifier_lite.classify('path_to_image_1')
# Returns {'path_to_image_1': {'safe': PROBABILITY, 'unsafe': PROBABILITY}}
# Classify multiple images (batch prediction)
# batch_size is optional; defaults to 4
classifier_lite.classify(['path_to_image_1', 'path_to_image_2'])
# Returns {'path_to_image_1': {'safe': PROBABILITY, 'unsafe': PROBABILITY},
#          'path_to_image_2': {'safe': PROBABILITY, 'unsafe': PROBABILITY}}

Using the tflite classifier from flutter: https://github.com/ndaysinaiK/nude-test

Detector Usage:

# Import module
from nudenet import NudeDetector

# initialize detector (downloads the checkpoint file automatically the first time)
detector = NudeDetector() # detector = NudeDetector('base') for the "base" version of detector.

# Detect single image
detector.detect('path_to_image')
# fast mode is ~3x faster compared to default mode with slightly lower accuracy.
detector.detect('path_to_image', mode='fast')
# Returns [{'box': LIST_OF_COORDINATES, 'score': PROBABILITY, 'label': LABEL}, ...]

# Detect video
# batch_size is optional; defaults to 2
# show_progress is optional; defaults to True
detector.detect_video('path_to_video', batch_size=BATCH_SIZE, show_progress=BOOLEAN)
# fast mode is ~3x faster compared to default mode with slightly lower accuracy.
detector.detect_video('path_to_video', batch_size=BATCH_SIZE, show_progress=BOOLEAN, mode='fast')
# Returns {"metadata": {"fps": FPS, "video_length": TOTAL_N_FRAMES, "video_path": 'path_to_video'},
#          "preds": {frame_i: {'box': LIST_OF_COORDINATES, 'score': PROBABILITY, 'label': LABEL}, ...], ....}}

Notes:

  • detect_video and classify_video first identify the "unique" frames in a video and run predictions on them for significant performance improvement.
  • V1 of NudeDetector (available in master branch of this repo) was trained on 12000 images labelled by the good folks at cti-community.
  • V2 (current version) of NudeDetector is trained on 160,000 entirely auto-labelled (using classification heat maps and various other hybrid techniques) images.
  • The entire data for the classifier is available at https://archive.org/details/NudeNet_classifier_dataset_v1
  • A part of the auto-labelled data (Images are from the classifier dataset above) used to train the base Detector is available at https://github.com/notAI-tech/NudeNet/releases/download/v0/DETECTOR_AUTO_GENERATED_DATA.zip
Owner
notAI.tech
Open Source initiative by a group of bored engineers.
notAI.tech
Comments
  • Train our Model

    Train our Model

    Hello i saw your project in Reddit so i came here to ask by any chance you're going to share with us how you train your Model to train ours with our data-set? I hope if you're going to share with us the method it will be a big help to the community!

  • ModuleNotFoundError: No module named 'nudenet'

    ModuleNotFoundError: No module named 'nudenet'

    (tf) C:\nude>nude.py Traceback (most recent call last): File "C:\nude\nude.py", line 2, in from nudenet import NudeClassifier ModuleNotFoundError: No module named 'nudenet

    I am getting this error while trying to use a classifier

  • Error when using NudeNet

    Error when using NudeNet

    This is the stack trace I'm getting when trying to instanciate a NudeClassifier. A pretty much identical error occurs when trying to instanciate a NudeDetector.

    ---------------------------------------------------------------------------
    AttributeError                            Traceback (most recent call last)
    <ipython-input-9-7465e1bf88d0> in <module>
    ----> 1 classifier = NudeClassifier()
    
    ~\Python\portable\python\Lib\site-packages\nudenet\classifier.py in __init__(self)
        137             pydload.dload(url, save_to_path=model_path, max_time=None)
        138 
    --> 139         self.nsfw_model = keras.models.load_model(model_path)
        140 
        141     def classify_video(
    
    ~\Python\portable\python\Lib\site-packages\keras\engine\saving.py in load_model(filepath, custom_objects, compile)
        417     f = h5dict(filepath, 'r')
        418     try:
    --> 419         model = _deserialize_model(f, custom_objects, compile)
        420     finally:
        421         if opened_new_file:
    
    ~\Python\portable\python\Lib\site-packages\keras\engine\saving.py in _deserialize_model(f, custom_objects, compile)
        223         raise ValueError('No model found in config.')
        224     model_config = json.loads(model_config.decode('utf-8'))
    --> 225     model = model_from_config(model_config, custom_objects=custom_objects)
        226     model_weights_group = f['model_weights']
        227 
    
    ~\Python\portable\python\Lib\site-packages\keras\engine\saving.py in model_from_config(config, custom_objects)
        456                         '`Sequential.from_config(config)`?')
        457     from ..layers import deserialize
    --> 458     return deserialize(config, custom_objects=custom_objects)
        459 
        460 
    
    ~\Python\portable\python\Lib\site-packages\keras\layers\__init__.py in deserialize(config, custom_objects)
         50     globs['Model'] = models.Model
         51     globs['Sequential'] = models.Sequential
    ---> 52     return deserialize_keras_object(config,
         53                                     module_objects=globs,
         54                                     custom_objects=custom_objects,
    
    ~\Python\portable\python\Lib\site-packages\keras\utils\generic_utils.py in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name)
        140             custom_objects = custom_objects or {}
        141             if has_arg(cls.from_config, 'custom_objects'):
    --> 142                 return cls.from_config(
        143                     config['config'],
        144                     custom_objects=dict(list(_GLOBAL_CUSTOM_OBJECTS.items()) +
    
    ~\Python\portable\python\Lib\site-packages\keras\engine\network.py in from_config(cls, config, custom_objects)
       1020         # First, we create all layers and enqueue nodes to be processed
       1021         for layer_data in config['layers']:
    -> 1022             process_layer(layer_data)
       1023         # Then we process nodes in order of layer depth.
       1024         # Nodes that cannot yet be processed (if the inbound node
    
    ~\Python\portable\python\Lib\site-packages\keras\engine\network.py in process_layer(layer_data)
       1005             from ..layers import deserialize as deserialize_layer
       1006 
    -> 1007             layer = deserialize_layer(layer_data,
       1008                                       custom_objects=custom_objects)
       1009             created_layers[layer_name] = layer
    
    ~\Python\portable\python\Lib\site-packages\keras\layers\__init__.py in deserialize(config, custom_objects)
         50     globs['Model'] = models.Model
         51     globs['Sequential'] = models.Sequential
    ---> 52     return deserialize_keras_object(config,
         53                                     module_objects=globs,
         54                                     custom_objects=custom_objects,
    
    ~\Python\portable\python\Lib\site-packages\keras\utils\generic_utils.py in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name)
        145                                         list(custom_objects.items())))
        146             with CustomObjectScope(custom_objects):
    --> 147                 return cls.from_config(config['config'])
        148         else:
        149             # Then `cls` may be a function returning a class.
    
    ~\Python\portable\python\Lib\site-packages\keras\engine\base_layer.py in from_config(cls, config)
       1107             A layer instance.
       1108         """
    -> 1109         return cls(**config)
       1110 
       1111     def count_params(self):
    
    ~\Python\portable\python\Lib\site-packages\keras\legacy\interfaces.py in wrapper(*args, **kwargs)
         89                 warnings.warn('Update your `' + object_name + '` call to the ' +
         90                               'Keras 2 API: ' + signature, stacklevel=2)
    ---> 91             return func(*args, **kwargs)
         92         wrapper._original_function = func
         93         return wrapper
    
    ~\Python\portable\python\Lib\site-packages\keras\engine\input_layer.py in __init__(self, input_shape, batch_size, batch_input_shape, dtype, input_tensor, sparse, name)
         82         if input_tensor is None:
         83             self.is_placeholder = True
    ---> 84             input_tensor = K.placeholder(shape=batch_input_shape,
         85                                          dtype=dtype,
         86                                          sparse=self.sparse,
    
    ~\Python\portable\python\Lib\site-packages\keras\backend\tensorflow_backend.py in placeholder(shape, ndim, dtype, sparse, name)
        515         x = tf.sparse_placeholder(dtype, shape=shape, name=name)
        516     else:
    --> 517         x = tf.placeholder(dtype, shape=shape, name=name)
        518     x._keras_shape = shape
        519     x._uses_learning_phase = False
    
    AttributeError: module 'tensorflow' has no attribute 'placeholder'
    

    I've googled around and these seem to be issues with Keras that have since been fixed? Basically, when I use keras==2.2.4 (which is listed in this library's setup.py) I can't get past this stage.

    I've tried upgrading to the latest version of keras for my own curiosity (keras==2.4.3) and the NudeClassifier then works perfectly! However, the NudeDetector now errors like this when I try to instanciate it:

    ---------------------------------------------------------------------------
    TypeError                                 Traceback (most recent call last)
    <ipython-input-8-c0ac40df705b> in <module>
    ----> 1 detector = NudeDetector()
    
    ~\Python\portable\python\Lib\site-packages\nudenet\detector.py in __init__(self, model_name)
         76             pydload.dload(classes_url, save_to_path=classes_path, max_time=None)
         77 
    ---> 78         self.detection_model = models.load_model(
         79             checkpoint_path, backbone_name="resnet50"
         80         )
    
    ~\Python\portable\python\Lib\site-packages\keras_retinanet\models\__init__.py in load_model(filepath, backbone_name)
         81     """
         82     import keras.models
    ---> 83     return keras.models.load_model(filepath, custom_objects=backbone(backbone_name).custom_objects)
         84 
         85 
    
    ~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\saving\save.py in load_model(filepath, custom_objects, compile, options)
        180     if (h5py is not None and (
        181         isinstance(filepath, h5py.File) or h5py.is_hdf5(filepath))):
    --> 182       return hdf5_format.load_model_from_hdf5(filepath, custom_objects, compile)
        183 
        184     filepath = path_to_string(filepath)
    
    ~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\saving\hdf5_format.py in load_model_from_hdf5(filepath, custom_objects, compile)
        175       raise ValueError('No model found in config file.')
        176     model_config = json.loads(model_config.decode('utf-8'))
    --> 177     model = model_config_lib.model_from_config(model_config,
        178                                                custom_objects=custom_objects)
        179 
    
    ~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\saving\model_config.py in model_from_config(config, custom_objects)
         53                     '`Sequential.from_config(config)`?')
         54   from tensorflow.python.keras.layers import deserialize  # pylint: disable=g-import-not-at-top
    ---> 55   return deserialize(config, custom_objects=custom_objects)
         56 
         57 
    
    ~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\layers\serialization.py in deserialize(config, custom_objects)
        169   """
        170   populate_deserializable_objects()
    --> 171   return generic_utils.deserialize_keras_object(
        172       config,
        173       module_objects=LOCAL.ALL_OBJECTS,
    
    ~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\utils\generic_utils.py in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name)
        352 
        353       if 'custom_objects' in arg_spec.args:
    --> 354         return cls.from_config(
        355             cls_config,
        356             custom_objects=dict(
    
    ~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\engine\training.py in from_config(cls, config, custom_objects)
       2236     # be constructed for FunctionalModel
       2237     from tensorflow.python.keras.engine import functional  # pylint: disable=g-import-not-at-top
    -> 2238     return functional.Functional.from_config(
       2239         config, custom_objects=custom_objects)
       2240 
    
    ~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\engine\functional.py in from_config(cls, config, custom_objects)
        614         ValueError: In case of improperly formatted config dict.
        615     """
    --> 616     input_tensors, output_tensors, created_layers = reconstruct_from_config(
        617         config, custom_objects)
        618     model = cls(inputs=input_tensors, outputs=output_tensors,
    
    ~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\engine\functional.py in reconstruct_from_config(config, custom_objects, created_layers)
       1202   # First, we create all layers and enqueue nodes to be processed
       1203   for layer_data in config['layers']:
    -> 1204     process_layer(layer_data)
       1205   # Then we process nodes in order of layer depth.
       1206   # Nodes that cannot yet be processed (if the inbound node
    
    ~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\engine\functional.py in process_layer(layer_data)
       1184       from tensorflow.python.keras.layers import deserialize as deserialize_layer  # pylint: disable=g-import-not-at-top
       1185 
    -> 1186       layer = deserialize_layer(layer_data, custom_objects=custom_objects)
       1187       created_layers[layer_name] = layer
       1188 
    
    ~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\layers\serialization.py in deserialize(config, custom_objects)
        169   """
        170   populate_deserializable_objects()
    --> 171   return generic_utils.deserialize_keras_object(
        172       config,
        173       module_objects=LOCAL.ALL_OBJECTS,
    
    ~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\utils\generic_utils.py in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name)
        352 
        353       if 'custom_objects' in arg_spec.args:
    --> 354         return cls.from_config(
        355             cls_config,
        356             custom_objects=dict(
    
    ~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\engine\training.py in from_config(cls, config, custom_objects)
       2236     # be constructed for FunctionalModel
       2237     from tensorflow.python.keras.engine import functional  # pylint: disable=g-import-not-at-top
    -> 2238     return functional.Functional.from_config(
       2239         config, custom_objects=custom_objects)
       2240 
    
    ~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\engine\functional.py in from_config(cls, config, custom_objects)
        614         ValueError: In case of improperly formatted config dict.
        615     """
    --> 616     input_tensors, output_tensors, created_layers = reconstruct_from_config(
        617         config, custom_objects)
        618     model = cls(inputs=input_tensors, outputs=output_tensors,
    
    ~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\engine\functional.py in reconstruct_from_config(config, custom_objects, created_layers)
       1212       if layer in unprocessed_nodes:
       1213         for node_data in unprocessed_nodes.pop(layer):
    -> 1214           process_node(layer, node_data)
       1215 
       1216   input_tensors = []
    
    ~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\engine\functional.py in process_node(layer, node_data)
       1160     if input_tensors is not None:
       1161       input_tensors = base_layer_utils.unnest_if_single_tensor(input_tensors)
    -> 1162       output_tensors = layer(input_tensors, **kwargs)
       1163 
       1164       # Update node index map.
    
    ~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\engine\base_layer.py in __call__(self, *args, **kwargs)
        923     # >> model = tf.keras.Model(inputs, outputs)
        924     if _in_functional_construction_mode(self, inputs, args, kwargs, input_list):
    --> 925       return self._functional_construction_call(inputs, args, kwargs,
        926                                                 input_list)
        927 
    
    ~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\engine\base_layer.py in _functional_construction_call(self, inputs, args, kwargs, input_list)
       1096         # Build layer if applicable (if the `build` method has been
       1097         # overridden).
    -> 1098         self._maybe_build(inputs)
       1099         cast_inputs = self._maybe_cast_inputs(inputs, input_list)
       1100 
    
    ~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\engine\base_layer.py in _maybe_build(self, inputs)
       2641         # operations.
       2642         with tf_utils.maybe_init_scope(self):
    -> 2643           self.build(input_shapes)  # pylint:disable=not-callable
       2644       # We must set also ensure that the layer is marked as built, and the build
       2645       # shape is stored since user defined build functions may not be calling
    
    ~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\layers\convolutional.py in build(self, input_shape)
        204         dtype=self.dtype)
        205     if self.use_bias:
    --> 206       self.bias = self.add_weight(
        207           name='bias',
        208           shape=(self.filters,),
    
    ~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\engine\base_layer.py in add_weight(self, name, shape, dtype, initializer, regularizer, trainable, constraint, partitioner, use_resource, synchronization, aggregation, **kwargs)
        595         caching_device = None
        596 
    --> 597     variable = self._add_variable_with_custom_getter(
        598         name=name,
        599         shape=shape,
    
    ~\Python\portable\python\Lib\site-packages\tensorflow\python\training\tracking\base.py in _add_variable_with_custom_getter(self, name, shape, dtype, initializer, getter, overwrite, **kwargs_for_getter)
        743         initializer = checkpoint_initializer
        744         shape = None
    --> 745     new_variable = getter(
        746         name=name,
        747         shape=shape,
    
    ~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\engine\base_layer_utils.py in make_variable(name, shape, dtype, initializer, trainable, caching_device, validate_shape, constraint, use_resource, collections, synchronization, aggregation, partitioner)
        131   # can remove the V1.
        132   variable_shape = tensor_shape.TensorShape(shape)
    --> 133   return tf_variables.VariableV1(
        134       initial_value=init_val,
        135       name=name,
    
    ~\Python\portable\python\Lib\site-packages\tensorflow\python\ops\variables.py in __call__(cls, *args, **kwargs)
        258   def __call__(cls, *args, **kwargs):
        259     if cls is VariableV1:
    --> 260       return cls._variable_v1_call(*args, **kwargs)
        261     elif cls is Variable:
        262       return cls._variable_v2_call(*args, **kwargs)
    
    ~\Python\portable\python\Lib\site-packages\tensorflow\python\ops\variables.py in _variable_v1_call(cls, initial_value, trainable, collections, validate_shape, caching_device, name, variable_def, dtype, expected_shape, import_scope, constraint, use_resource, synchronization, aggregation, shape)
        204     if aggregation is None:
        205       aggregation = VariableAggregation.NONE
    --> 206     return previous_getter(
        207         initial_value=initial_value,
        208         trainable=trainable,
    
    ~\Python\portable\python\Lib\site-packages\tensorflow\python\ops\variables.py in <lambda>(**kwargs)
        197                         shape=None):
        198     """Call on Variable class. Useful to force the signature."""
    --> 199     previous_getter = lambda **kwargs: default_variable_creator(None, **kwargs)
        200     for _, getter in ops.get_default_graph()._variable_creator_stack:  # pylint: disable=protected-access
        201       previous_getter = _make_getter(getter, previous_getter)
    
    ~\Python\portable\python\Lib\site-packages\tensorflow\python\ops\variable_scope.py in default_variable_creator(next_creator, **kwargs)
       2581   if use_resource:
       2582     distribute_strategy = kwargs.get("distribute_strategy", None)
    -> 2583     return resource_variable_ops.ResourceVariable(
       2584         initial_value=initial_value,
       2585         trainable=trainable,
    
    ~\Python\portable\python\Lib\site-packages\tensorflow\python\ops\variables.py in __call__(cls, *args, **kwargs)
        262       return cls._variable_v2_call(*args, **kwargs)
        263     else:
    --> 264       return super(VariableMetaclass, cls).__call__(*args, **kwargs)
        265 
        266 
    
    ~\Python\portable\python\Lib\site-packages\tensorflow\python\ops\resource_variable_ops.py in __init__(self, initial_value, trainable, collections, validate_shape, caching_device, name, dtype, variable_def, import_scope, constraint, distribute_strategy, synchronization, aggregation, shape)
       1505       self._init_from_proto(variable_def, import_scope=import_scope)
       1506     else:
    -> 1507       self._init_from_args(
       1508           initial_value=initial_value,
       1509           trainable=trainable,
    
    ~\Python\portable\python\Lib\site-packages\tensorflow\python\ops\resource_variable_ops.py in _init_from_args(self, initial_value, trainable, collections, caching_device, name, dtype, constraint, synchronization, aggregation, distribute_strategy, shape)
       1649           with ops.name_scope("Initializer"), device_context_manager(None):
       1650             initial_value = ops.convert_to_tensor(
    -> 1651                 initial_value() if init_from_fn else initial_value,
       1652                 name="initial_value", dtype=dtype)
       1653           if shape is not None:
    
    ~\Python\portable\python\Lib\site-packages\keras_retinanet\initializers.py in __call__(self, shape, dtype)
         35     def __call__(self, shape, dtype=None):
         36         # set bias to -log((1 - p)/p) for foreground
    ---> 37         result = np.ones(shape, dtype=dtype) * -math.log((1 - self.probability) / self.probability)
         38 
         39         return result
    
    ~\Python\portable\python\Lib\site-packages\numpy\core\numeric.py in ones(shape, dtype, order)
        205 
        206     """
    --> 207     a = empty(shape, dtype, order)
        208     multiarray.copyto(a, 1, casting='unsafe')
        209     return a
    
    TypeError: data type not understood
    

    Do you know why this is happening? I'd love to play around with this library but I can't figure out how to get past these errors.

    If it helps, I'm running Python 3.8.2

    Thanks in advance!

  • No training configuration found in the detector model

    No training configuration found in the detector model

    Hey mate, Docker running tensorflow 1.15.3 (python3) and your code.

    When I try and run that example python script (detector):

    # detector.py
    
    from nudenet import NudeDetector
    detector = NudeDetector()
    
    # Performing detection
    detector.detect('one.jpg')
    

    it complains at this point:

    /usr/local/lib/python3.6/dist-packages/keras/engine/saving.py:292: UserWarning: No training configuration found in save file: the model was *not* compiled. Compile it manually. 
    warnings.warn('No training configuration found in save file: '
    

    Any pointers as to what might be happening here? Should I be running a specific version of tensorflow? The classify script works a treat but I cant seem to get detector to work.

    Cheers,

  • "_run.sh: line 52: 6 Illegal instruction (core dumped) python3 -u _loop.py" error on docker version of detector and classifier

    Describe the bug and error messages (if any) The docker container for the detector and classifier image never fully start.

    2020-08-15:00:56:25,236 INFO [_utils.py:129] AVAILABLE FREE MEMORY: 78120.62890625; CACHE: 3906.0314453125 MB 2020-08-15:00:56:25,474 INFO [_utils.py:129] AVAILABLE FREE MEMORY: 78120.625; CACHE: 3906.03125 MB Using TensorFlow backend. _run.sh: line 52: 6 Illegal instruction (core dumped) python3 -u _loop.py Waiting for prediction loop to begin.

    System Specs: ESXi VM, Ubuntu 18.04, 2x2.261GHz Intel Xeon L5640, 4GB RAM, GPU: svgadrmfb, Kernel: x86_64 Linux 5.4.0-42-generic

    The code snippet which gave this error* docker run -it -p8081:8080 notaitech/nudenet:classifier

    Specify versions of the following libraries Latest docker image

    Expected behavior It should work? Never exits whatever loop generates "Waiting for prediction loop to begin".

  • Upgrade tensorflow version

    Upgrade tensorflow version

    Could you please update the model and prediction codes using tensorflow 2.0+, else I'll have to install two different versions of tensorflow for my project.

  • Incompability with newest tensorflow

    Incompability with newest tensorflow

    Describe the bug and error messages (if any) I keep getting the error, that the tensorflow module, doesn't have an attribute called contrib. I believe this has to do with tensorflow pushing a new version that removes that attribute. Correct me if I'm wrong.

    Traceback:

    Traceback (most recent call last):
      File "/Users//Desktop/hallo/Code/hikari/hikaribot/src/bot.py", line 290, in handle_errors
        raise error
      File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/lightbulb/command_handler.py", line 853, in process_commands_for_event
        await self._invoke_command(command, context, positional_args, keyword_arg)
      File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/lightbulb/command_handler.py", line 789, in _invoke_command
        await command.invoke(context)
      File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/lightbulb/commands.py", line 503, in invoke
        return await self._callback(context, *new_args, **kwargs)
      File "/Users//Desktop/hallo/Code/hikari/hikaribot/src/bot.py", line 244, in nsfw
        detector = NudeDetector()
      File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/nudenet/detector.py", line 62, in __init__
        self.detection_model = tf.contrib.predictor.from_saved_model(
    AttributeError: module 'tensorflow' has no attribute 'contrib'
    

    The code snippet which gave this error*

    @bot.command()
    async def nsfw(ctx):
        attachment = ctx.message.attachments[0]
        async with attachment.stream() as resp:
            data = await resp.read()
    
        detector = NudeDetector() #stuck here
    
        print(detector.detect(data))
    

    data is of the type bytes

    Specify versions of the following libraries

    1. nudenet - 2.0.6
    2. tensorflow/ tensorflow-gpu - 2.3.1
    3. keras - not installed

    Expected behavior No errors, and the coordinates of the boxes being printed

  • Can it be used with dart , flutter?

    Can it be used with dart , flutter?

    I am a software guy and I had to make a project where people will share short short videos, and I have to make sure that no pornographic material is exchanged among users, if there's an alternative then please tell me.

  • now working in tfjs node and browser with few questions

    now working in tfjs node and browser with few questions

    fyi with few quick questions:

    i've downloaded checkpoint as noted in the detector.py and converted it to tfjs graph_format using
    tensorflowjs_converter --strip_debug_ops=* --control_flow_v2=* --quantize_float16=* saved/ f16/
    (quantized to float16 to reduce size by half)

    model works in tfjs in nodejs and browser using webgl like a charm using tfjs 2.6.0!

    few comments:

    • checkpoint is the training version and references python variables used in model definition
      any chance you can also do a compiled version?
      it should significantly help with size and speed
      i can probably do it as well, but i'd think you'd want to release compiled version for usage and only use dev version for training
    • model is very picky about input image resolution
      any thoughts on that? seems like i get best results if i resize image before inference to a range around 800-1000px
      anything smaller than 700px and it misses things badly and anything bigger than 1100px gets a lot of false positives
    • performance is pretty low compared to any other object detection model out there by 2-5x? any thoughts?
    • model is very memory hungry - it can easily eat up 2gb of gpu memory to process an image with 1k resolution
      which unfortunately quickly leads to out-of-memory situations
      due to general bad behavior of browser garbage collection of webgl objects

    this is by far the most advanced nsfw model i've seen - if it weren't for few issues (performance, memory, resolution sensitivity), it would be perfect!

  • TypeError: data type not understood

    TypeError: data type not understood

    Describe the bug and error messages (if any) https://pastebin.ubuntu.com/p/FYmNPbhrC5/

    The code snippet which gave this error

    from nudenet import NudeDetector
    
    
    detector = NudeDetector()
    print(detector.detect('./88676111_215_ed12.jpg'))
    

    Specify versions of the following libraries

    1. nudenet 2.0.3
    2. tensorflow/ tensorflow-gpu 2.3.0
    3. keras 2.4.3

    Expected behavior detecting nude image or video

  • Handle multiple input formats

    Handle multiple input formats

    This pull requests allows to handle multiple inputs for the classifier:

    • list of image paths
    • list of ndarray (opencv frames)
    • single image path
    • single ndarray (opencv frame)
  • How do you switch to onnxruntime-gpu?

    How do you switch to onnxruntime-gpu?

    With onnxruntime being used in V2, I can't seem to force it to run on a GPU by default despite it being shown. There is another support ticket that says to uninstall onnxruntime and install onnxruntime-gpu however its unclear what that means. Uninstalling with PIP breaks nudenet regardless of the onnxruntime-gpu being installed. It will throw the exception "module 'onnxruntime' has no attribute 'InferenceSession'".

    What are the steps to get onnxruntime-gpu running?

  • Segmentation fault (core dumped)  pthread_setaffinity_np failed

    Segmentation fault (core dumped) pthread_setaffinity_np failed

    I cann't run in server. My server is 8cpu 16ram testing vps in Canada. This project is fine in local. (venv) [email protected]:/home/nudeProject# python demoClassify.py Downloading the checkpoint to /root/.NudeNet/classifier_model.onnx MB100% (80.0 of 80.0) |#############################################################################################################################################| Elapsed Time: 0:00:00 Time: 0:00:00 Succefully Downloaded to: /root/.NudeNet/classifier_model.onnx Traceback (most recent call last): Segmentation fault (core dumped) (venv) [email protected]:/home/nudeProject# python demoClassify.py Traceback (most recent call last): File "demoClassify.py", line 11, in classifier = NudeClassifier() File "/home/nudeProject/venv/lib/python3.7/site-packages/nudenet/classifier.py", line 37, in init self.nsfw_model = onnxruntime.InferenceSession(model_path) File "/home/nudeProject/venv/lib/python3.7/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 283, in init self._create_inference_session(providers, provider_options, disabled_optimizers) File "/home/nudeProject/venv/lib/python3.7/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 310, in _create_inference_session sess = C.InferenceSession(session_options, self._model_path, True, self._read_config_from_model) RuntimeError: /onnxruntime_src/onnxruntime/core/platform/posix/env.cc:142 onnxruntime::{anonymous}::PosixThread::PosixThread(const char*, int, unsigned int ()(int, Eigen::ThreadPoolInterface), Eigen::ThreadPoolInterface*, const onnxruntime::ThreadOptions&) pthread_setaffinity_np failed

    Segmentation fault (core dumped) (venv) [email protected]:/home/nudeProject# ls core.45476 core.45494 demoClassify.py venv (venv) [email protected]:/home/nudeProject# ++++++++++++ tensorflow==1.15 nudenet --upgrade ubuntu 20.04.1 Code Example

    Import module

    from nudenet import NudeClassifier import imageio from PIL import Image

    initialize classifier (downloads the checkpoint file automatically the first time)

    classifier = NudeClassifier()

    A. Classify single image

    print(classifier.classify('/media/classification/sexy.jpg'))

  • Couple newbie questions

    Couple newbie questions

    I generated the windows installer - what does that actually install?

    Is there any additional documentation or examples anywhere?

    My primary use-case would be: input image -> output image with selective censorship boxes. Are there any examples that implement this already? Or will I have to implement the boxes myself since the api just returns the coordinates?

    Great project. Cheers.

PyTorch code for SENTRY: Selective Entropy Optimization via Committee Consistency for Unsupervised DA
PyTorch code for SENTRY: Selective Entropy Optimization via Committee Consistency for Unsupervised DA

PyTorch Code for SENTRY: Selective Entropy Optimization via Committee Consistency for Unsupervised Domain Adaptation Viraj Prabhu, Shivam Khare, Deeks

Oct 15, 2022
Selective Wavelet Attention Learning for Single Image Deraining

SWAL Code for Paper "Selective Wavelet Attention Learning for Single Image Deraining" Prerequisites Python 3 PyTorch Models We provide the models trai

Jun 17, 2022
Modeling Category-Selective Cortical Regions with Topographic Variational Autoencoders

Modeling Category-Selective Cortical Regions with Topographic Variational Autoencoders

Oct 11, 2021
Create animations for the optimization trajectory of neural nets
Create animations for the optimization trajectory of neural nets

Animating the Optimization Trajectory of Neural Nets loss-landscape-anim lets you create animated optimization path in a 2D slice of the loss landscap

Nov 28, 2022
Code for visualizing the loss landscape of neural nets
Code for visualizing the loss landscape of neural nets

Visualizing the Loss Landscape of Neural Nets This repository contains the PyTorch code for the paper Hao Li, Zheng Xu, Gavin Taylor, Christoph Studer

Nov 26, 2022
Nov 14, 2022
SMD-Nets: Stereo Mixture Density Networks
SMD-Nets: Stereo Mixture Density Networks

SMD-Nets: Stereo Mixture Density Networks This repository contains a Pytorch implementation of "SMD-Nets: Stereo Mixture Density Networks" (CVPR 2021)

Oct 28, 2022
Companion code for the paper "An Infinite-Feature Extension for Bayesian ReLU Nets That Fixes Their Asymptotic Overconfidence" (NeurIPS 2021)

ReLU-GP Residual (RGPR) This repository contains code for reproducing the following NeurIPS 2021 paper: @inproceedings{kristiadi2021infinite, title=

Dec 26, 2021
[NeurIPS 2021] Well-tuned Simple Nets Excel on Tabular Datasets
[NeurIPS 2021] Well-tuned Simple Nets Excel on Tabular Datasets

[NeurIPS 2021] Well-tuned Simple Nets Excel on Tabular Datasets Introduction This repo contains the source code accompanying the paper: Well-tuned Sim

Nov 14, 2022
Real-CUGAN - Real Cascade U-Nets for Anime Image Super Resolution

Real Cascade U-Nets for Anime Image Super Resolution 中文 | English ?? Real-CUGAN

Nov 26, 2022
Implement face detection, and age and gender classification, and emotion classification.
Implement face detection, and age and gender classification, and emotion classification.

YOLO Keras Face Detection Implement Face detection, and Age and Gender Classification, and Emotion Classification. (image from wider face dataset) Ove

Nov 14, 2022
This repository contains notebook implementations of the following Neural Process variants: Conditional Neural Processes (CNPs), Neural Processes (NPs), Attentive Neural Processes (ANPs).

The Neural Process Family This repository contains notebook implementations of the following Neural Process variants: Conditional Neural Processes (CN

Dec 2, 2022
Image Classification - A research on image classification and auto insurance claim prediction, a systematic experiments on modeling techniques and approaches

A research on image classification and auto insurance claim prediction, a systematic experiments on modeling techniques and approaches

Jan 23, 2022
Simple-Image-Classification - Simple Image Classification Code (PyTorch)
Simple-Image-Classification - Simple Image Classification Code (PyTorch)

Simple-Image-Classification Simple Image Classification Code (PyTorch) Yechan Kim This repository contains: Python3 / Pytorch code for multi-class ima

Oct 29, 2022
Hl classification bc - A Network-Based High-Level Data Classification Algorithm Using Betweenness Centrality
Hl classification bc - A Network-Based High-Level Data Classification Algorithm Using Betweenness Centrality

A Network-Based High-Level Data Classification Algorithm Using Betweenness Centr

Mar 13, 2022
Cancer-and-Tumor-Detection-Using-Inception-model - In this repo i am gonna show you how i did cancer/tumor detection in lungs using deep neural networks, specifically here the Inception model by google.
Cancer-and-Tumor-Detection-Using-Inception-model - In this repo i am gonna show you how i did cancer/tumor detection in lungs using deep neural networks, specifically here the Inception model by google.

Cancer-and-Tumor-Detection-Using-Inception-model In this repo i am gonna show you how i did cancer/tumor detection in lungs using deep neural networks

Jan 1, 2022
For holding anime-related object classification and detection models

Animesion An end-to-end framework for anime-related object classification, detection, segmentation, and other models. Update: 01/22/2020. Due to time-

Nov 30, 2022
Aerial Imagery dataset for fire detection: classification and segmentation (Unmanned Aerial Vehicle (UAV))
Aerial Imagery dataset for fire detection: classification and segmentation (Unmanned Aerial Vehicle (UAV))

Aerial Imagery dataset for fire detection: classification and segmentation using Unmanned Aerial Vehicle (UAV) Title FLAME (Fire Luminosity Airborne-b

Nov 29, 2022