Skip to main content
https://travis-ci.org/CatalystCode/py_custom_vision_client.svg?branch=master https://img.shields.io/pypi/v/custom_vision_client.svg

py_custom_vision_client

This repository contains a simple Python client for the Custom Vision Service.

Usage

# first, train a model

from custom_vision_client import TrainingClient, TrainingConfig

azure_region = "southcentralus"
training_key = "my-training-key"  # from settings pane on customvision.ai

training_client = TrainingClient(TrainingConfig(azure_region, training_key))
project_id = training_client.create_project("my-project-name").Id

training_client.create_tag(project_id, "Cat")
training_client.create_tag(project_id, "Dog")

training_client.add_training_images(project_id, ["kitten.jpg"], "Cat")
training_client.add_training_images(project_id, ["akita.png", "spitz.png"], "Dog")
training_client.add_training_images(project_id, ["best-animal-pals.jpg"], "Cat", "Dog")

model_id = training_client.trigger_training(project_id).Id

# then, use the model to predict:

from custom_vision_client import PredictionClient, PredictionConfig

azure_region = "southcentralus"
prediction_key = "my-prediction-key"  # from settings pane on customvision.ai

prediction_client = PredictionClient(PredictionConfig(azure_region, project_id, prediction_key))

predictions = prediction_client.classify_image("cat.jpg", model_id)  # could also be a url to a file
best_prediction = max(predictions, key=lambda _: _.Probability)
print(best_prediction.Tag)

Command-line interface

You can also interact with the Custom Vision Service via a command-line interface:

# first, train a model
python3 -m custom_vision_client.training \
  --key="my-training-key" \
  --projectname="my-project-name" \
  --imagesroot="/path/to/images"

# then, use the model to predict:
python3 -m custom_vision_client.prediction \
  --key="my-prediction-key" \
  --projectid="my-project-id-from-training" \
  --modelid="my-model-id-from-training" \
  --image="path-or-url-to-image"

The command-line interface assumes that your training images are organized in folders such that every folder contains all the training images for that label:

/path/to/images
├── label_one
│   ├── image_1.jpg
│   ├── image_2.png
│   └── image_3.png
└── label_two
    ├── image_4.jpg
    └── image_5.jpg

Release files for custom_vision_client 0.0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for custom_vision_client 0.0.8
File Size Uploaded
custom_vision_client-0.0.8.tar.gz 5.6 kB Details

Release files / custom_vision_client-0.0.8.tar.gz

Download URL custom_vision_client-0.0.8.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
f6d1f0405b63621a10853da1a1b4b93f54a300837178c7ddf68fc95ca2635483
BLAKE2b-256 checksum
How to use checksums
4d22b8ec33004828550f44e7ba8fab243aba518972fdc7cf6e2dfff476274feb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.0.8 This release

1 release file

0.0.7

1 release file

0.0.6

1 release file

0.0.5

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page