/ Computer Vision

Best Practices and documentation for Computer Vision

Best Practices and documentation for Computer Vision

Computer Vision

In recent years, we see an extra-ordinary growth in Computer Vision, with applications in face recognition, image understanding, search, drones, mapping, semi-autonomous and autonomous vehicles. Key essence to many of these applications are visual recognition tasks such as image classification, object detection and image similarity. Researchers have been applying newer deep learning methods to achieve state-of-the-art(SOTA) results on these challenging visual recognition tasks.

This repository provides examples and best practice guidelines for building computer vision systems. The focus of the repository is on state-of-the-art methods that are popular among researchers and practitioners working on problems involving image recognition, object detection and image similarity.

These examples are provided as Jupyter notebooks and common utility functions. All examples use PyTorch as the deep learning library.

Overview

The goal of this repository is to accelerate the development of computer vision applications. Rather than creating implementions from scratch, the focus is on providing examples and links to existing state-of-the-art libraries. In addition, having worked in this space for many years, we aim to answer common questions, point out frequently observed pitfalls, and show how to use the cloud for training and deployment.

We hope that these examples and utilities can significantly reduce the “time to market” by simplifying the experience from defining the business problem to development of solution by orders of magnitude. In addition, the example notebooks would serve as guidelines and showcase best practices and usage of the tools in a wide variety of languages.

Scenarios

The following is a summary of commonly used Computer Vision scenarios that are covered in this repository. For each of these scenarios, we give you the tools to effectively build your own model. This includes tasks such as fine-tuning your own model on your own data, to more complex tasks such as hard-negative mining and even model deployment. See all supported scenarios here.

Scenario Description
Classification Image Classification is a supervised machine learning technique that allows you to learn and predict the category of a given image.
Similarity Image Similarity is a way to compute a similarity score given a pair of images. Given an image, it allows you to identify the most similar image in a given dataset.
Detection Object Detection is a supervised machine learning technique that allows you to detect the bounding box of an object within an image.

Getting Started

To get started:

  1. (Optional) Create an Azure Data Science Virtual Machine with e.g. a V100 GPU (instructions, price table).
  2. Install Anaconda with Python >= 3.6. Miniconda. This step can be skipped if working on a Data Science Virtual Machine.
  3. Clone the repository
    git clone https://github.com/Microsoft/ComputerVision
    
  4. Install the conda environment, you'll find the environment.yml file in the root directory. To build the conda environment:

    If you are using Windows, remove - pycocotools>=2.0 from the environment.yaml

    conda env create -f environment.yml
    
  5. Activate the conda environment and register it with Jupyter:
    conda activate cv
    python -m ipykernel install --user --name cv --display-name "Python (cv)"
    
    If you would like to use JupyterLab, install jupyter-webrtc widget:
    jupyter labextension install jupyter-webrtc
    

    If you are using Windows run at this point:

    • pip install Cython
    • pip install git+https://github.com/philferriere/cocoapi.git#egg=pycocotools^&subdirectory=PythonAPI
  6. Start the Jupyter notebook server
    jupyter notebook
    
  7. At this point, you should be able to run the notebooks in this repo.

As an alternative to the steps above, and if one wants to install only
the 'utils_cv' library (without creating a new conda environment),
this can be done by running

pip install git+https://github.com/microsoft/[email protected]#egg=utils_cv

or by downloading the repo and then running pip install . in the
root directory.

Introduction

Note that for certain computer vision problems, you may not need to build your own models. Instead, pre-built or easily customizable solutions exist which do not require any custom coding or machine learning expertise. We strongly recommend evaluating if these can sufficiently solve your problem. If these solutions are not applicable, or the accuracy of these solutions is not sufficient, then resorting to more complex and time-consuming custom approaches may be necessary.

The following Microsoft services offer simple solutions to address common computer vision tasks:

  • Vision Services
    are a set of pre-trained REST APIs which can be called for image tagging, face recognition, OCR, video analytics, and more. These APIs work out of the box and require minimal expertise in machine learning, but have limited customization capabilities. See the various demos available to get a feel for the functionality (e.g. Computer Vision).

  • Custom Vision
    is a SaaS service to train and deploy a model as a REST API given a user-provided training set. All steps including image upload, annotation, and model deployment can be performed using either the UI or a Python SDK. Training image classification or object detection models can be achieved with minimal machine learning expertise. The Custom Vision offers more flexibility than using the pre-trained cognitive services APIs, but requires the user to bring and annotate their own data.

Build Your Own Computer Vision Model

If you need to train your own model, the following services and links provide additional information that is likely useful.

  • Azure Machine Learning service (AzureML)
    is a service that helps users accelerate the training and deploying of machine learning models. While not specific for computer vision workloads, the AzureML Python SDK can be used for scalable and reliable training and deployment of machine learning solutions to the cloud. We leverage Azure Machine Learning in several of the notebooks within this repository (e.g. deployment to Azure Kubernetes Service)

  • Azure AI Reference architectures
    provide a set of examples (backed by code) of how to build common AI-oriented workloads that leverage multiple cloud components. While not computer vision specific, these reference architectures cover several machine learning workloads such as model deployment or batch scoring.

Computer Vision Domains

Most applications in computer vision (CV) fall into one of these 4 categories:

  • Image classification: Given an input image, predict what object is present in the image. This is typically the easiest CV problem to solve, however classification requires objects to be reasonably large in the image.

intro_ic_vis

  • Object Detection: Given an input image, identify and locate which objects are present (using rectangular coordinates). Object detection can find small objects in an image. Compared to image classification, both model training and manually annotating images is more time-consuming in object detection, since both the label and location are required.

intro_od_vis

  • Image Similarity Given an input image, find all similar objects in images from a reference dataset. Here, rather than predicting a label and/or rectangle, the task is to sort through a reference dataset to find objects similar to that found in the query image.

intro_is_vis

  • Image Segmentation Given an input image, assign a label to every pixel (e.g., background, bottle, hand, sky, etc.). In practice, this problem is less common in industry, in large part due to time required to label the ground truth segmentation required in order to train a solution.

intro_iseg_vis

Build Status

VM Testing

Build Type Branch Status Branch Status
Linux GPU master Build Status staging Build Status
Linux CPU master Build Status staging Build Status
Windows GPU master Build Status staging Build Status
Windows CPU master Build Status staging Build Status
AzureML Notebooks master Build Status staging Build Status

AzureML Testing

Build Type Branch Status Branch Status
Linxu GPU master Build Status staging Build Status
Linux CPU master Build Status staging Build Status
Notebook unit GPU master Build Status staging Build Status
Nightly GPU master Build Status staging Build Status

GitHub