/DeepNipple

State-of-the-art nipple detection algorithm and dataset ⚙️

Primary LanguagePython

Official DeepNipple Algorithm

python fastai torch opencv

DeepNipple is an algorithm that detects the areola and nipple with very high precision. The core is a convolutional neural network that solves a typical AI segmentation problem. This novel dataset and algorithm are the state-of-the-art in nipple detection and can be used for real-world applications such as criminal identification.

I am sure that github's community can take the best from this repo, and inspire other creative tools.

Table of contents

How does DeepNipple work?

DeepNipple innovates in nipple detection by rethinking the problem as a segmentation problem comprising of two categories: areola and nipple. It is also possible to extract the areola and nipple in a bounding box as if it was an object detection problem.

DeepNipple dataset is composed of 1,000 images of more than 200 subjects with their areola and nipple segmentation masks. The figure below shows an example of an image and its areola and nipple masks, which in the dataset come as a single mask with pixel value 0 for background, 1 for areola and 2 for nipple. The example is not an original image of the dataset to avoid problems with NSFW content.

Dataset will be available soon.

Other datasets

NTU-Nipple-v1 dataset, used in The Nipple-Areola Complex for Criminal Identification, contains 2732 images from 428 different nipple-areola complexes (NAC) but they only provide a bounding box.

Method

Segmentation

The U-Net is convolutional network architecture for fast and precise segmentation of images. Up to now it has outperformed the prior best method (a sliding-window convolutional network) on the ISBI challenge for segmentation of neuronal structures in electron microscopic stacks. It is possible to use different base networks within a unet, like the different versions of ResNet.

Seg2bbox

Seg2bbox consist in converting output mask pixel values into bounding boxes. This is done by applying a contour finder to obtain x1, x2, y1 and y2 points. The figure below shows a segmentation mask with the calculated bounding box for each blob.

Running DeepNipple

Download PyTorch weights for Resnet34 and place them in the directory base-model.

├── 📁 DeepNipple
│   |
│   ├── 📁 utils
│   │   ├── 📁 advanced-model
│   │   ├── 📁 base-model
│   |   |   ├── export.pkl

Then run the following command in the terminal:

$ python base_deepnipple.py --mode seg --img_path PATH --show True

Performance

Base algorithm 🔓

This algorithm is public. It has been trained only on 138 images, validated on 34 images and tested on 19 images so metrics are not supported by a proper size and diversified subset.

Segmentation

Model Categories Metrics
Precision (%) Recall (%)
F1 (%)
Resnet34 Background 99.36 ± 0.01 99.84 ± 0.02 99.59 ± 0.00
Areola 68.48 ± 26.14 50.65 ± 31.20 53.67 ± 27.98
Nipple 46.38 ± 34.45 40.67 ± 35.00 38.63 ± 29.60

The model finds quite good the NAC but it varies a lot from image to image. It performs quite badly in images where the nipple is too far and covers only XXX a few pixels. Surprisingly, even if in those images segmentation is not that good, it finds something. As we see, standard deviation is very high, because some images get over 90% in some metrics while others get close to 0%. We find the following outputs:

  • NAC is detected with success
  • NAC is partially detected
  • Not a single NAC pixel detected
  • False positive

Detection

Detection has been reduced to the simple binary problem of finding if there is at least one nipple in the image.

Model Category Metrics
Sensitivity (%) Specificity (%)
Resnet34 NAC 88.24 85.00

Advanced algorithm 🔒

This algorithm is trained on 70% of the data, validated on 20% and tested on 10%. Is is still to be tested. Results will be released soon.

Segmentation

Model Categories Metrics
Precision (%) Recall (%)
F1 (%)
Resnet34 Background - - -
Areola - - -
Nipple - - -
Resnet101 Background - - -
Areola - - -
Nipple - - -

Detection

Model Category Metrics
Sensitivity (%) Specificity (%)
Resnet34 NAC - -
Resnet101 NAC - -

Applications

DeepNippleID 💻

DeepNippleID is a nipple identification algorithm under development. Identifiying a person has many interesting applications like finding criminals and this is typically done by face recognition. However, sexual offenders do not normally show their face in the videos. Identifying people by finding similarity in the nipples could be useful. Wojciech et al. conclude that "the experimental results indicate that the NAC can be a useful characteristic for forensic applications".

Nipple censor 🔒

This application uses nipple detection to find nipples and censor the images by applying blur, emoji or other type of modification.

Obscene content idetification 🔒

This application uses nipple detection to find nipples in videos or a large batch of images and finds NSFW content. It can be used as a filtering tool.

Previous work

There is not much research on this area. I will list some of the papers I found:

There is an Android App that apparently uses object detection to locate nipples.

Donations ₿

BTC Wallet: 1DswCAGmXYQ4u2EWVJWitySM7Xo7SH4Wdf

Contact

✉️ | 🔗 | 🕸