Install and run Form Recognizer v2.1-preview containers

Important

  • Form Recognizer containers are in gated preview. To use them, you must submit an online request, and receive approval. See Request approval to run container below for more information.

  • The online request form requires that you provide a valid email address that belongs to the organization that owns the Azure subscription ID and that you have or have been granted access to that subscription.

Azure Form Recognizer is an Azure Applied AI Service that lets you build automated data processing software using machine learning technology. Form Recognizer enables you to identify and extract text, key/value pairs, selection marks, table data, and more from your form documents and output structured data that includes the relationships in the original file.

In this article you'll learn how to download, install, and run Form Recognizer containers. Containers enable you to run the Form Recognizer service in your own environment. Containers are great for specific security and data governance requirements. Form Recognizer features are supported by six Form Recognizer feature containers—Layout, Business Card,ID Document, Receipt, Invoice, and Custom (for Receipt, Business Card and ID Document containers you will also need the Read OCR container).

Prerequisites

To get started, you'll need an active Azure account. If you don't have one, you can create a free account.

You'll also need the following to use Form Recognizer containers:

Required Purpose
Familiarity with Docker You should have a basic understanding of Docker concepts, like registries, repositories, containers, and container images, as well as knowledge of basic docker terminology and commands.
Docker Engine installed
  • You need the Docker Engine installed on a host computer. Docker provides packages that configure the Docker environment on macOS, Windows, and Linux. For a primer on Docker and container basics, see the Docker overview.
  • Docker must be configured to allow the containers to connect with and send billing data to Azure.
  • On Windows, Docker must also be configured to support Linux containers.
Form Recognizer resource A single-service Azure Form Recognizer or multi-service Cognitive Services resource in the Azure portal. To use the containers, you must have the associated API key and endpoint URI. Both values are available on the Azure portal Form Recognizer Keys and Endpoint page:
  • {FORM_RECOGNIZER_API_KEY}: one of the two available resource keys.
  • {FORM_RECOGNIZER_ENDPOINT_URI}: the endpoint for the resource used to track billing information.
Computer Vision API resource To process business cards, ID documents, or Receipts, you'll need a Computer Vision resource.
  • You can access the Recognize Text feature as either an Azure resource (the REST API or SDK) or a cognitive-services-recognize-text container. The usual billing fees apply.
  • If you use the cognitive-services-recognize-text container, make sure that your Computer Vision key for the Form Recognizer container is the key specified in the Computer Vision docker run or docker compose command for the cognitive-services-recognize-text container and your billing endpoint is the container's endpoint (for example, http://localhost:5000). If you use both the Computer Vision container and Form Recognizer container together on the same host, they can't both be started with the default port of 5000.

Pass in both the API key and endpoints for your Computer Vision Azure cloud or Cognitive Services container:
  • {COMPUTER_VISION_API_KEY}: one of the two available resource keys.
  • {COMPUTER_VISION_ENDPOINT_URI}: the endpoint for the resource used to track billing information.
Optional Purpose
Azure CLI (command-line interface) The Azure CLI enables you to use a set of online commands to create and manage Azure resources. It is available to install in Windows, macOS, and Linux environments and can be run in a Docker container and Azure Cloud Shell.

Request approval to run the container

Complete and submit the Application for Gated Services form to request approval to run the container.

The form requests information about you, your company, and the user scenario for which you'll use the container. After you submit the form, the Azure Cognitive Services team will review it and email you with a decision.

On the form, you must use an email address associated with an Azure subscription ID. The Azure resource you use to run the container must have been created with the approved Azure subscription ID. Check your email (both inbox and junk folders) for updates on the status of your application from Microsoft. After you're approved, you will be able to run the container after downloading it from the Microsoft Container Registry (MCR), described later in the article.

Host computer requirements

The host is a x64-based computer that runs the Docker container. It can be a computer on your premises or a Docker hosting service in Azure, such as:

Container requirements and recommendations

Required containers

The following table lists the additional supporting container(s) for each Form Recognizer container you download. Please refer to the Billing section for more information.

Feature container Supporting container(s)
Layout None
Business Card Computer Vision Read
ID Document Computer Vision Read
Invoice Layout
Receipt Computer Vision Read
Custom Custom API, Custom Supervised, Layout

Note

The minimum and recommended values are based on Docker limits and not the host machine resources.

Read, Layout, and Prebuilt containers
Container Minimum Recommended
Read 3.2 8 cores, 16-GB memory 8 cores, 24-GB memory
Layout 2.1-preview 8 cores, 16-GB memory 4 core, 8-GB memory
Business Card 2.1-preview 2 cores, 4-GB memory 4 cores, 4-GB memory
ID Document 2.1-preview 1 core, 2-GB memory 2 cores, 2-GB memory
Invoice 2.1-preview 4 cores, 8-GB memory 8 cores, 8-GB memory
Receipt 2.1-preview 4 cores, 8-GB memory 8 cores, 8-GB memory
Custom containers

The following host machine requirements are applicable to train and analyze requests:

Container Minimum Recommended
Custom API 0.5 cores, 0.5-GB memory 1 cores, 1-GB memory
Custom Supervised 4 cores, 2-GB memory 8 cores, 4-GB memory

If you are only making analyze calls, the host machine requirements are as follows:

Container Minimum Recommended
Custom Supervised (Analyze) 1 core, 0.5-GB 2 cores, 1-GB memory
  • Each core must be at least 2.6 gigahertz (GHz) or faster.
  • Core and memory correspond to the --cpus and --memory settings, which are used as part of the docker compose or docker run command.

