Skip to main content

Coco to Custom Vision (in Azure)

Build GitHub release

A simple utility to upload a COCO dataset format to custom vision and vice versa. This can be used to backup your custom vision object detection projects into a storage account and restore it later or use AzureML to create a more custom CV model.

Currently the scripts work with Object Detection but can be easily updated to work with Classification.

Installation

Install from pip:

pip install coco2customvision

Usage

To export a custom vision project to an Azure storage account use the following:

coco2customvision export -sk "<storage_account_key>" -sn <storage_account_name> -sc <storage_account_container_name> -cvk <custom_vision_key> -cve <custom_vision_endpoint> -cvp <custom_vision_project_name> coco_dataset_filename.json

To import a coco dataset that is located in an Azure storage account container into a custom vision project (the project may not exist yet):

coco2customvision import -sk "<storage_account_key>" -sn <storage_account_name> -sc <storage_account_container_name> -cvk <custom_vision_key> -cve <custom_vision_endpoint> -cvp <custom_vision_project_name> coco_dataset_filename.json

You can get the parameters from:

  • Custom vision: custom_vision_key, custom_vision_endpoint, custom_vision_project_name
  • Azure portal: storage_account_key, storage_account_name, storage_account_container_name

Code development

If you want to contribute to this code base, clone the repo and follow these instructions.

Development installation

Install module in editable/develop mode (-e) and include the development dependencies (the [dev] argument you see) using the following:

pip install -e .[dev]

For tests to complete, you need to configure some secrets. These secrets are retrieved from environment variables. To avoid adding these environment variables in your system, you need to create a pytest.ini file based on the pytest.ini.template template and fill in all needed values. Use the following links to retrieve the corresponding settings:

The pytest.ini file is in .gitignore to avoid pushing credentials accidentally.

To run all tests:

python -m pytest . -c pytest.ini

or use the VSCode Test Explorer to even debug your code.

[Optional] Invoking the dev code from command line

If you installed the module in develop mode you can use it directly as seen in the instructions above. You can also use the module reference, as seen bellow.

To export a custom vision project to an Azure storage account use the following:

python -m src.coco2customvision export -sk "<storage_account_key>" -sn <storage_account_name> -sc <storage_account_container_name> -cvk <custom_vision_key> -cve <custom_vision_endpoint> -cvp <custom_vision_project_name> coco_dataset_filename.json

To import a coco dataset that is located in an Azure storage account container into a custom vision project (the project may not exist yet):

python -m src.coco2customvision import -sk "<storage_account_key>" -sn <storage_account_name> -sc <storage_account_container_name> -cvk <custom_vision_key> -cve <custom_vision_endpoint> -cvp <custom_vision_project_name> coco_dataset_filename.json

Code quality practices

Before making any commit you can invoke the pre-commit.bat file which does the following:

  • Format the code using black:

    python -m black . 
    
  • Ensure that there is no flake8 error:

    python -m flake8 .
    
  • Ensure all test pass:

    python -m pytest . -c pytest.ini
    
  • Ensure setup.cfg file is consistently formatted:

    setup-cfg-fmt setup.cfg
    

Publishing to pypi

To create a release you need to create an annotated tag:

git tag -a v0.1.0 -m "First version of the tool"

You can view existing tags and their comments (-n) using:

git tag -n

Run a build to create the corresponding version artifacts under the dist folder. Then push them to testpypi to verify:

pip install --upgrade twine
twine upload --repository testpypi dist/*

Verify results in the test Pypi instance. You can try installing in a new python environment using:

pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple coco2customvision

If you decide to make some more changes, you can delete a tag using the following:

git tag -d v0.1.0

Note: You will not be able to push the same version to the test Pypi instance. As a work around you can increase the prerelease 4th digit e.g. 0.1.0.1.

When you are ready push changes to remote and let github actions publish the package to the production Pypi. Just push the tag to GitHub and the CD action will create the release:

git push origin --tags

Note that currently the CD process is kicked when you push the tag and it doesn't do the CI part. So make sure your code is passing the CI part before tagging and pushing the tag to GitHub.

References

Here is a list of related projects and references to this effort:

List of Python related references:

Metadata

Release files for coco2customvision 0.0.1

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

Source distribution (sdist)

Source distribution for coco2customvision 0.0.1
File Size Uploaded Provenance Actions
coco2customvision-0.0.1.tar.gz 20.1 kB Without provenance Details for coco2customvision-0.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for coco2customvision 0.0.1
File Interpreter ABI Platform Actions
coco2customvision-0.0.1-py3-none-any.whl Python 3 none any Details for coco2customvision-0.0.1-py3-none-any.whl

Total release size: 34.1 kB

Release files / coco2customvision-0.0.1.tar.gz

Download URL coco2customvision-0.0.1.tar.gz
Size 20.1 kB
Tags Source
SHA-256 checksum
How to use checksums
dee7f1df44de4540b47e0590b27205e58d05f5da744c9125a369bd67eac99715
BLAKE2b-256 checksum
How to use checksums
25a7a668655d0915365d8ca37de85cad23fe89fd6f22ec1aa87f4785fc66b09c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

Release files / coco2customvision-0.0.1-py3-none-any.whl

Download URL coco2customvision-0.0.1-py3-none-any.whl
Size 14.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f359a98c064b5b3d057654a8132f7297df632abee27dbf949f05db7ca65f9449
BLAKE2b-256 checksum
How to use checksums
3976d08e4b646a99a4e06fd072716b6ac3ad73715c831bba8c6041fc035274a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

Security for coco2customvision 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files No provenance

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