Inference Providers documentation
Image Classification
Get Started
Guides
Your First API CallBuilding Your First AI AppStructured Outputs with LLMsFunction CallingResponses API (beta)How to use OpenAI gpt-ossBuild an Image EditorAutomating Code Review with GitHub ActionsAgentic Coding Environments with OpenEnvEvaluating Models with Inspect
Integrations
OverviewAdd Your IntegrationClaude CodeHermes AgentNeMo Data DesignerMacWhisperOpenCodePiVision AgentsVS Code with GitHub Copilot
Inference Tasks
Providers
CerebrasCohereDeepInfraFal AIFeatherless AIFireworksGroqHyperbolicHF InferenceNovitaNscaleOVHcloud AI EndpointsPublic AIReplicateSambaNovaScalewayTogetherWaveSpeedAIZ.ai
Hub APIRegister as an Inference ProviderImage Classification
Image classification is the task of assigning a label or class to an entire image. Images are expected to have only one class for each image.
For more details about the
image-classificationtask, check out its dedicated page! You will find examples and related materials.
Recommended models
- google/vit-base-patch16-224: A strong image classification model.
- facebook/deit-base-distilled-patch16-224: A robust image classification model.
Explore all available models and find the one that suits you best here.
Using the API
Language
Client
Provider
Copied
import os
from huggingface_hub import InferenceClient
client = InferenceClient(
provider="hf-inference",
api_key=os.environ["HF_TOKEN"],
)
output = client.image_classification("cats.jpg", model="Falconsai/nsfw_image_detection")API specification
Request
| Headers | ||
|---|---|---|
| authorization | string | Authentication header in the form 'Bearer: hf_****' when hf_**** is a personal user access token with “Inference Providers” permission. You can generate one from your settings page. |
| Payload | ||
|---|---|---|
| inputs* | string | The input image data as a base64-encoded string. If no parameters are provided, you can also provide the image data as a raw bytes payload. |
| parameters | object | |
| function_to_apply | enum | Possible values: sigmoid, softmax, none. |
| top_k | integer | When specified, limits the output to the top K most probable classes. |
Response
| Body | ||
|---|---|---|
| (array) | object[] | Output is an array of objects. |
| label | string | The predicted class label. |
| score | number | The corresponding probability. |