Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  
Deprecated in [API level 37](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# Builder

*** ** * ** ***

```
class Builder
```

|---|---|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||
| ↳ | [android.adservices.ondevicepersonalization.InferenceInput.Builder](https://developer.android.com/reference/kotlin/android/adservices/ondevicepersonalization/InferenceInput.Builder#) |

*** ** * ** ***

> [!CAUTION]
> **This class was deprecated in API level 37.**
>
> The ODP APIs are deprecated and will not be supported in future Android releases. There is no direct replacement API available. Developers currently integrated with these APIs must cease further integration efforts. For comprehensive details regarding this deprecation and the future roadmap of Privacy Sandbox on Android, please consult the official Privacy Sandbox developer documentation and announcements: <https://privacysandbox.google.com>

A builder for `https://developer.android.com/reference/kotlin/android/adservices/ondevicepersonalization/InferenceInput`

## Summary

| Public constructors ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/adservices/ondevicepersonalization/InferenceInput.Builder#Builder(android.adservices.ondevicepersonalization.InferenceInput.Params,%20kotlin.ByteArray)(params: https://developer.android.com/reference/kotlin/android/adservices/ondevicepersonalization/InferenceInput.Params, inputData: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)` Creates a new Builder with provided runtime parameters and input data. |
| `https://developer.android.com/reference/kotlin/android/adservices/ondevicepersonalization/InferenceInput.Builder#Builder(android.adservices.ondevicepersonalization.InferenceInput.Params,%20kotlin.Array,%20android.adservices.ondevicepersonalization.InferenceOutput)(params: https://developer.android.com/reference/kotlin/android/adservices/ondevicepersonalization/InferenceInput.Params, inputData: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html!>, expectedOutputStructure: https://developer.android.com/reference/kotlin/android/adservices/ondevicepersonalization/InferenceOutput)` Note: use `https://developer.android.com/reference/kotlin/android/adservices/ondevicepersonalization/InferenceInput.Builder#Builder(android.adservices.ondevicepersonalization.InferenceInput.Params,%20kotlin.ByteArray)` instead. |

| Public methods ||
|---|---|
| [InferenceInput](https://developer.android.com/reference/kotlin/android/adservices/ondevicepersonalization/InferenceInput) | `https://developer.android.com/reference/kotlin/android/adservices/ondevicepersonalization/InferenceInput.Builder#build()()` Builds the instance. |
| [InferenceInput.Builder](https://developer.android.com/reference/kotlin/android/adservices/ondevicepersonalization/InferenceInput.Builder#) | `https://developer.android.com/reference/kotlin/android/adservices/ondevicepersonalization/InferenceInput.Builder#setBatchSize(kotlin.Int)(value: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` The number of input examples. |
| [InferenceInput.Builder](https://developer.android.com/reference/kotlin/android/adservices/ondevicepersonalization/InferenceInput.Builder#) | `https://developer.android.com/reference/kotlin/android/adservices/ondevicepersonalization/InferenceInput.Builder#setExpectedOutputStructure(android.adservices.ondevicepersonalization.InferenceOutput)(value: https://developer.android.com/reference/kotlin/android/adservices/ondevicepersonalization/InferenceOutput)` The empty InferenceOutput representing the expected output structure. |
| [InferenceInput.Builder](https://developer.android.com/reference/kotlin/android/adservices/ondevicepersonalization/InferenceInput.Builder#) | `https://developer.android.com/reference/kotlin/android/adservices/ondevicepersonalization/InferenceInput.Builder#setInputData(kotlin.ByteArray)(value: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)` A byte array that holds input data. |
| [InferenceInput.Builder](https://developer.android.com/reference/kotlin/android/adservices/ondevicepersonalization/InferenceInput.Builder#) | `https://developer.android.com/reference/kotlin/android/adservices/ondevicepersonalization/InferenceInput.Builder#setInputData(kotlin.Any)(vararg value: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html!)` Note: use `https://developer.android.com/reference/kotlin/android/adservices/ondevicepersonalization/InferenceInput.Builder#setInputData(kotlin.ByteArray)` instead. |
| [InferenceInput.Builder](https://developer.android.com/reference/kotlin/android/adservices/ondevicepersonalization/InferenceInput.Builder#) | `https://developer.android.com/reference/kotlin/android/adservices/ondevicepersonalization/InferenceInput.Builder#setParams(android.adservices.ondevicepersonalization.InferenceInput.Params)(value: https://developer.android.com/reference/kotlin/android/adservices/ondevicepersonalization/InferenceInput.Params)` The configuration that controls runtime interpreter behavior. |

## Public constructors

### Builder

Added in [API level 36.1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
Builder(
    params: InferenceInput.Params, 
    inputData: ByteArray)
```

Creates a new Builder with provided runtime parameters and input data.

For LiteRT, inputData field is mapped to inputs of runForMultipleInputsOutputs: https://www.tensorflow.org/lite/api_docs/java/org/tensorflow/lite/InterpreterApi#parameters_9 For example, if a model takes multiple inputs:

```kotlin
<code>String[] input0 = {"foo", "bar"}; // string tensor shape is [2].
  int[] input1 = new int[]{3, 2, 1}; // int tensor shape is [3].
  Object[] data = {input0, input1, ...};
  byte[] inputData = serializeObject(data);
  </code>
```

For Executorch, inputData field is mapped to a serialized EValue array.

| Parameters ||
|---|---|
| `params` | [InferenceInput.Params](https://developer.android.com/reference/kotlin/android/adservices/ondevicepersonalization/InferenceInput.Params): configuration that controls runtime interpreter behavior. This value cannot be `null`. |
| `inputData` | [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html): byte array that holds serialized input data. This value cannot be `null`. |

### Builder

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
Builder(
    params: InferenceInput.Params, 
    inputData: Array<Any!>, 
    expectedOutputStructure: InferenceOutput)
```

Note: use `https://developer.android.com/reference/kotlin/android/adservices/ondevicepersonalization/InferenceInput.Builder#Builder(android.adservices.ondevicepersonalization.InferenceInput.Params,%20kotlin.ByteArray)` instead.

Creates a new Builder for LiteRT model inference input. For LiteRT, inputData field is mapped to inputs of runForMultipleInputsOutputs: https://www.tensorflow.org/lite/api_docs/java/org/tensorflow/lite/InterpreterApi#parameters_9 The inputs should be in the same order as inputs \* of the model. \*

For example, if a model takes multiple inputs: \*

```kotlin
<code>String[] input0 = {"foo", "bar"}; // string tensor shape is [2].
  int[] input1 = new int[]{3, 2, 1}; // int tensor shape is [3].
  Object[] inputData = {input0, input1, ...};
  </code>
```
For LiteRT, the inference code will verify whether the expected output structure matches model output signature.

If a model produce string tensors:

```kotlin
<code>String[] output = new String[3][2];  // Output tensor shape is [3, 2].
  HashMap&lt;Integer, Object&gt; outputs = new HashMap&lt;&gt;();
  outputs.put(0, output);
  expectedOutputStructure = new InferenceOutput.Builder().setDataOutputs(outputs).build();
 
  </code>
```

| Parameters ||
|---|---|
| `params` | [InferenceInput.Params](https://developer.android.com/reference/kotlin/android/adservices/ondevicepersonalization/InferenceInput.Params): configuration that controls runtime interpreter behavior. This value cannot be `null`. |
| `inputData` | [Array](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html)\<[Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)!\>: an array of input data. This value cannot be `null`. |
| `expectedOutputStructure` | [InferenceOutput](https://developer.android.com/reference/kotlin/android/adservices/ondevicepersonalization/InferenceOutput): an empty InferenceOutput representing the expected output structure. This value cannot be `null`. |

## Public methods

### build

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun build(): InferenceInput
```

**Deprecated:** *Deprecated in Java.*

Builds the instance. This builder should not be touched after calling this!

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/adservices/ondevicepersonalization/InferenceInput` | This value cannot be `null`. |

### setBatchSize

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun setBatchSize(value: Int): InferenceInput.Builder
```

**Deprecated:** *Deprecated in Java.*

The number of input examples. Adopter can set this field to run batching inference. The batch size is 1 by default. The batch size should match the input data size.

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/adservices/ondevicepersonalization/InferenceInput.Builder#` | This value cannot be `null`. |

### setExpectedOutputStructure

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun setExpectedOutputStructure(value: InferenceOutput): InferenceInput.Builder
```

**Deprecated:** *Deprecated in Java.*

The empty InferenceOutput representing the expected output structure. It's only required by LiteRT model. For LiteRT, the inference code will verify whether this expected output structure matches model output signature.

If a model produce string tensors:

```kotlin
<code>String[] output = new String[3][2];  // Output tensor shape is [3, 2].
  HashMap&lt;Integer, Object&gt; outputs = new HashMap&lt;&gt;();
  outputs.put(0, output);
  expectedOutputStructure = new InferenceOutput.Builder().setDataOutputs(outputs).build();
  </code>
```

| Parameters ||
|---|---|
| `value` | [InferenceOutput](https://developer.android.com/reference/kotlin/android/adservices/ondevicepersonalization/InferenceOutput): This value cannot be `null`. |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/adservices/ondevicepersonalization/InferenceInput.Builder#` | This value cannot be `null`. |

### setInputData

Added in [API level 36.1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  
Deprecated in [API level 37](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun setInputData(value: ByteArray): InferenceInput.Builder
```

**Deprecated:** *Deprecated in Java.*

A byte array that holds input data. The inputs should be in the same order as inputs of the model.

For LiteRT, this field is mapped to inputs of runForMultipleInputsOutputs: https://www.tensorflow.org/lite/api_docs/java/org/tensorflow/lite/InterpreterApi#parameters_9

```kotlin
<code>String[] input0 = {"foo", "bar"}; // string tensor shape is [2].
  int[] input1 = new int[]{3, 2, 1}; // int tensor shape is [3].
  Object[] data = {input0, input1, ...};
  byte[] inputData = serializeObject(data);
  </code>
```

For Executorch model, this field is a serialized EValue array.

| Parameters ||
|---|---|
| `value` | [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html): This value cannot be `null`. |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/adservices/ondevicepersonalization/InferenceInput.Builder#` | This value cannot be `null`. |

### setInputData

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun setInputData(vararg value: Any!): InferenceInput.Builder
```

**Deprecated:** *Deprecated in Java.*

Note: use `https://developer.android.com/reference/kotlin/android/adservices/ondevicepersonalization/InferenceInput.Builder#setInputData(kotlin.ByteArray)` instead.

An array of input data. The inputs should be in the same order as inputs of the model.

For example, if a model takes multiple inputs:

```kotlin
<code>String[] input0 = {"foo", "bar"}; // string tensor shape is [2].
  int[] input1 = new int[]{3, 2, 1}; // int tensor shape is [3].
  Object[] inputData = {input0, input1, ...};
  </code>
```
For LiteRT, this field is mapped to inputs of runForMultipleInputsOutputs: https://www.tensorflow.org/lite/api_docs/java/org/tensorflow/lite/InterpreterApi#parameters_9

| Parameters ||
|---|---|
| `value` | [Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)!: This value cannot be `null`. |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/adservices/ondevicepersonalization/InferenceInput.Builder#` | This value cannot be `null`. |

### setParams

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun setParams(value: InferenceInput.Params): InferenceInput.Builder
```

**Deprecated:** *Deprecated in Java.*

The configuration that controls runtime interpreter behavior.

| Parameters ||
|---|---|
| `value` | [InferenceInput.Params](https://developer.android.com/reference/kotlin/android/adservices/ondevicepersonalization/InferenceInput.Params): This value cannot be `null`. |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/adservices/ondevicepersonalization/InferenceInput.Builder#` | This value cannot be `null`. |