Working with Models

A key aspect of the alwaysAI workflow is the flexible way models can be used in your computer vision applications. Any model that is within the alwaysAI system can be used in any alwaysAI application and added to any Project. This includes any models contained in the public alwaysAI model cataglog, that have been successfully uploaded to alwaysAI, or that were trained using the alwaysAI model retraining toolkit. Use models side-by-side to test out functionality, swap models within a core service, or use models from different core services in the same application. This page will cover core concepts of alwaysAI models as well as all the ways you can leverage alwaysAI models in building computer vision applications.

Core Concepts

Types of Models

alwaysAI enables you to work with models built for image classification, object detection, pose estimation (key points), and semantic segmentation. If you are new to computer vision, you can read more about these types of models in our documentation on core computer vision services.

Datasets

The models in the public alwaysAI model catalog are based on one of three datasets: ImageNet (image classification), COCO (object detection), and Pascal VOC (object detection). If you want to train your own model, you can read about dataset generation and collection guidelines in our documentation.

ImageNet Dataset

Models based on the ImageNet dataset can classify an image into 1,000 separate categories and are trained on a dataset consisting of more than 1.2 million images. A full list of ImageNet object categories can be found here.

COCO Dataset

The Common Object in Context (COCO) dataset is a large-scale object detection dataset consisting of 330,000 images. Models in the catalog are capable of identifying between 90 - 100 unique object categories depending on their training. More information on the COCO dataset can be found here.

Pascal VOC

Pascal Visual Object Classes (VOC) is an object detection dataset consisting of 11,530 images and capable of identifying 20 unique object classes (person, bird, cat, cow, dog, horse, sheep, aeroplane, bicycle, boat, bus, car, motorbike, train, bottle, chair, dining table, potted plant, sofa, tv/monitor). More information on the VOC dataset can be found here.

Model Accuracy and Inference Times

Where available, accuracy information for a model is shown in mean Average Precision (mAP). Two mAP values are given based on how often an object is correctly predicted within the first predictions (top-1) or within the top five predictions (top-5) returned by the inference engine. For full information on mAP and how it is calculated see this Medium article.

Inference times for models measure how long it takes for the inference engine to process an image and return predictions. Inference times are given in seconds, with benchmarking done on the Inforce 6640. Information for the Inforce 6640 can be found here.

Models within alwaysAI

There are many options for models in alwaysAI: in addition to the large number of models available in the alwaysAI public model catalog, you can upload your own pre-trained custom model, or train a custom model using the alwaysAI model retraining toolkit. Once inside the alwaysAI system, any model can be used virtually interchangeably using the alwaysAI API, edgeIQ.

The alwaysAI Public Model Catalog

The alwaysAI model catalog provides a set of pre-trained machine learning models that, when combined with the alwaysAI edgeIQ APIs, allows developers to quickly prototype a computer vision application without the need to first create and train a custom model.

Uploading Models

In order to use your own custom model, first upload the model to your account. Although your model lives in the alwaysAI cloud, it will be private and only accessible by you or Collaborators on Projects you have shared the model with.

You can upload a private model from the ‘Models’ tab on your Dashboard, by clicking the red ‘Upload a Model’ button, which takes you to this form.

Follow the prompts and upload the specified files to upload your model.

Note: We currently do not support h5 format.

Training Your Own Model

If you can’t find a suitable model in the alwaysAI model catalog, you can also train your own model using the retraining toolkit and use it in the same manner that you would any other model in the alwaysAI platform.

Using Models

All models in the alwaysAI system can be used in any application, added to any Project, and shared with any alwaysAI Collaborator, in exactly the same way. Both the Dashboard and CLI enable you to add or remove models to a project, including models that you are training locally and which haven’t been published to the alwaysAI cloud yet. The alwaysAI API, edgeIQ, has standardized interfaces for working with each model type in each of the core services.

Adding Models to Your Application

We have detailed documentation on adding models to your application and Project via the Dashboard. Any time you make a change to models for a Project in your Dashboard, you can sync the changes locally using the command:

$ aai app models sync

You can also use the CLI locally to add models to your application, as shown below.

Navigate to your app directory and run the following command in the terminal:

$ aai app models add <username>/<modelName>

Where username is your alwaysAI username, and modelName is the name you gave the model when you uploaded it. Here’s an example:

$ aai app models add alwaysai/MyFirstModel

In addition to adding the model to your Project, you must update the class instantiation in your application source (app.py) to use the new model. If you’re using an ObjectDetection model, your code might look like this:

obj_detect = ObjectDetection("alwaysai/MyFirstModel")

Note: The specific CLI commands and Python code needed to add a given model to an application are provided within the model details page for every model in the alwaysAI public model catalog for convenience.

Add an Unpublished Model

You can also add models that you have trained locally that have not yet been published. To do so, use the following command:

$ aai app models add <username/modelName> --local-version <num>

Display Models

At any time, you can check which models have been added to a Project on the Dashboard, by looking under the ‘Models’ tab for a specific Project, or by running the following command from within a project directory:

$ aai app models show

Install a Model Locally

To install locally on your development machine or to a remote device, use the command:

$ aai app install

This will pull the necessary model files down to your local machine, storing them in the models folder in the local Project directory. Run this command after making any model changes to your application and before running aai app start.

(Optional) Removing Models From Your Application

If you have a previous model in your app, you can delete it from the Project using your Dashboard. Click the three dots next to any model listed under ‘Models’ in a specific Project, and select ‘Delete’ to remove the model from the Project.

You can also remove it from the Project from the CLI using the command:

$ aai app models remove <username>/<modelName>

For instance, to remove the model alwaysai/mobilenet_ssd, you would run:

$ aai app models remove alwaysai/mobilenet_ssd

Related Tutorials