> For the complete documentation index, see [llms.txt](https://docs.roboflow.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.roboflow.com/deploy/supported-models/resnet.md).

# ResNet

Run ImageNet-pretrained ResNet image classification through the [Serverless Hosted API](/deploy/serverless-hosted-api-v2.md), or self-host using [Roboflow Inference](https://inference.roboflow.com/).

## Default aliases

Pass any of these aliases as the `model_id` when using the [inference-sdk](/deploy/serverless-hosted-api-v2/use-with-python-sdk.md):

* `resnet18`
* `resnet34`
* `resnet50`
* `resnet101`

## Accuracy and inference speed

Latency is measured with [Roboflow Inference](https://inference.roboflow.com/) on 1x NVIDIA L4, batch size 1, mean of 1,000 inferences (100 warmup). These aliases run on ONNX (no prebuilt TensorRT engine). Batching does not help: these checkpoints export a fixed batch dimension of 1.

Accuracy is the published ImageNet-1k spec for the standard torchvision weights ([source](https://pytorch.org/vision/stable/models.html)).

<table data-search="false"><thead><tr><th>Alias</th><th>Top-1</th><th>Top-5</th><th>Latency (ms)</th></tr></thead><tbody><tr><td><code>resnet18</code></td><td>69.8</td><td>89.1</td><td>1.4</td></tr><tr><td><code>resnet34</code></td><td>73.3</td><td>91.4</td><td>2.2</td></tr><tr><td><code>resnet50</code></td><td>76.1</td><td>92.9</td><td>2.4</td></tr><tr><td><code>resnet101</code></td><td>77.4</td><td>93.5</td><td>3.7</td></tr></tbody></table>

## Code sample

{% stepper %}
{% step %}

### Get your API Key

Create a Roboflow account, find your key on the [Roboflow API settings page](https://app.roboflow.com/settings/api) and make it available to your shell:

```bash
export ROBOFLOW_API_KEY="your-key-here"
```

{% endstep %}

{% step %}

### Install the dependencies

This package calls the model:

```bash
pip install inference-sdk
```

{% endstep %}

{% step %}

### Run the model

The sample below runs `resnet50` against a remote image.

```python
import os
import cv2
import numpy as np
import requests
from inference_sdk import InferenceHTTPClient

content = requests.get("https://media.roboflow.com/notebooks/examples/dog.jpeg").content
image = cv2.imdecode(np.frombuffer(content, np.uint8), cv2.IMREAD_COLOR)

client = InferenceHTTPClient(
    api_url="https://serverless.roboflow.com",
    api_key=os.environ["ROBOFLOW_API_KEY"],
)
results = client.infer(image, model_id="resnet50")
print(results)
```

<figure><img src="/files/U8XfavEZzBRrLQID27ok" alt=""><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

{% hint style="info" %}
Set `api_url` to match your deployment target:

* `https://serverless.roboflow.com` for the Serverless Hosted API.
* `http://localhost:9001` for a local [Inference](https://inference.roboflow.com/) server.
* Your [Dedicated Deployment](/deploy/dedicated-deployments.md) URL for a private endpoint.
  {% endhint %}
