ViT

Run ViT classification models trained on Roboflow via the Serverless Hosted API

Use Vision Transformer (ViT) classification models trained on Roboflow through the Serverless Hosted API. There are no public ViT aliases; you train your own ViT classifier on your dataset and call it by your {project_id}/{version}.

Code sample

Install the SDK:

pip install inference-sdk

Pass your Roboflow API Key via the API_KEY env variable, and replace your-project/1 with your own project ID and version.

import os
import urllib.request
from inference_sdk import InferenceHTTPClient

image_url = "https://media.roboflow.com/notebooks/examples/dog.jpeg"
image_path = "dog.jpeg"
urllib.request.urlretrieve(image_url, image_path)

client = InferenceHTTPClient(
    api_url="https://serverless.roboflow.com",
    api_key=os.getenv("API_KEY"),
)
results = client.infer(image_path, model_id="your-project/1")
print(results)

Set api_url to match your deployment target:

  • https://serverless.roboflow.com for the Serverless Hosted API.

  • http://localhost:9001 for a local Inference server.

  • Your Dedicated Deployment URL for a private endpoint.

For self-hosted deployment and additional details, see the Inference documentation.

Last updated

Was this helpful?