Microsoft Azure Custom Vision Client Library for Python providing training and prediction clients for custom computer vision models.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Complete machine learning pipeline management for Azure Custom Vision. The training client provides comprehensive functionality for building custom computer vision models including project management, data handling, model training, performance evaluation, and export capabilities.
Create and configure the training client with authentication credentials.
class CustomVisionTrainingClient:
def __init__(self, endpoint: str, credentials):
"""
Initialize the Custom Vision Training Client.
Parameters:
- endpoint: str, Custom Vision training endpoint URL
- credentials: Authentication credentials object
"""
class CustomVisionTrainingClientConfiguration:
"""Training client configuration settings."""Create, configure, and manage Custom Vision projects for different computer vision tasks.
def get_projects() -> list:
"""
Get all projects for the current user.
Returns:
list[Project]: List of user's projects
"""
def create_project(name: str, description: str = None, domain_id: str = None,
classification_type: str = None, target_export_platforms: list = None,
export_model_container_uri: str = None, notification_queue_uri: str = None) -> Project:
"""
Create a new Custom Vision project.
Parameters:
- name: str, project name
- description: str, optional project description
- domain_id: str, domain ID for the project type
- classification_type: str, "Multiclass" or "Multilabel"
- target_export_platforms: list, platforms for model export
- export_model_container_uri: str, container URI for exports
- notification_queue_uri: str, notification queue URI
Returns:
Project: Created project object
"""
def get_project(project_id: str) -> Project:
"""
Get project by ID.
Parameters:
- project_id: str, unique project identifier
Returns:
Project: Project object
"""
def update_project(project_id: str, project: Project) -> Project:
"""
Update project settings.
Parameters:
- project_id: str, project identifier
- project: Project, updated project object
Returns:
Project: Updated project object
"""
def delete_project(project_id: str):
"""
Delete a project permanently.
Parameters:
- project_id: str, project identifier to delete
"""
def export_project(project_id: str, platform: str, flavor: str = None, options: dict = None) -> str:
"""
Export project for transfer or backup.
Parameters:
- project_id: str, project identifier
- platform: str, export platform
- flavor: str, export flavor/variant
- options: dict, export options
Returns:
str: Export token for project import
"""
def import_project(name: str, export_token: str, export_model_container_uri: str = None,
notification_queue_uri: str = None) -> Project:
"""
Import project from export token.
Parameters:
- name: str, name for imported project
- export_token: str, token from export_project
- export_model_container_uri: str, container URI for models
- notification_queue_uri: str, notification queue URI
Returns:
Project: Imported project object
"""Manage available domains that define the type of computer vision model (classification, object detection, etc.).
def get_domains() -> list:
"""
Get list of available domains for projects.
Returns:
list[Domain]: Available domains for different model types
"""
def get_domain(domain_id: str) -> Domain:
"""
Get specific domain information.
Parameters:
- domain_id: str, domain identifier
Returns:
Domain: Domain information object
"""Upload, organize, and manage training images with metadata and tagging information.
def create_images_from_data(project_id: str, image_data: bytes, tag_ids: list = None) -> ImageCreateSummary:
"""
Upload image from binary data with optional tags.
Parameters:
- project_id: str, target project identifier
- image_data: bytes, image binary data
- tag_ids: list, optional list of tag IDs to apply
Returns:
ImageCreateSummary: Summary of image creation results
"""
def create_images_from_files(project_id: str, batch: ImageFileCreateBatch) -> ImageCreateSummary:
"""
Upload multiple images from file batch.
Parameters:
- project_id: str, target project identifier
- batch: ImageFileCreateBatch, batch of file entries
Returns:
ImageCreateSummary: Summary of batch upload results
"""
def create_images_from_urls(project_id: str, batch: ImageUrlCreateBatch) -> ImageCreateSummary:
"""
Upload multiple images from URL batch.
Parameters:
- project_id: str, target project identifier
- batch: ImageUrlCreateBatch, batch of URL entries
Returns:
ImageCreateSummary: Summary of batch upload results
"""
def create_images_from_predictions(project_id: str, batch: ImageIdCreateBatch) -> ImageCreateSummary:
"""
Create training images from stored predictions.
Parameters:
- project_id: str, target project identifier
- batch: ImageIdCreateBatch, batch of prediction IDs
Returns:
ImageCreateSummary: Summary of image creation results
"""
def get_images(project_id: str, tag_ids: list = None, ordering: str = None,
take: int = 50, skip: int = 0) -> list:
"""
Get project images with filtering and pagination.
Parameters:
- project_id: str, project identifier
- tag_ids: list, filter by specific tag IDs
- ordering: str, sort order ("Newest", "Oldest", "Suggested")
- take: int, number of images to retrieve (max 256)
- skip: int, number of images to skip
Returns:
list[Image]: List of image objects
"""
def get_tagged_images(project_id: str, iteration_id: str = None, tag_ids: list = None,
ordering: str = None, take: int = 50, skip: int = 0) -> list:
"""
Get images that have been tagged.
Parameters:
- project_id: str, project identifier
- iteration_id: str, optional iteration filter
- tag_ids: list, filter by specific tag IDs
- ordering: str, sort order
- take: int, number of images to retrieve
- skip: int, number of images to skip
Returns:
list[Image]: List of tagged images
"""
def get_untagged_images(project_id: str, iteration_id: str = None,
take: int = 50, skip: int = 0) -> list:
"""
Get images that have not been tagged.
Parameters:
- project_id: str, project identifier
- iteration_id: str, optional iteration filter
- take: int, number of images to retrieve
- skip: int, number of images to skip
Returns:
list[Image]: List of untagged images
"""
def delete_images(project_id: str, image_ids: list = None, all_images: bool = None,
all_iterations: bool = None):
"""
Delete images from project.
Parameters:
- project_id: str, project identifier
- image_ids: list, specific image IDs to delete
- all_images: bool, delete all images
- all_iterations: bool, delete from all iterations
"""
def update_image_metadata(project_id: str, batch: ImageMetadataUpdateBatch) -> ImageMetadataUpdateSummary:
"""
Update metadata for multiple images.
Parameters:
- project_id: str, project identifier
- batch: ImageMetadataUpdateBatch, batch metadata updates
Returns:
ImageMetadataUpdateSummary: Summary of update results
"""Create and manage classification tags for organizing and labeling training data.
def get_tags(project_id: str, iteration_id: str = None) -> list:
"""
Get all tags for a project.
Parameters:
- project_id: str, project identifier
- iteration_id: str, optional iteration filter
Returns:
list[Tag]: List of project tags
"""
def create_tag(project_id: str, name: str, description: str = None, type: str = None) -> Tag:
"""
Create a new tag for the project.
Parameters:
- project_id: str, project identifier
- name: str, tag name
- description: str, optional tag description
- type: str, tag type ("Regular", "Negative", "GeneralProduct")
Returns:
Tag: Created tag object
"""
def get_tag(project_id: str, tag_id: str) -> Tag:
"""
Get specific tag information.
Parameters:
- project_id: str, project identifier
- tag_id: str, tag identifier
Returns:
Tag: Tag object
"""
def update_tag(project_id: str, tag_id: str, tag: Tag) -> Tag:
"""
Update tag information.
Parameters:
- project_id: str, project identifier
- tag_id: str, tag identifier
- tag: Tag, updated tag object
Returns:
Tag: Updated tag object
"""
def delete_tag(project_id: str, tag_id: str):
"""
Delete a tag from the project.
Parameters:
- project_id: str, project identifier
- tag_id: str, tag identifier to delete
"""
def create_image_tags(project_id: str, batch: ImageTagCreateBatch) -> ImageTagCreateSummary:
"""
Apply tags to multiple images.
Parameters:
- project_id: str, project identifier
- batch: ImageTagCreateBatch, batch tag assignments
Returns:
ImageTagCreateSummary: Summary of tag creation results
"""
def delete_image_tags(project_id: str, image_ids: list, tag_ids: list):
"""
Remove tags from images.
Parameters:
- project_id: str, project identifier
- image_ids: list, image IDs to untag
- tag_ids: list, tag IDs to remove
"""Train custom vision models and manage different training iterations with performance tracking.
def train_project(project_id: str, training_type: str = None, reserved_budget_in_hours: int = None,
force_train: bool = None, notification_email_address: str = None,
training_parameters: dict = None) -> Iteration:
"""
Start training a new model iteration.
Parameters:
- project_id: str, project identifier
- training_type: str, "Regular" or "Advanced"
- reserved_budget_in_hours: int, training time budget
- force_train: bool, force training even with few images
- notification_email_address: str, email for completion notification
- training_parameters: dict, advanced training parameters
Returns:
Iteration: New training iteration object
"""
def get_iterations(project_id: str) -> list:
"""
Get all training iterations for a project.
Parameters:
- project_id: str, project identifier
Returns:
list[Iteration]: List of training iterations
"""
def get_iteration(project_id: str, iteration_id: str) -> Iteration:
"""
Get specific iteration information.
Parameters:
- project_id: str, project identifier
- iteration_id: str, iteration identifier
Returns:
Iteration: Iteration object with details
"""
def update_iteration(project_id: str, iteration_id: str, iteration: Iteration) -> Iteration:
"""
Update iteration settings.
Parameters:
- project_id: str, project identifier
- iteration_id: str, iteration identifier
- iteration: Iteration, updated iteration object
Returns:
Iteration: Updated iteration object
"""
def delete_iteration(project_id: str, iteration_id: str):
"""
Delete a training iteration.
Parameters:
- project_id: str, project identifier
- iteration_id: str, iteration identifier to delete
"""
def publish_iteration(project_id: str, iteration_id: str, publish_name: str, prediction_id: str):
"""
Publish iteration for prediction use.
Parameters:
- project_id: str, project identifier
- iteration_id: str, iteration to publish
- publish_name: str, name for published model
- prediction_id: str, prediction resource ID
"""
def unpublish_iteration(project_id: str, iteration_id: str):
"""
Unpublish an iteration.
Parameters:
- project_id: str, project identifier
- iteration_id: str, iteration to unpublish
"""Evaluate model performance with detailed metrics and per-image analysis.
def get_iteration_performance(project_id: str, iteration_id: str, threshold: float = None,
overlap_threshold: float = None) -> IterationPerformance:
"""
Get detailed performance metrics for an iteration.
Parameters:
- project_id: str, project identifier
- iteration_id: str, iteration identifier
- threshold: float, confidence threshold for metrics
- overlap_threshold: float, overlap threshold for object detection
Returns:
IterationPerformance: Comprehensive performance metrics
"""
def get_image_performances(project_id: str, iteration_id: str, tag_ids: list = None,
ordering: str = None, take: int = 50, skip: int = 0) -> list:
"""
Get per-image performance analysis.
Parameters:
- project_id: str, project identifier
- iteration_id: str, iteration identifier
- tag_ids: list, filter by specific tags
- ordering: str, sort order
- take: int, number of results to retrieve
- skip: int, number of results to skip
Returns:
list[ImagePerformance]: Per-image performance data
"""Perform quick tests on trained models without formal publishing.
def quick_test_image(project_id: str, image_data: bytes, iteration_id: str = None,
store: bool = True) -> ImagePrediction:
"""
Quick test with image data.
Parameters:
- project_id: str, project identifier
- image_data: bytes, test image binary data
- iteration_id: str, specific iteration to test (default: latest)
- store: bool, whether to store prediction results
Returns:
ImagePrediction: Prediction results
"""
def quick_test_image_url(project_id: str, image_url: str, iteration_id: str = None,
store: bool = True) -> ImagePrediction:
"""
Quick test with image URL.
Parameters:
- project_id: str, project identifier
- image_url: str, URL of test image
- iteration_id: str, specific iteration to test
- store: bool, whether to store prediction results
Returns:
ImagePrediction: Prediction results
"""Manage bounding box regions for object detection training and region proposals.
def get_image_region_proposals(project_id: str, image_id: str) -> ImageRegionProposal:
"""
Get region proposals for an image to assist with labeling.
Parameters:
- project_id: str, project identifier
- image_id: str, image identifier
Returns:
ImageRegionProposal: Suggested regions for labeling
"""
def create_image_regions(project_id: str, regions: list) -> ImageRegionCreateSummary:
"""
Create image regions (bounding boxes) for object detection.
Parameters:
- project_id: str, project identifier
- regions: list[ImageRegionCreateEntry], regions to create
Returns:
ImageRegionCreateSummary: Summary of region creation results
"""
def delete_image_regions(project_id: str, region_ids: list):
"""
Delete image regions.
Parameters:
- project_id: str, project identifier
- region_ids: list[str], region IDs to delete
"""Manage tag assignments for images.
def create_image_tags(project_id: str, tags: list) -> ImageTagCreateSummary:
"""
Associate images with tags.
Parameters:
- project_id: str, project identifier
- tags: list[ImageTagCreateEntry], tag assignments
Returns:
ImageTagCreateSummary: Summary of tagging results
"""
def delete_image_tags(project_id: str, image_ids: list, tag_ids: list):
"""
Remove tag associations from images.
Parameters:
- project_id: str, project identifier
- image_ids: list[str], image identifiers
- tag_ids: list[str], tag identifiers to remove
"""Manage model exports for different platforms and formats.
def get_exports(project_id: str, iteration_id: str) -> list:
"""
Get all exports for an iteration.
Parameters:
- project_id: str, project identifier
- iteration_id: str, iteration identifier
Returns:
list[Export]: Available exports for the iteration
"""
def export_iteration(project_id: str, iteration_id: str, platform: str, flavor: str = None) -> Export:
"""
Export trained iteration to specified platform.
Parameters:
- project_id: str, project identifier
- iteration_id: str, iteration to export
- platform: str, target platform (TensorFlow, ONNX, etc.)
- flavor: str, platform variant
Returns:
Export: Export operation details
"""Manage prediction results and queries.
def delete_prediction(project_id: str, ids: list):
"""
Delete prediction results.
Parameters:
- project_id: str, project identifier
- ids: list[str], prediction IDs to delete
"""
def query_predictions(project_id: str, query: PredictionQueryToken) -> PredictionQueryResult:
"""
Query stored prediction results.
Parameters:
- project_id: str, project identifier
- query: PredictionQueryToken, query parameters
Returns:
PredictionQueryResult: Matching prediction results
"""AI-powered suggestions for tagging and region labeling.
def suggest_tags_and_regions(project_id: str, iteration_id: str, image_ids: list) -> list:
"""
Get AI suggestions for tags and regions on images.
Parameters:
- project_id: str, project identifier
- iteration_id: str, trained iteration for suggestions
- image_ids: list[str], images to analyze
Returns:
list[SuggestedTagAndRegion]: AI-generated suggestions
"""
def query_suggested_images(project_id: str, iteration_id: str, query: SuggestedTagAndRegionQueryToken) -> SuggestedTagAndRegionQuery:
"""
Query suggested images based on criteria.
Parameters:
- project_id: str, project identifier
- iteration_id: str, iteration identifier
- query: SuggestedTagAndRegionQueryToken, query parameters
Returns:
SuggestedTagAndRegionQuery: Matching suggested images
"""
def query_suggested_image_count(project_id: str, iteration_id: str, tag_ids: list = None, threshold: float = None) -> dict:
"""
Get count of images with suggestions.
Parameters:
- project_id: str, project identifier
- iteration_id: str, iteration identifier
- tag_ids: list[str], filter by tag IDs
- threshold: float, confidence threshold
Returns:
dict: Suggestion counts by category
"""Extended image management capabilities.
def get_artifact(project_id: str, path: str):
"""
Get artifact content from blob storage.
Parameters:
- project_id: str, project identifier
- path: str, artifact path
Returns:
Generator: Artifact content stream
"""
def get_image_performance_count(project_id: str, iteration_id: str, tag_ids: list = None) -> int:
"""
Get count of images with performance data.
Parameters:
- project_id: str, project identifier
- iteration_id: str, iteration identifier
- tag_ids: list[str], filter by tag IDs
Returns:
int: Count of images with performance data
"""class ImageCreateSummary:
"""Summary of image upload operations."""
is_batch_successful: bool
images: list # list[ImageCreateResult]
duplicated_images: list
class ImageFileCreateBatch:
"""Batch of images to upload from files."""
images: list # list[ImageFileCreateEntry]
tag_ids: list
class ImageFileCreateEntry:
"""Individual file upload entry."""
name: str = None
contents: bytes
tag_ids: list = None
regions: list = None
metadata: dict = None
class ImageTagCreateBatch:
"""Batch tag creation for images."""
tags: list # list[ImageTagCreateEntry]
class ImageTagCreateEntry:
"""Individual tag assignment entry."""
image_id: str
tag_id: str
class IterationPerformance:
"""Model performance metrics."""
per_tag_performance: list # list[TagPerformance]
precision: float
precision_std_deviation: float
recall: float
recall_std_deviation: float
average_precision: float
class Image:
"""Training image with metadata."""
id: str
created: datetime
width: int
height: int
image_uri: str
thumbnail_uri: str
tags: list # list[ImageTag]
regions: list # list[ImageRegion]
metadata: dictInstall with Tessl CLI
npx tessl i tessl/pypi-azure-cognitiveservices-vision-customvision