NSFW Filter
The NSFW (Not Safe For Work) Filter detects the likelihood that an image contains explicit or unsafe content. It outputs a probability score from 0 (safe) to 1 (NSFW), helping you filter or flag images in your datasets.
Model Details
- Architecture: MLP trained on CLIP ViT-L/14 image embeddings
- Source: CLIP-based NSFW Detector
- Output Field:
nsfw_score - Score Range: 0–1 (higher scores show NSFW content)
- Embeddings: Requires CLIP ViT-L/14 (see Image embeddings)
How It Works
The filter takes pre-computed normalized image embeddings from a previous pipeline stage and predicts the probability of NSFW content. The lightweight model processes batches of embeddings efficiently on the GPU.
Prerequisites
Before using the ImageNSFWFilterStage, ensure you have:
Model Setup
The NSFW detector model weights are automatically downloaded from the LAION repository on first use. The stage will:
- Download the CLIP-based NSFW detector model (~20MB) to the specified
model_dir - Cache the model for subsequent runs
- Load the model onto GPU (or CPU if GPU unavailable)
First-time setup: The initial model download is quick (under 1 minute on most connections). Subsequent runs will use the cached model.
Required Input
- CLIP Embeddings: Images must have embeddings already generated by
ImageEmbeddingStage - Embedding Format: CLIP ViT-L/14 768-dimensional vectors stored in
ImageObject.embedding
Usage
Python
Parameters
Performance Notes
- The small model processes pre-computed embeddings efficiently on the GPU.
- Increase batch size for faster throughput if memory allows.
Best Practices
- Use CLIP ViT-L/14 embeddings generated by
ImageEmbeddingStagefor best results. - Run the NSFW filter after embedding generation in the same pipeline to avoid extra I/O.
- The filter requires pre-computed embeddings and cannot extract embeddings from raw images.
- Review a sample of scores to calibrate thresholds for your use case.
- Adjust
model_inference_batch_sizebased on available GPU memory.