Tip

You can use the docker images command to list your downloaded container images. For example, the following command lists the ID, repository, and tag of each downloaded container image, formatted as a table:

docker images --format "table {{.ID}}\t{{.Repository}}\t{{.Tag}}"

IMAGE ID         REPOSITORY                TAG
<image-id>       <repository-path/name>    <tag-name>

Run the container with the docker-compose up command

  • Replace the {ENDPOINT_URI} and {API_KEY} values with your resource Endpoint URI and the API Key from the Azure resource page.

    Screenshot: Azure portal keys and endpoint page.

  • Ensure that the EULA value is set to "accept".

  • The EULA, Billing, and ApiKey values must be specified; otherwise the container won't start.

Important

The subscription keys are used to access your Form Recognizer resource. Do not share your keys. Store them securely, for example, using Azure Key Vault. We also recommend regenerating these keys regularly. Only one key is necessary to make an API call. When regenerating the first key, you can use the second key for continued access to the service.

Below is a self-contained docker compose example to run the Form Recognizer Layout container. With docker compose, you use a YAML file to configure your application’s services. Then, with docker-compose up command, you create and start all the services from your configuration. Enter {FORM_RECOGNIZER_ENDPOINT_URI} and {{FORM_RECOGNIZER_API_KEY} values for your Layout container instance.

version: "3.9"
services:
azure-cognitive-service-layout:
    container_name: azure-cognitive-service-layout
    image: mcr.microsoft.com/azure-cognitive-services/form-recognizer/layout
    environment:
      - EULA=accept
      - billing={FORM_RECOGNIZER_ENDPOINT_URI}
      - apikey={FORM_RECOGNIZER_API_KEY}
    ports:
      - "5000"
    networks:
      - ocrvnet
networks:
  ocrvnet:
    driver: bridge

Now, you can start the service with the docker compose command:

docker-compose up

Validate that the service is running

There are several ways to validate that the container is running:

  • The container provides a homepage at \ as a visual validation that the container is running.

  • You can open your favorite web browser and navigate to the external IP address and exposed port of the container in question. Use the various request URLs below to validate the container is running. The example request URLs listed below are http://localhost:5000, but your specific container may vary. Keep in mind that you're navigating to your container's External IP address and exposed port.

    Request URL Purpose
    http://localhost:5000/ The container provides a home page.
    http://localhost:5000/ready Requested with GET, this provides a verification that the container is ready to accept a query against the model. This request can be used for Kubernetes liveness and readiness probes.
    http://localhost:5000/status Requested with GET, this verifies if the api-key used to start the container is valid without causing an endpoint query. This request can be used for Kubernetes liveness and readiness probes.
    http://localhost:5000/swagger The container provides a full set of documentation for the endpoints and a Try it out feature. With this feature, you can enter your settings into a web-based HTML form and make the query without having to write any code. After the query returns, an example CURL command is provided to demonstrate the HTTP headers and body format that's required.

Screenshot: Azure container welcome page.

Stop the containers

To stop the containers, use the following command:

docker-compose down

Billing

The Form Recognizer containers send billing information to Azure by using a Form Recognizer resource on your Azure account.

Queries to the container are billed at the pricing tier of the Azure resource that's used for the ApiKey. You will be billed for each container instance used to process your documents and images. Thus, If you use the business card feature, you will be billed for the Form Recognizer BusinessCard and Compuer Vision Read container instances. For the invoice feature, you will be billed for the Form Recognizer Invoice and Layout container instances. See, Form Recognizer and Computer Vision Read feature container pricing.

Azure Cognitive Services containers aren't licensed to run without being connected to the metering / billing endpoint. You must enable the containers to communicate billing information with the billing endpoint at all times. Cognitive Services containers don't send customer data, such as the image or text that's being analyzed, to Microsoft.

Connect to Azure

The container needs the billing argument values to run. These values allow the container to connect to the billing endpoint. The container reports usage about every 10 to 15 minutes. If the container doesn't connect to Azure within the allowed time window, the container continues to run but doesn't serve queries until the billing endpoint is restored. The connection is attempted 10 times at the same time interval of 10 to 15 minutes. If it can't connect to the billing endpoint within the 10 tries, the container stops serving requests. See the Cognitive Services container FAQ for an example of the information sent to Microsoft for billing.

Billing arguments

The docker-compose up command will start the container when all three of the following options are provided with valid values:

Option Description
ApiKey The API key of the Cognitive Services resource that's used to track billing information.
The value of this option must be set to an API key for the provisioned resource that's specified in Billing.
Billing The endpoint of the Cognitive Services resource that's used to track billing information.
The value of this option must be set to the endpoint URI of a provisioned Azure resource.
Eula Indicates that you accepted the license for the container.
The value of this option must be set to accept.

For more information about these options, see Configure containers.

Summary

That's it! In this article, you learned concepts and workflows for downloading, installing, and running Form Recognizer containers. In summary:

  • Form Recognizer provides seven Linux containers for Docker.
  • Container images are downloaded from mcr.
  • Container images run in Docker.
  • You must specify the billing information when you instantiate a container.

Important

Cognitive Services containers are not licensed to run without being connected to Azure for metering. Customers need to enable the containers to communicate billing information with the metering service at all times. Cognitive Services containers do not send customer data (for example, the image or text that is being analyzed) to Microsoft.

Next steps