Nudity detection through deep learning
Project description
Overview
newd analyzes images and identifies specific NSFW body parts with high accuracy. It can also optionally censor detected areas.
Installation
pip install newd
Usage
Basic Detection
from newd import detect
# Standard detection with default settings
results = detect('path/to/image.jpg')
print(results)
Advanced Options
# Faster detection with slightly reduced accuracy
results = detect('image.jpg', mode="fast")
# Adjust detection sensitivity
results = detect('image.jpg', min_prob=0.3) # Lower threshold catches more potential matches
# Combine options
results = detect('image.jpg', mode="fast", min_prob=0.3)
Compatible Input Types
The detect() function accepts:
- String file paths
- Images loaded with OpenCV (
cv2) - Images loaded with PIL/Pillow
Output Format
Detection results are returned as a list of dictionaries:
[
{
'box': [x1, y1, x2, y2], # Bounding box coordinates (top-left, bottom-right)
'score': 0.825, # Confidence score (0-1)
'label': 'EXPOSED_BREAST_F' # Classification label
},
# Additional detections...
]
First-Time Use
When importing newd for the first time, it will download a 139MB model file to your home directory (~/.newd/). This happens only once.
Performance Notes
- Standard mode: Best accuracy, normal processing speed
- Fast mode: ~3x faster processing with slightly reduced accuracy
Censoring / Redacting Detected Regions
newd.censor() masks detected NSFW regions with solid black rectangles. Use it when you need to create a safe-for-work version of an image.
from newd import censor
# Censor all detected areas and write the result
censored_img = censor(
'image.jpg',
out_path='image_censored.jpg' # file will be written to disk
)
# Only censor specific labels (e.g. exposed anus & male genitals)
selected_parts = ['EXPOSED_ANUS_F', 'EXPOSED_GENITALIA_M']
censored_img = censor(
'image.jpg',
out_path='image_censored.jpg',
parts_to_blur=selected_parts
)
Function parameters:
| Parameter | Type | Description |
|---|---|---|
img_path |
str / Path | Source image or path. |
out_path |
str / Path, optional | Destination path; if omitted you can still obtain the result via the return value when visualize=True. |
visualize |
bool, default False |
If True, the censored numpy.ndarray image is returned for display (cv2.imshow, etc.). |
parts_to_blur |
List[str], optional | Restrict censoring to given label names. When empty, all detected labels are censored. |
If neither out_path nor visualize=True is supplied, the function exits early because there is nowhere to deliver the censored image.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file newd-0.0.4.tar.gz.
File metadata
- Download URL: newd-0.0.4.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba1e696a8bc3fcf1167dd708ddcfa3dffb0db787872a37e5ba363140dcd187c5
|
|
| MD5 |
033e213cac86c53b453e4aff223a43bd
|
|
| BLAKE2b-256 |
b0607ea26d2c182dea8f5c5ac91db47101ad75e39d226a1e233e30320bb7fa90
|
File details
Details for the file newd-0.0.4-py2.py3-none-any.whl.
File metadata
- Download URL: newd-0.0.4-py2.py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb4c8b5633f980a9a3afdf0a47094d57aacb097b0b822b9cb548c8f7693fc215
|
|
| MD5 |
2a8ddffa4406605def0f6d26dce3094a
|
|
| BLAKE2b-256 |
6a378de45697a77827bcd96c886a0013c0a38a5967ce5aa0ed0261e685806652
|