Skip to main content

Advanced configuration

The Client#run method allows you to select a custom output task and parameters for your deployment using the taskName and parameters attributes:

import {Client} from "@ikomia/ikclient";

const client = new Client({
url: "https://your.scale.endpoint.url",
});

const results = await client.run({
image: "https://production-media.paperswithcode.com/datasets/Foggy_Cityscapes-0000003414-fb7dc023.jpg",
taskName: "infer_mmlab_segmentation",
parameters: {
model_config: "maskformer_r50-d32_8xb2-160k_ade20k-512x512"
}
});

If you need to select outputs, or set parameters for intermediary tasks, you can use the Context API which allows more flexibility in configuring your deployment:

const context = await client.buildContext();

A Context object holds a specific configuration for your deployment which can be reused across multiple runs.

Using the Context#setOutput method, you can select multiple outputs from different tasks in your workflow:

// Select outputs 1 from algorithm infer_grounding_dino
context.setOutput("infer_grounding_dino", 1);

// Select ALL outputs from algorithm infer_segment_anything
context.setOutput("infer_segment_anything");

Outputs are zero indexed, so context.setOutput("infer_grounding_dino", 1) will select the second output from the infer_grounding_dino task.

In a similar way, you can set parameters for any task using the Context#setParameters method:

// Set parameters for algorithm infer_grounding_dino
context.setParameters("infer_grounding_dino", {
model_name: "Swin-T",
prompt: "person . car . bicycle .",
});

// Set parameters for algorithm infer_segment_anything
context.setParameters("infer_segment_anything", {
model_name: "vit_h"
});

You can then pass the Context object to the Client#run method to use the custom configuration:

const results = await client.run({
context,
image: "https://production-media.paperswithcode.com/datasets/Foggy_Cityscapes-0000003414-fb7dc023.jpg"
});
warning

When the context attribute is passed, you can't pass the taskName and/or parameters attributes in the Client#run method as their values may be conflicting. This will results in a TypeError. It is also required to define at least one output using the Context#setOutput method.