Introduction
Azure Custom Vision is a cloud-based service that enables developers to build, train, and deploy custom image classification models without requiring deep machine learning expertise. It provides an easy-to-use interface and API, allowing users to:
- ✔️ Upload images
- ✔️ Label images
- ✔️ Train models that recognize specific objects or categories
In this article, we will walk through:
- ✅ Creating and configuring a Custom Vision project
- ✅ Uploading and labeling custom training images
- ✅ Training a custom image classification model
- ✅ Deploying the trained model as an API endpoint
- ✅ Performing image inference using the deployed API
![Projects]()
Step 1. Setting Up a Custom Vision Project
Prerequisites
Before starting, ensure you have:
- ✔️ An Azure account with an active subscription
- ✔️ Access to the Azure Custom Vision portal
- ✔️ The Azure Custom Vision SDK (if working with code)
- ✔️ A dataset of labeled images for training
Creating a Custom Vision Project
1️⃣ Navigate to the Azure Custom Vision portal
2️⃣ Sign in with your Azure credentials
3️⃣ Click "New Project" and configure the settings:
- Project Name: Enter a unique project name
- Resource Group: Choose or create a resource group
- Project Type: Choose Classification (for object classification) or Object Detection (if detecting multiple objects in an image)
- Domains: Select a domain that best suits your dataset (e.g., General, Food, Retail)
4️⃣ Click "Create project" to proceed.
![Create new resource]()
For more details, refer to the Azure Custom Vision Documentation
Step 2. Uploading and Labeling Training Data
Uploading Images
- Open the created project in the Custom Vision portal.
- Click "Add images" and select images from your local machine.
- Assign tags (labels) to classify images into categories.
- Click "Upload" to add images to the training dataset.
Best Practices for Image Labeling
✔️ Use at least 50 images per category for better accuracy.
✔️ Ensure images are varied in lighting, angles, and backgrounds.
✔️ Label images accurately to improve model performance.
Step 3. Training the Custom Vision Model
- In the Custom Vision portal, click "Train".
- Choose between:
- Quick Training (faster but less accurate for small datasets)
- Advanced Training (recommended for higher accuracy and larger datasets)
- Wait for the training process to complete.
- After training, view performance metrics such as precision, recall, and overall accuracy.
Sample Code. Training a Custom Vision Model via SDK
from azure.cognitiveservices.vision.customvision.training import CustomVisionTrainingClient
from msrest.authentication import ApiKeyCredentials
# Azure Custom Vision credentials
ENDPOINT = "<your_custom_vision_endpoint>"
TRAINING_KEY = "<your_training_key>"
credentials = ApiKeyCredentials(in_headers={"Training-key": TRAINING_KEY})
trainer = CustomVisionTrainingClient(ENDPOINT, credentials)
# Create a new project
project = trainer.create_project("My Custom Vision Project")
Step 4. Deploying the Model as an API
Once training is complete, navigate to the Performance tab in Custom Vision.
- Click "Publish" and configure the API endpoint:
- Prediction Resource: Choose an Azure resource for deployment.
- Model Name: Provide a name for the deployed model.
- Click "Publish" to deploy the trained model as an API.
For more details, refer to the Custom Vision Deployment Guide
Sample Code. Accessing the Model via API
from azure.cognitiveservices.vision.customvision.prediction import CustomVisionPredictionClient
from msrest.authentication import ApiKeyCredentials
# Azure Custom Vision Prediction credentials
PREDICTION_KEY = "<your_prediction_key>"
ENDPOINT = "<your_custom_vision_endpoint>"
predictor = CustomVisionPredictionClient(
ENDPOINT, ApiKeyCredentials(in_headers={"Prediction-key": PREDICTION_KEY})
)
# Perform image classification
image_path = "test_image.jpg"
with open(image_path, "rb") as image_data:
results = predictor.classify_image("<project_id>", "<published_model_name>", image_data.read())
for prediction in results.predictions:
print(f"{prediction.tag_name}: {prediction.probability * 100:.2f}%")
Step 5. Performing Image Inference
After deployment, you can send images to the API to get classification results.
Example API Call
You can test the API using Python, Postman, or any HTTP client:
import requests
url = "https://<your_custom_vision_endpoint>/classify/iterations/<your_model>/image"
headers = {
"Prediction-Key": "<your_prediction_key>",
"Content-Type": "application/octet-stream"
}
with open("image.jpg", "rb") as image_file:
response = requests.post(url, headers=headers, data=image_file.read())
print(response.json())
Conclusion
In this article, we covered:
- ✅ Creating a Custom Vision project
- ✅ Uploading and labeling training images
- ✅ Training a custom image classification model
- ✅ Deploying the trained model as a REST API
- ✅ Performing image inference using the API
Azure Custom Vision makes it easy to build and deploy image classification models with minimal coding effort. You can further enhance your model by:
- ✔️ Adding more training images
- ✔️ Retraining with additional categories
- ✔️ Integrating it with Azure Functions and Power Automate for automated workflows
For further learning, visit the Azure Custom Vision Documentation.