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

Overview

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
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!

    question 
    opened by Kurumi-chan 16
  • 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

    Support TF new versions 
    opened by UnifySoftTech 15
  • 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!

    Support TF new versions 
    opened by matthewgdv 11
  • 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,

    not a bug 
    opened by barezina 11
  • "_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".

    docker-image-issue 
    opened by MyAltGitHubAccount 10
  • 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.

    enhancement 
    opened by aayushbhaskar 10
  • 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

    Support TF new versions 
    opened by YodaPY 7
  • 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.

    not a bug 
    opened by JackTheProgrammer 7
  • 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!

    enhancement 
    opened by vladmandic 7
  • 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

    Support TF new versions 
    opened by foozzi 6
  • 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)
    opened by padmalcom 5
  • 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?

    opened by rmills 2
  • 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'))

    opened by htoohtoowai 0
  • 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.

    opened by madstacksofcash 1
Owner
notAI.tech
Open Source initiative by a group of bored engineers.
notAI.tech
fastgradio is a python library to quickly build and share gradio interfaces of your trained fastai models.

fastgradio is a python library to quickly build and share gradio interfaces of your trained fastai models.

Ali Abdalla 34 Jan 05, 2023
Code for the paper: On Pathologies in KL-Regularized Reinforcement Learning from Expert Demonstrations

Non-Parametric Prior Actor-Critic (N-PPAC) This repository contains the code for On Pathologies in KL-Regularized Reinforcement Learning from Expert D

Cong Lu 5 May 13, 2022
Framework to build and train RL algorithms

RayLink RayLink is a RL framework used to build and train RL algorithms. RayLink was used to build a RL framework, and tested in a large-scale multi-a

Bytedance Inc. 32 Oct 07, 2022
EgoNN: Egocentric Neural Network for Point Cloud Based 6DoF Relocalization at the City Scale

EgonNN: Egocentric Neural Network for Point Cloud Based 6DoF Relocalization at the City Scale Paper: EgoNN: Egocentric Neural Network for Point Cloud

19 Sep 20, 2022
AugMix: A Simple Data Processing Method to Improve Robustness and Uncertainty

AugMix Introduction We propose AugMix, a data processing technique that mixes augmented images and enforces consistent embeddings of the augmented ima

Google Research 876 Dec 17, 2022
Pytorch implementation of "Forward Thinking: Building and Training Neural Networks One Layer at a Time"

forward-thinking-pytorch Pytorch implementation of Forward Thinking: Building and Training Neural Networks One Layer at a Time Requirements Python 2.7

Kim Heecheol 65 Oct 06, 2022
Syntax-Aware Action Targeting for Video Captioning

Syntax-Aware Action Targeting for Video Captioning Code for SAAT from "Syntax-Aware Action Targeting for Video Captioning" (Accepted to CVPR 2020). Th

59 Oct 13, 2022
TransGAN: Two Transformers Can Make One Strong GAN

[Preprint] "TransGAN: Two Transformers Can Make One Strong GAN", Yifan Jiang, Shiyu Chang, Zhangyang Wang

VITA 1.5k Jan 07, 2023
(CVPR2021) Kaleido-BERT: Vision-Language Pre-training on Fashion Domain

Kaleido-BERT: Vision-Language Pre-training on Fashion Domain Mingchen Zhuge*, Dehong Gao*, Deng-Ping Fan#, Linbo Jin, Ben Chen, Haoming Zhou, Minghui

248 Dec 04, 2022
Code of the paper "Part Detector Discovery in Deep Convolutional Neural Networks" by Marcel Simon, Erik Rodner and Joachim Denzler

Part Detector Discovery This is the code used in our paper "Part Detector Discovery in Deep Convolutional Neural Networks" by Marcel Simon, Erik Rodne

Computer Vision Group Jena 17 Feb 22, 2022
ECLARE: Extreme Classification with Label Graph Correlations

ECLARE ECLARE: Extreme Classification with Label Graph Correlations @InProceedings{Mittal21b, author = "Mittal, A. and Sachdeva, N. and Agrawal

Extreme Classification 35 Nov 06, 2022
A keras-based real-time model for medical image segmentation (CFPNet-M)

CFPNet-M: A Light-Weight Encoder-Decoder Based Network for Multimodal Biomedical Image Real-Time Segmentation This repository contains the implementat

268 Nov 27, 2022
Implementation of OpenAI paper with Simple Noise Scale on Fastai V2

README Implementation of OpenAI paper "An Empirical Model of Large-Batch Training" for Fastai V2. The code is based on the batch size finder implement

13 Dec 10, 2021
Open-source codebase for EfficientZero, from "Mastering Atari Games with Limited Data" at NeurIPS 2021.

EfficientZero (NeurIPS 2021) Open-source codebase for EfficientZero, from "Mastering Atari Games with Limited Data" at NeurIPS 2021. Thank you for you

Weirui Ye 671 Jan 03, 2023
A plug-and-play library for neural networks written in Python

A plug-and-play library for neural networks written in Python!

Dimos Michailidis 2 Jul 16, 2022
Meandering In Networks of Entities to Reach Verisimilar Answers

MINERVA Meandering In Networks of Entities to Reach Verisimilar Answers Code and models for the paper Go for a Walk and Arrive at the Answer - Reasoni

Shehzaad Dhuliawala 271 Dec 13, 2022
SimDeblur is a simple framework for image and video deblurring, implemented by PyTorch

SimDeblur (Simple Deblurring) is an open source framework for image and video deblurring toolbox based on PyTorch, which contains most deep-learning based state-of-the-art deblurring algorithms. It i

220 Jan 07, 2023
Baseline powergrid model for NY

Baseline-powergrid-model-for-NY Table of Contents About The Project Built With Usage License Contact Acknowledgements About The Project As the urgency

Anderson Energy Lab at Cornell 6 Nov 24, 2022
The implementation of 'Image synthesis via semantic composition'.

Image synthesis via semantic synthesis [Project Page] by Yi Wang, Lu Qi, Ying-Cong Chen, Xiangyu Zhang, Jiaya Jia. Introduction This repository gives

DV Lab 71 Jan 06, 2023
Official code for "Stereo Waterdrop Removal with Row-wise Dilated Attention (IROS2021)"

Stereo-Waterdrop-Removal-with-Row-wise-Dilated-Attention This repository includes official codes for "Stereo Waterdrop Removal with Row-wise Dilated A

29 Oct 01, 2022