
ResNet-18 is a small, fast, supervised classification model. ResNet-18 uses the ResNet CNN architecture with 18 convolution and residual layers.
ResNet-18 is an ideal model architecture to use if you need a model that runs at dozens of frames per second on the edge. You can train ResNet-18 models – as well as larger ResNet models – in the cloud with Roboflow Train.
In this guide, we are going to walk through how to train a ResNet-18 model in the cloud, then deploy the model on your own hardware with Roboflow Inference
Without further ado, let’s get started!
Step #1: Annotate and Prepare a Dataset
First, we need to label a dataset for classification. For this guide, we will use a pre-existing dataset that contains photos of metal plates. Some of the photos contain a scratch, whereas others contain no defect. We will train our model to classify an image into two categories: defect and no defect.
Here is an example of an image with a defect:
There is a scratch in the top left corner of the metal plate.
If you want to train a model using this dataset, you can fork – copy – the dataset from Roboflow Universe. To fork the dataset, open the dataset in Roboflow Universe, then click the “Fork Dataset” button:
This will copy the dataset into your Workspace.
If you want to use your own dataset, open your Roboflow dashboard and create a new project. Choose “Single-label classification” as your model type. Then, upload the images you want to label. You can then label the images using Roboflow Annotate. In the Annotate interface, you can assign a class to an image:
Once you have labeled your dataset, click “Versions” in the left sidebar of your project. Then, add a “Resize” preprocessing step with the resolution 640x640, as well as an Auto-Orient preprocessing step:
We recommend applying no augmentations for your first dataset version so you can evaluate how your dataset performs on your task. To learn more about best practices for augmentation, refer to our image augmentation guide.
Click “Create” at the bottom of the page to create your dataset version.
Step #2: Train a ResNet-18 Model
With a dataset version ready, you can start training a model. Click “Custom Train”:
Then, choose the ResNet model architecture:
Choose the ResNet-18 architecture:
Then, choose “Train from ImageNet” and click “Start Training”:
Your dataset will be prepared for training and a model training job will begin. You will receive an estimate of how long we think the model training job will take. The amount of time a training job will take to complete will depend on the architecture you have chosen and the number of images in your dataset.
You can follow the progress of your training job in real time:
Once your model has finished training, you can use and deploy it.
Step #3: Run the ResNet-18 Model with Workflows
We are going to create a Workflow that runs our model and can be run with Inference on our own hardware.
Click “Deployments” on the left sidebar of your project, then click the Workflows deployment option:
You will be asked what template you want to use. Select “Build My Own”. You will then be taken into the Workflows editor. From the Workflows editor, you can build custom logic that uses your model using several blocks, from the label annotator (which draws labels) to the Expression block (which you can use to return, for example PASS/FAIL depending on conditions).
For this guide, we’ll deploy the default Workflow to show our model is working.
Here is an example of a Workflow that runs our ResNet model and returns the result:
Step #4: Deploy the ResNet-18 Model
Our model is already set up, so all we need to do is get the deployment code. Click “Deploy” in the top right corner, then copy-paste the “Run on an Image (Local)” code. The code will look like this:
from inference_sdk import InferenceHTTPClient
client = InferenceHTTPClient(
api_url="https://localhost:9001", # use local inference server
api_key="API_KEY"
)
result = client.run_workflow(
workspace_name="your-workspace-name",
workflow_id="your-workflow-id",
images={
"image": "YOUR_IMAGE.jpg"
}
)
print(result)
Before you run the code, you will need to install Inference on your machine and install Docker. If you don’t already have Docker installed, follow the official Docker installation instructions.
You can then start a local Inference server:
pip install inference-cli && inference server start
Let’s run our code on the following image from the test split of our dataset:
There is a small defect in the bottom right corner.
Our code returns:
defect
The model successfully identified that the image contains a defect.
Conclusion
ResNet-18 is a small, fast computer vision model architecture used for classification. You can train ResNet-18 models with Roboflow, then deploy the model on your own hardware using Roboflow Workflows and Inference.
In this guide, we trained a ResNet-18 model to classify defects in metal. We uploaded data to Roboflow, annotated the dataset, generated a dataset version, trained a model, then created a Workflow to run our model.
If you are interested in learning more about deploying with Roboflow, check out our other Workflow tutorials.
Cite this Post
Use the following entry to cite this post in your research:
James Gallagher. (Jun 25, 2025). How to Train a ResNet-18 Model with a Custom Dataset. Roboflow Blog: https://blog.roboflow.com/train-resnet-18/