Falconsai NSFW ViT
Falconsai's NSFW detector: a ViT-B/16 that classifies an image as normal or nsfw. Apache-2.0 weights.
stable Fork of https://huggingface.co/Falconsai/nsfw_image_detection@96cb0d0 · backends: portable, kernels
- Paper Falconsai/nsfw_image_detection Model card · first released 13 Oct 2023
Checkpoint falconsai-nsfw-vit
Paper 2023 Added in 0.2.0
Use it
pip install fastforks Lean install with only what this model needs: pip install "fastforks-core[timm]"
from fastforks import classification
model = classification.load("falconsai-nsfw-vit") # kernels on a supported GPU, else portable PyTorch
result = model(image)
result.logits
result.backend # what ran: mode, device, dtype, kernels fastforks bench falconsai-nsfw-vit Times the model on this machine. load(…, mode="portable") or mode="kernels" picks a backend; usage guide.
Speed and memory
Every backend on one GPU (RTX 5060 Ti 16 GB) and the same input, the authors’ code included. Kernels runs fp16. Portable runs fp16 on CUDA.
Input: synthetic, 224x224 (the task’s standard size)
| Backend | dtype | Time per call (ms) | vs original fp16 | Peak memory allocated / reserved | Load (s) | First call (s) |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | 6.76 | 0.85× | 367 MiB/388 MiB | 3.4 | 0.23 |
| Original fp16.half() on 1 modules, fp16 inputs | fp16 | 5.74 | – | 200 MiB/226 MiB | 3.0 | 0.27 |
| Portable fp32 | fp32 | not measured | – | – | – | – |
| Portable | fp16 | 2.83 | 2.0× | 201 MiB/226 MiB | 1.8 | 0.09 |
| Kernels | fp16 | 1.61 | 3.6× | 198 MiB/228 MiB | 2.4 | 0.06 |
| Portable + torch.compile | 2.02 | 2.8× | 236 MiB/266 MiB | 8 (build) | – | |
| TensorRT fp16 | fp16 | 1.12 | 5.1× | 196 MiBenginenot comparable | 27 (build) | – |
Measured on RTX 5060 Ti 16 GB, torch 2.14.1+cu130, 2026-11-13 to 2026-11-16. First call, 3 warm-up, peak reset, median of 3 rounds x median of 5. Ratios divide two
times of this table (same GPU, same input). Original fp16 is the authors’ own precision option, else torch.autocast. torch.compile and TensorRT: build time instead of load time. TensorRT memory (engine, not comparable) is the GPU memory the engine took, read from the driver because TensorRT allocates outside PyTorch, so it can't be compared with the PyTorch peaks of the other rows.
Other devices
| Device | Backend | dtype | ms / call | Peak memory | Output vs reference | Input |
|---|---|---|---|---|---|---|
| Apple M1 Pro 16 GB MPS, torch 2.14.1, 2026-11-14 | Original | fp32 | 18.8 | 1,121 MiB process | – | 224x224 |
| Portable | fp16 | 15.9 | 1,244 MiB process | matches | 224x224 | |
| Portable | fp32 | 17.0 | 1,084 MiB process | matches | 224x224 | |
| Kernels | fp16 | not implemented | – | 224x224 | ||
CUDA memory is torch’s peak allocated / reserved; Apple has no such counter, so the Mac rows show the process footprint (weights, Python and torch included). “Output vs reference” compares the device’s output with the stored golden output under the card’s tolerance; – = not checked on that device. Kernels “not implemented” = no kernels for this model on that backend yet: it runs portable there.
Licence and weights
Commercial use allowed
- Code
- Apache-2.0
- Weights
- Apache-2.0 source
- Training data
-
- ImageNet-21k / ImageNet-22k (full ImageNet, fall 2011 release) noncommercial, non-commercial
- Falconsai proprietary NSFW data (about 80 000 images, normal / nsfw) not stated
Our reading of the licences, not legal advice.
Weights
falconsai-nsfw-vit.safetensors 343 MB· hosted on Hugging Facefastforks downloads and checks these files on first use (fastforks download falconsai-nsfw-vit).
Accuracy
The test set through the authors’ code and through ours: same checkpoint, same protocol. The distance between the original’s fp32 and fp16 runs is what half precision alone costs; our runs should stay within it.
Accuracy not measured for falconsai-nsfw-vit.
Closeness to the original
Beyond the test-set scores: the raw output of ours against the original’s fp32 output on the same input, pixel by pixel. CPU, float32: max |diff| <= 1e-05 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.009 and p99 <= 0.011 (absolute error of the output logits).
| Check | Tolerance | Measured |
|---|---|---|
| CPU fp32, max |diff| | ≤ 0.00001 | not recorded |
| GPU default dtypes, mean |diff| | ≤ 0.009 | 0.00599 |
| GPU default dtypes, p99 |diff| | ≤ 0.011 | 0.00719 |
Recorded for falconsai-nsfw-vit on RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-13, with these kernels: cudnn_haccfvm_convfvm_extrafvm_mbfvm_r3
Details
Falconsai's NSFW image detector: ViT-B/16 (ImageNet-21k pretrained) fine-tuned on about 80 000 images, classes normal / nsfw.
- Input / output
- Input: one RGB image. Output: ImageNet-1k class logits.
- Input size
- fixed 224x224: the input is resized (short side 224) and centre-cropped to it; tested up to 224x224 (211 MiB allocated)
- Outputs
logits- CUDA kernels
cudnn_haccconvolutions with fp16 accumulation (cuDNN)fvm_convfused convolutions for image classifiersfvm_extrafused transformer row operations (rotary split, SwiGLU with LayerNorm)fvm_mbfused MBConv blocks (MobileNet and EfficientNet families)fvm_r3further fused classifier blocks
- Apple (MPS)
- fp32, fp16
Limitations
- No accuracy measurement: the weights' training set (Falconsai's private labelled NSFW images) is not published and no public labelled NSFW test set is part of the evaluation data here; tiers are compared by output parity and speed only.
- The image is stretched to 224 x 224 without keeping its aspect ratio, as the original processor does.
Full reference, generated from the repository
Falconsai's NSFW detector: a ViT-B/16 that classifies an image as normal or nsfw. Apache-2.0 weights.
Commercial use: yes.
| variant | input | backend | time (ms) | peak memory (MiB, allocated / reserved) |
|---|---|---|---|---|
falconsai-nsfw-vit | synthetic (224x224) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 6.76 5.74 2.83 1.61 2.02 1.12 | 367 / 388 200 / 226 201 / 226 198 / 228 236 / 266 393 / 420 |
Details
- Original code: https://huggingface.co/Falconsai/nsfw_image_detection at
96cb0d0342c7 - Code licence: Apache-2.0 (permissive); files:
- Weights licence: Apache-2.0
- Licence evidence: https://huggingface.co/Falconsai/nsfw_image_detection/blob/96cb0d0342c7afb80cab76ecc58b265fa44da256/README.md
- Training data: ImageNet-21k / ImageNet-22k (full ImageNet, fall 2011 release), Falconsai proprietary NSFW data (about 80 000 images, normal / nsfw)
- Kernel libraries:
cudnn_hacc,fvm_conv,fvm_extra,fvm_mb,fvm_r3 - Variants:
falconsai-nsfw-vit - Outputs: logits; label_set:
nsfw-2 - Input size: fixed 224x224: the input is resized (short side 224) and centre-cropped to it
- Tested up to (portable, fp16, RTX 5060 Ti 16 GB):
falconsai-nsfw-vit224x224 (0.2 GiB peak allocated, 0.3 reserved) falconsai-nsfw-vit224x224, first call: portable + torch.compile 8 s (cold Inductor cache), TensorRT fp16 27 s (ONNX + engine).falconsai-nsfw-vitoriginal 224x224: .half() on 1 modules, fp16 inputsfalconsai-nsfw-vitload / first call: original 2.95 s / 0.273 s, portable 2.63 s / 0.094 s, kernels 2.42 s / 0.085 s- Protocol, first call, 3 warm-up, peak reset, median of 3 rounds x median of 5
Parity
CPU, float32: max |diff| <= 1e-05 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.009 and p99 <= 0.011 (absolute error of the output logits).
| variant | kernels error vs original, mean / p99 | GPU, torch | kernels used |
|---|---|---|---|
falconsai-nsfw-vit | 0.00599 / 0.00719 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400, fvm_conv@f1d064e539e1:sm_120, fvm_extra@3208ce525a91:sm_120, fvm_mb@720dd3f29bf7:sm_120, fvm_r3@f54eb890e23c:sm_120 |
Limitations
- No accuracy measurement: the weights' training set (Falconsai's private labelled NSFW images) is not published and no public labelled NSFW test set is part of the evaluation data here; tiers are compared by output parity and speed only.
- The image is stretched to 224 x 224 without keeping its aspect ratio, as the original processor does.
Example output
One fixed input through this checkpoint, the same for every model of the task (kernels · float16 · NVIDIA GeForce RTX 5060 Ti).
Top 5
Input: Chelsea the cat, Stéfan van der Walt (CC0).