This model is a fine-tuned version of
vit-base-patch16-384
on ~1.7M generated images from the
AdamCodd/Civitai-8m-prompts
dataset, balanced between NSFW/SFW labels.
It achieves the following results on the evaluation set:
The Vision Transformer (ViT) is a transformer encoder model (BERT-like) pretrained on a large collection of images in a supervised fashion, namely ImageNet-21k, at a resolution of 224x224 pixels. Next, the model was fine-tuned on ImageNet (also referred to as ILSVRC2012), a dataset comprising 1 million images and 1,000 classes, at a higher resolution of 384x384.
Intended uses & limitations
Usage for a local image:
from transformers import pipeline
from PIL import Image
img = Image.open("<path_to_image_file>")
predict = pipeline('image-classification', model='AdamCodd/vit-nsfw-stable-diffusion')
predict(img)
/* Instructions:* - Place this script in an HTML file using the <script type="module"> tag.* - Ensure the HTML file is served over a local or remote server (e.g., using Python's http.server, Node.js server, or similar).* - Replace 'https://example.com/path/to/image.jpg' in the classifyImage function call with the URL of the image you want to classify.** Example of how to include this script in HTML:* <script type="module" src="path/to/this_script.js"></script>** This setup ensures that the script can use imports and perform network requests without CORS issues.*/import { pipeline, env } from'https://cdn.jsdelivr.net/npm/@xenova/[email protected]';
// Since we will download the model from HuggingFace Hub, we can skip the local model check
env.allowLocalModels = false;
// Load the image classification modelconst classifier = awaitpipeline('image-classification', 'AdamCodd/vit-nsfw-stable-diffusion');
// Function to fetch and classify an image from a URLasyncfunctionclassifyImage(url) {
try {
const response = awaitfetch(url);
if (!response.ok) thrownewError('Failed to load image');
const blob = await response.blob();
const image = newImage();
const imagePromise = newPromise((resolve, reject) => {
image.onload = () =>resolve(image);
image.onerror = reject;
image.src = URL.createObjectURL(blob);
});
const img = await imagePromise; // Ensure the image is loadedconst classificationResults = awaitclassifier([img.src]); // Classify the imageconsole.log('Predicted class: ', classificationResults[0].label);
} catch (error) {
console.error('Error classifying image:', error);
}
}
// Example usageclassifyImage('https://example.com/path/to/image.jpg');
// Predicted class: sfw
Since this model has been trained on generated images from stable diffusion, it won't perform as well on real pictures (in that case just use my other ViT model).
I would like to express my sincere gratitude to Prodia.com for generously providing the GPU resources, specifically the RTX 4090, that made the training of this model possible.
Runs of AdamCodd vit-nsfw-stable-diffusion on huggingface.co
0
Total runs
0
24-hour runs
0
3-day runs
0
7-day runs
0
30-day runs
More Information About vit-nsfw-stable-diffusion huggingface.co Model
More vit-nsfw-stable-diffusion license Visit here:
vit-nsfw-stable-diffusion huggingface.co is an AI model on huggingface.co that provides vit-nsfw-stable-diffusion's model effect (), which can be used instantly with this AdamCodd vit-nsfw-stable-diffusion model. huggingface.co supports a free trial of the vit-nsfw-stable-diffusion model, and also provides paid use of the vit-nsfw-stable-diffusion. Support call vit-nsfw-stable-diffusion model through api, including Node.js, Python, http.
vit-nsfw-stable-diffusion huggingface.co is an online trial and call api platform, which integrates vit-nsfw-stable-diffusion's modeling effects, including api services, and provides a free online trial of vit-nsfw-stable-diffusion, you can try vit-nsfw-stable-diffusion online for free by clicking the link below.
AdamCodd vit-nsfw-stable-diffusion online free url in huggingface.co:
vit-nsfw-stable-diffusion is an open source model from GitHub that offers a free installation service, and any user can find vit-nsfw-stable-diffusion on GitHub to install. At the same time, huggingface.co provides the effect of vit-nsfw-stable-diffusion install, users can directly use vit-nsfw-stable-diffusion installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
vit-nsfw-stable-diffusion install url in huggingface.co: