Skip to content

Custom training#

Now that we trained our first model with the train API, you might wonder if there is any knobs that can be tweaked to improve the performance, like choosing a model with more parameters, or training for more epochs. This is possible with our custom training API.

Requirements#

To setup a custom training job, you will need to provide the following information:

We will use an object detection project as an example for the rest of this guide.

The following is a boilerplate setup we will use to execute the examples in the next sections:

import requests

host = "https://api.landing.ai"
api_key = "YOUR_API_KEY"
project_id = "YOUR_PROJECT_ID"

# we can reuse this session accross multiple calls
session = requests.Session()
session.headers.update({ "apikey": api_key })

Get the available architectures for custom training#

LandingLens provides several model architectures that can be used for training. To get such list, we can use our model architectures API

response = session.get(
    f"{host}/v1/projects/{project_id}/train/architectures",
)
print(reponse.json()["data"])

Depending on the project type, a different list of model names will be returned. Since this example assumes an object detection project, we can expect the following response:

[
    { "name": "RtmDet-[9M]" },
    { "name": "RepPoints-[20M]" },
    { "name": "RepPoints-[37M]" }
]

This means that we provide 3 different model architectures for training custom object detection models. For the next steps, we will assume we want to train a custom model using the RtmDet-[9M] architecture.

Note

It is beyond the scope of this guide to describe model architectures into detail. However, it is important to know that number between the braces indicates the number of trainable parameters (the bigger the number, the bigger the model).

Create the training job#

payload = {
    # the name for your custom model that will be shown in the UI
    "name": "my_custom_model",
    "model": {
        "architecture": "RtmDet-[9M]",
        # currently the only hyperparam we allow to set is number of epochs
        "hyperParams": {
            "epochs": 50,
        },
    },
    "transforms": {
        # preprocessing should contain at least one of resize/rescaleWithPadding
        "preprocessing": [
            {
                "resize": {
                    "height": 896,
                    "width": 1280,
                },
            },
        ],
        "augmentations": [
            {
                "horizontalFlip": {
                    "p": 0.5,
                },
            },
        ],
    },
}

# we can now send the request to the train API using as json payload
response = session.post(
    f"{host}/v1/projects/{project_id}/train",
    json=payload,
)

if response.status_code == 200:
    data = response.json()
    training_id = data["data"]["trainingId"]
    print(f"Training started successfully! Training ID: {training_id}")
    # Store the training ID for future use (e.g., status monitoring)
else:
    print(f"Error during training request: {response.text}")

Restrictions#

  • Epoch value ranges currently depend on project type (this may change in the future)
    • Classification: 10-200
    • Object Detection: 10-250
    • Segmentation: 10-200
  • You must always add at least one preprocessing transform up to two transforms