Views
No views yet
Marqo/nsfw-image-detection-384 is a lightweight image classification model designed to identify NSFW images. The model is approximately 18–20x smaller than other open-source models and achieves a superior accuracy of 98.56% on our dataset. This model uses 384x384 pixel images for the input with 16x16 pixel patches.pip install timm1from urllib.request import urlopen
2from PIL import Image
3import timm
4import torch
5
6img = Image.open(urlopen(
7 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
8))
9
10model = timm.create_model("hf_hub:Marqo/nsfw-image-detection-384", pretrained=True)
11model = model.eval()
12
13data_config = timm.data.resolve_model_data_config(model)
14transforms = timm.data.create_transform(**data_config, is_training=False)
15
16with torch.no_grad():
17 output = model(transforms(img).unsqueeze(0)).softmax(dim=-1).cpu()
18
19class_names = model.pretrained_cfg["label_names"]
20print("Probabilities:", output[0])
21print("Class:", class_names[output[0].argmax()])


1batch_size: 256
2color_jitter: 0.2
3color_jitter_prob: 0.05
4cutmix: 0.1
5drop: 0.1
6drop_path: 0.05
7epoch_repeats: 0.0
8epochs: 20
9gaussian_blur_prob: 0.005
10hflip: 0.5
11lr: 5.0e-05
12mixup: 0.1
13mixup_mode: batch
14mixup_prob: 1.0
15mixup_switch_prob: 0.5
16momentum: 0.9
17num_classes: 2
18opt: adamw
19remode: pixel
20reprob: 0.5
21sched: cosine
22smoothing: 0.1
23warmup_epochs: 2
24warmup_lr: 1.0e-05
25warmup_prefix: false@article{dosovitskiy2020vit,
title={An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale},
author={Dosovitskiy, Alexey and Beyer, Lucas and Kolesnikov, Alexander and Weissenborn, Dirk and Zhai, Xiaohua and Unterthiner, Thomas and Dehghani, Mostafa and Minderer, Matthias and Heigold, Georg and Gelly, Sylvain and Uszkoreit, Jakob and Houlsby, Neil},
journal={ICLR},
year={2021}
}@misc{rw2019timm,
author = {Ross Wightman},
title = {PyTorch Image Models},
year = {2019},
publisher = {GitHub},
journal = {GitHub repository},
doi = {10.5281/zenodo.4414861},
howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
}