
software.amazon.awssdk.services.sagemaker.model.InputConfig Maven / Gradle / Ivy
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package software.amazon.awssdk.services.sagemaker.model;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Function;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.core.SdkField;
import software.amazon.awssdk.core.SdkPojo;
import software.amazon.awssdk.core.protocol.MarshallLocation;
import software.amazon.awssdk.core.protocol.MarshallingType;
import software.amazon.awssdk.core.traits.LocationTrait;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
/**
*
* Contains information about the location of input model artifacts, the name and shape of the expected data inputs, and
* the framework in which the model was trained.
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class InputConfig implements SdkPojo, Serializable, ToCopyableBuilder {
private static final SdkField S3_URI_FIELD = SdkField. builder(MarshallingType.STRING).memberName("S3Uri")
.getter(getter(InputConfig::s3Uri)).setter(setter(Builder::s3Uri))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("S3Uri").build()).build();
private static final SdkField DATA_INPUT_CONFIG_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("DataInputConfig").getter(getter(InputConfig::dataInputConfig)).setter(setter(Builder::dataInputConfig))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("DataInputConfig").build()).build();
private static final SdkField FRAMEWORK_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("Framework").getter(getter(InputConfig::frameworkAsString)).setter(setter(Builder::framework))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Framework").build()).build();
private static final SdkField FRAMEWORK_VERSION_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("FrameworkVersion").getter(getter(InputConfig::frameworkVersion))
.setter(setter(Builder::frameworkVersion))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("FrameworkVersion").build()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(S3_URI_FIELD,
DATA_INPUT_CONFIG_FIELD, FRAMEWORK_FIELD, FRAMEWORK_VERSION_FIELD));
private static final long serialVersionUID = 1L;
private final String s3Uri;
private final String dataInputConfig;
private final String framework;
private final String frameworkVersion;
private InputConfig(BuilderImpl builder) {
this.s3Uri = builder.s3Uri;
this.dataInputConfig = builder.dataInputConfig;
this.framework = builder.framework;
this.frameworkVersion = builder.frameworkVersion;
}
/**
*
* The S3 path where the model artifacts, which result from model training, are stored. This path must point to a
* single gzip compressed tar archive (.tar.gz suffix).
*
*
* @return The S3 path where the model artifacts, which result from model training, are stored. This path must point
* to a single gzip compressed tar archive (.tar.gz suffix).
*/
public final String s3Uri() {
return s3Uri;
}
/**
*
* Specifies the name and shape of the expected data inputs for your trained model with a JSON dictionary form. The
* data inputs are InputConfig$Framework specific.
*
*
* -
*
* TensorFlow
: You must specify the name and shape (NHWC format) of the expected data inputs using a
* dictionary format for your trained model. The dictionary formats required for the console and CLI are different.
*
*
* -
*
* Examples for one input:
*
*
* -
*
* If using the console, {"input":[1,1024,1024,3]}
*
*
* -
*
* If using the CLI, {\"input\":[1,1024,1024,3]}
*
*
*
*
* -
*
* Examples for two inputs:
*
*
* -
*
* If using the console, {"data1": [1,28,28,1], "data2":[1,28,28,1]}
*
*
* -
*
* If using the CLI, {\"data1\": [1,28,28,1], \"data2\":[1,28,28,1]}
*
*
*
*
*
*
* -
*
* KERAS
: You must specify the name and shape (NCHW format) of expected data inputs using a dictionary
* format for your trained model. Note that while Keras model artifacts should be uploaded in NHWC (channel-last)
* format, DataInputConfig
should be specified in NCHW (channel-first) format. The dictionary formats
* required for the console and CLI are different.
*
*
* -
*
* Examples for one input:
*
*
* -
*
* If using the console, {"input_1":[1,3,224,224]}
*
*
* -
*
* If using the CLI, {\"input_1\":[1,3,224,224]}
*
*
*
*
* -
*
* Examples for two inputs:
*
*
* -
*
* If using the console, {"input_1": [1,3,224,224], "input_2":[1,3,224,224]}
*
*
* -
*
* If using the CLI, {\"input_1\": [1,3,224,224], \"input_2\":[1,3,224,224]}
*
*
*
*
*
*
* -
*
* MXNET/ONNX/DARKNET
: You must specify the name and shape (NCHW format) of the expected data inputs in
* order using a dictionary format for your trained model. The dictionary formats required for the console and CLI
* are different.
*
*
* -
*
* Examples for one input:
*
*
* -
*
* If using the console, {"data":[1,3,1024,1024]}
*
*
* -
*
* If using the CLI, {\"data\":[1,3,1024,1024]}
*
*
*
*
* -
*
* Examples for two inputs:
*
*
* -
*
* If using the console, {"var1": [1,1,28,28], "var2":[1,1,28,28]}
*
*
* -
*
* If using the CLI, {\"var1\": [1,1,28,28], \"var2\":[1,1,28,28]}
*
*
*
*
*
*
* -
*
* PyTorch
: You can either specify the name and shape (NCHW format) of expected data inputs in order
* using a dictionary format for your trained model or you can specify the shape only using a list format. The
* dictionary formats required for the console and CLI are different. The list formats for the console and CLI are
* the same.
*
*
* -
*
* Examples for one input in dictionary format:
*
*
* -
*
* If using the console, {"input0":[1,3,224,224]}
*
*
* -
*
* If using the CLI, {\"input0\":[1,3,224,224]}
*
*
*
*
* -
*
* Example for one input in list format: [[1,3,224,224]]
*
*
* -
*
* Examples for two inputs in dictionary format:
*
*
* -
*
* If using the console, {"input0":[1,3,224,224], "input1":[1,3,224,224]}
*
*
* -
*
* If using the CLI, {\"input0\":[1,3,224,224], \"input1\":[1,3,224,224]}
*
*
*
*
* -
*
* Example for two inputs in list format: [[1,3,224,224], [1,3,224,224]]
*
*
*
*
* -
*
* XGBOOST
: input data name and shape are not needed.
*
*
*
*
* DataInputConfig
supports the following parameters for CoreML
* OutputConfig$TargetDevice (ML Model format):
*
*
* -
*
* shape
: Input shape, for example {"input_1": {"shape": [1,224,224,3]}}
. In addition to
* static input shapes, CoreML converter supports Flexible input shapes:
*
*
* -
*
* Range Dimension. You can use the Range Dimension feature if you know the input shape will be within some specific
* interval in that dimension, for example: {"input_1": {"shape": ["1..10", 224, 224, 3]}}
*
*
* -
*
* Enumerated shapes. Sometimes, the models are trained to work only on a select set of inputs. You can enumerate
* all supported input shapes, for example:
* {"input_1": {"shape": [[1, 224, 224, 3], [1, 160, 160, 3]]}}
*
*
*
*
* -
*
* default_shape
: Default input shape. You can set a default shape during conversion for both Range
* Dimension and Enumerated Shapes. For example
* {"input_1": {"shape": ["1..10", 224, 224, 3], "default_shape": [1, 224, 224, 3]}}
*
*
* -
*
* type
: Input type. Allowed values: Image
and Tensor
. By default, the
* converter generates an ML Model with inputs of type Tensor (MultiArray). User can set input type to be Image.
* Image input type requires additional input parameters such as bias
and scale
.
*
*
* -
*
* bias
: If the input type is an Image, you need to provide the bias vector.
*
*
* -
*
* scale
: If the input type is an Image, you need to provide a scale factor.
*
*
*
*
* CoreML ClassifierConfig
parameters can be specified using OutputConfig$CompilerOptions.
* CoreML converter supports Tensorflow and PyTorch models. CoreML conversion examples:
*
*
* -
*
* Tensor type input:
*
*
* -
*
* "DataInputConfig": {"input_1": {"shape": [[1,224,224,3], [1,160,160,3]], "default_shape": [1,224,224,3]}}
*
*
*
*
* -
*
* Tensor type input without input name (PyTorch):
*
*
* -
*
* "DataInputConfig": [{"shape": [[1,3,224,224], [1,3,160,160]], "default_shape": [1,3,224,224]}]
*
*
*
*
* -
*
* Image type input:
*
*
* -
*
* "DataInputConfig": {"input_1": {"shape": [[1,224,224,3], [1,160,160,3]], "default_shape": [1,224,224,3], "type": "Image", "bias": [-1,-1,-1], "scale": 0.007843137255}}
*
*
* -
*
* "CompilerOptions": {"class_labels": "imagenet_labels_1000.txt"}
*
*
*
*
* -
*
* Image type input without input name (PyTorch):
*
*
* -
*
* "DataInputConfig": [{"shape": [[1,3,224,224], [1,3,160,160]], "default_shape": [1,3,224,224], "type": "Image", "bias": [-1,-1,-1], "scale": 0.007843137255}]
*
*
* -
*
* "CompilerOptions": {"class_labels": "imagenet_labels_1000.txt"}
*
*
*
*
*
*
* Depending on the model format, DataInputConfig
requires the following parameters for
* ml_eia2
OutputConfig:TargetDevice.
*
*
* -
*
* For TensorFlow models saved in the SavedModel format, specify the input names from signature_def_key
* and the input model shapes for DataInputConfig
. Specify the signature_def_key
in OutputConfig:CompilerOptions
if the model does not use TensorFlow's default signature def
* key. For example:
*
*
* -
*
* "DataInputConfig": {"inputs": [1, 224, 224, 3]}
*
*
* -
*
* "CompilerOptions": {"signature_def_key": "serving_custom"}
*
*
*
*
* -
*
* For TensorFlow models saved as a frozen graph, specify the input tensor names and shapes in
* DataInputConfig
and the output tensor names for output_names
in OutputConfig:CompilerOptions
. For example:
*
*
* -
*
* "DataInputConfig": {"input_tensor:0": [1, 224, 224, 3]}
*
*
* -
*
* "CompilerOptions": {"output_names": ["output_tensor:0"]}
*
*
*
*
*
*
* @return Specifies the name and shape of the expected data inputs for your trained model with a JSON dictionary
* form. The data inputs are InputConfig$Framework specific.
*
* -
*
* TensorFlow
: You must specify the name and shape (NHWC format) of the expected data inputs
* using a dictionary format for your trained model. The dictionary formats required for the console and CLI
* are different.
*
*
* -
*
* Examples for one input:
*
*
* -
*
* If using the console, {"input":[1,1024,1024,3]}
*
*
* -
*
* If using the CLI, {\"input\":[1,1024,1024,3]}
*
*
*
*
* -
*
* Examples for two inputs:
*
*
* -
*
* If using the console, {"data1": [1,28,28,1], "data2":[1,28,28,1]}
*
*
* -
*
* If using the CLI, {\"data1\": [1,28,28,1], \"data2\":[1,28,28,1]}
*
*
*
*
*
*
* -
*
* KERAS
: You must specify the name and shape (NCHW format) of expected data inputs using a
* dictionary format for your trained model. Note that while Keras model artifacts should be uploaded in
* NHWC (channel-last) format, DataInputConfig
should be specified in NCHW (channel-first)
* format. The dictionary formats required for the console and CLI are different.
*
*
* -
*
* Examples for one input:
*
*
* -
*
* If using the console, {"input_1":[1,3,224,224]}
*
*
* -
*
* If using the CLI, {\"input_1\":[1,3,224,224]}
*
*
*
*
* -
*
* Examples for two inputs:
*
*
* -
*
* If using the console, {"input_1": [1,3,224,224], "input_2":[1,3,224,224]}
*
*
* -
*
* If using the CLI, {\"input_1\": [1,3,224,224], \"input_2\":[1,3,224,224]}
*
*
*
*
*
*
* -
*
* MXNET/ONNX/DARKNET
: You must specify the name and shape (NCHW format) of the expected data
* inputs in order using a dictionary format for your trained model. The dictionary formats required for the
* console and CLI are different.
*
*
* -
*
* Examples for one input:
*
*
* -
*
* If using the console, {"data":[1,3,1024,1024]}
*
*
* -
*
* If using the CLI, {\"data\":[1,3,1024,1024]}
*
*
*
*
* -
*
* Examples for two inputs:
*
*
* -
*
* If using the console, {"var1": [1,1,28,28], "var2":[1,1,28,28]}
*
*
* -
*
* If using the CLI, {\"var1\": [1,1,28,28], \"var2\":[1,1,28,28]}
*
*
*
*
*
*
* -
*
* PyTorch
: You can either specify the name and shape (NCHW format) of expected data inputs in
* order using a dictionary format for your trained model or you can specify the shape only using a list
* format. The dictionary formats required for the console and CLI are different. The list formats for the
* console and CLI are the same.
*
*
* -
*
* Examples for one input in dictionary format:
*
*
* -
*
* If using the console, {"input0":[1,3,224,224]}
*
*
* -
*
* If using the CLI, {\"input0\":[1,3,224,224]}
*
*
*
*
* -
*
* Example for one input in list format: [[1,3,224,224]]
*
*
* -
*
* Examples for two inputs in dictionary format:
*
*
* -
*
* If using the console, {"input0":[1,3,224,224], "input1":[1,3,224,224]}
*
*
* -
*
* If using the CLI, {\"input0\":[1,3,224,224], \"input1\":[1,3,224,224]}
*
*
*
*
* -
*
* Example for two inputs in list format: [[1,3,224,224], [1,3,224,224]]
*
*
*
*
* -
*
* XGBOOST
: input data name and shape are not needed.
*
*
*
*
* DataInputConfig
supports the following parameters for CoreML
* OutputConfig$TargetDevice (ML Model format):
*
*
* -
*
* shape
: Input shape, for example {"input_1": {"shape": [1,224,224,3]}}
. In
* addition to static input shapes, CoreML converter supports Flexible input shapes:
*
*
* -
*
* Range Dimension. You can use the Range Dimension feature if you know the input shape will be within some
* specific interval in that dimension, for example:
* {"input_1": {"shape": ["1..10", 224, 224, 3]}}
*
*
* -
*
* Enumerated shapes. Sometimes, the models are trained to work only on a select set of inputs. You can
* enumerate all supported input shapes, for example:
* {"input_1": {"shape": [[1, 224, 224, 3], [1, 160, 160, 3]]}}
*
*
*
*
* -
*
* default_shape
: Default input shape. You can set a default shape during conversion for both
* Range Dimension and Enumerated Shapes. For example
* {"input_1": {"shape": ["1..10", 224, 224, 3], "default_shape": [1, 224, 224, 3]}}
*
*
* -
*
* type
: Input type. Allowed values: Image
and Tensor
. By default,
* the converter generates an ML Model with inputs of type Tensor (MultiArray). User can set input type to
* be Image. Image input type requires additional input parameters such as bias
and
* scale
.
*
*
* -
*
* bias
: If the input type is an Image, you need to provide the bias vector.
*
*
* -
*
* scale
: If the input type is an Image, you need to provide a scale factor.
*
*
*
*
* CoreML ClassifierConfig
parameters can be specified using
* OutputConfig$CompilerOptions. CoreML converter supports Tensorflow and PyTorch models. CoreML
* conversion examples:
*
*
* -
*
* Tensor type input:
*
*
* -
*
* "DataInputConfig": {"input_1": {"shape": [[1,224,224,3], [1,160,160,3]], "default_shape": [1,224,224,3]}}
*
*
*
*
* -
*
* Tensor type input without input name (PyTorch):
*
*
* -
*
* "DataInputConfig": [{"shape": [[1,3,224,224], [1,3,160,160]], "default_shape": [1,3,224,224]}]
*
*
*
*
* -
*
* Image type input:
*
*
* -
*
* "DataInputConfig": {"input_1": {"shape": [[1,224,224,3], [1,160,160,3]], "default_shape": [1,224,224,3], "type": "Image", "bias": [-1,-1,-1], "scale": 0.007843137255}}
*
*
* -
*
* "CompilerOptions": {"class_labels": "imagenet_labels_1000.txt"}
*
*
*
*
* -
*
* Image type input without input name (PyTorch):
*
*
* -
*
* "DataInputConfig": [{"shape": [[1,3,224,224], [1,3,160,160]], "default_shape": [1,3,224,224], "type": "Image", "bias": [-1,-1,-1], "scale": 0.007843137255}]
*
*
* -
*
* "CompilerOptions": {"class_labels": "imagenet_labels_1000.txt"}
*
*
*
*
*
*
* Depending on the model format, DataInputConfig
requires the following parameters for
* ml_eia2
OutputConfig:TargetDevice.
*
*
* -
*
* For TensorFlow models saved in the SavedModel format, specify the input names from
* signature_def_key
and the input model shapes for DataInputConfig
. Specify the
* signature_def_key
in OutputConfig:CompilerOptions
if the model does not use TensorFlow's default signature
* def key. For example:
*
*
* -
*
* "DataInputConfig": {"inputs": [1, 224, 224, 3]}
*
*
* -
*
* "CompilerOptions": {"signature_def_key": "serving_custom"}
*
*
*
*
* -
*
* For TensorFlow models saved as a frozen graph, specify the input tensor names and shapes in
* DataInputConfig
and the output tensor names for output_names
in OutputConfig:CompilerOptions
. For example:
*
*
* -
*
* "DataInputConfig": {"input_tensor:0": [1, 224, 224, 3]}
*
*
* -
*
* "CompilerOptions": {"output_names": ["output_tensor:0"]}
*
*
*
*
*/
public final String dataInputConfig() {
return dataInputConfig;
}
/**
*
* Identifies the framework in which the model was trained. For example: TENSORFLOW.
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #framework} will
* return {@link Framework#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is available from
* {@link #frameworkAsString}.
*
*
* @return Identifies the framework in which the model was trained. For example: TENSORFLOW.
* @see Framework
*/
public final Framework framework() {
return Framework.fromValue(framework);
}
/**
*
* Identifies the framework in which the model was trained. For example: TENSORFLOW.
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #framework} will
* return {@link Framework#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is available from
* {@link #frameworkAsString}.
*
*
* @return Identifies the framework in which the model was trained. For example: TENSORFLOW.
* @see Framework
*/
public final String frameworkAsString() {
return framework;
}
/**
*
* Specifies the framework version to use.
*
*
* This API field is only supported for PyTorch framework versions 1.4
, 1.5
, and
* 1.6
for cloud instance target devices: ml_c4
, ml_c5
, ml_m4
,
* ml_m5
, ml_p2
, ml_p3
, and ml_g4dn
.
*
*
* @return Specifies the framework version to use.
*
* This API field is only supported for PyTorch framework versions 1.4
, 1.5
, and
* 1.6
for cloud instance target devices: ml_c4
, ml_c5
,
* ml_m4
, ml_m5
, ml_p2
, ml_p3
, and ml_g4dn
.
*/
public final String frameworkVersion() {
return frameworkVersion;
}
@Override
public Builder toBuilder() {
return new BuilderImpl(this);
}
public static Builder builder() {
return new BuilderImpl();
}
public static Class extends Builder> serializableBuilderClass() {
return BuilderImpl.class;
}
@Override
public final int hashCode() {
int hashCode = 1;
hashCode = 31 * hashCode + Objects.hashCode(s3Uri());
hashCode = 31 * hashCode + Objects.hashCode(dataInputConfig());
hashCode = 31 * hashCode + Objects.hashCode(frameworkAsString());
hashCode = 31 * hashCode + Objects.hashCode(frameworkVersion());
return hashCode;
}
@Override
public final boolean equals(Object obj) {
return equalsBySdkFields(obj);
}
@Override
public final boolean equalsBySdkFields(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof InputConfig)) {
return false;
}
InputConfig other = (InputConfig) obj;
return Objects.equals(s3Uri(), other.s3Uri()) && Objects.equals(dataInputConfig(), other.dataInputConfig())
&& Objects.equals(frameworkAsString(), other.frameworkAsString())
&& Objects.equals(frameworkVersion(), other.frameworkVersion());
}
/**
* Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be
* redacted from this string using a placeholder value.
*/
@Override
public final String toString() {
return ToString.builder("InputConfig").add("S3Uri", s3Uri()).add("DataInputConfig", dataInputConfig())
.add("Framework", frameworkAsString()).add("FrameworkVersion", frameworkVersion()).build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "S3Uri":
return Optional.ofNullable(clazz.cast(s3Uri()));
case "DataInputConfig":
return Optional.ofNullable(clazz.cast(dataInputConfig()));
case "Framework":
return Optional.ofNullable(clazz.cast(frameworkAsString()));
case "FrameworkVersion":
return Optional.ofNullable(clazz.cast(frameworkVersion()));
default:
return Optional.empty();
}
}
@Override
public final List> sdkFields() {
return SDK_FIELDS;
}
private static Function
*
* -
*
* TensorFlow
: You must specify the name and shape (NHWC format) of the expected data inputs
* using a dictionary format for your trained model. The dictionary formats required for the console and
* CLI are different.
*
*
* -
*
* Examples for one input:
*
*
* -
*
* If using the console, {"input":[1,1024,1024,3]}
*
*
* -
*
* If using the CLI, {\"input\":[1,1024,1024,3]}
*
*
*
*
* -
*
* Examples for two inputs:
*
*
* -
*
* If using the console, {"data1": [1,28,28,1], "data2":[1,28,28,1]}
*
*
* -
*
* If using the CLI, {\"data1\": [1,28,28,1], \"data2\":[1,28,28,1]}
*
*
*
*
*
*
* -
*
* KERAS
: You must specify the name and shape (NCHW format) of expected data inputs using a
* dictionary format for your trained model. Note that while Keras model artifacts should be uploaded in
* NHWC (channel-last) format, DataInputConfig
should be specified in NCHW (channel-first)
* format. The dictionary formats required for the console and CLI are different.
*
*
* -
*
* Examples for one input:
*
*
* -
*
* If using the console, {"input_1":[1,3,224,224]}
*
*
* -
*
* If using the CLI, {\"input_1\":[1,3,224,224]}
*
*
*
*
* -
*
* Examples for two inputs:
*
*
* -
*
* If using the console, {"input_1": [1,3,224,224], "input_2":[1,3,224,224]}
*
*
* -
*
* If using the CLI, {\"input_1\": [1,3,224,224], \"input_2\":[1,3,224,224]}
*
*
*
*
*
*
* -
*
* MXNET/ONNX/DARKNET
: You must specify the name and shape (NCHW format) of the expected
* data inputs in order using a dictionary format for your trained model. The dictionary formats required
* for the console and CLI are different.
*
*
* -
*
* Examples for one input:
*
*
* -
*
* If using the console, {"data":[1,3,1024,1024]}
*
*
* -
*
* If using the CLI, {\"data\":[1,3,1024,1024]}
*
*
*
*
* -
*
* Examples for two inputs:
*
*
* -
*
* If using the console, {"var1": [1,1,28,28], "var2":[1,1,28,28]}
*
*
* -
*
* If using the CLI, {\"var1\": [1,1,28,28], \"var2\":[1,1,28,28]}
*
*
*
*
*
*
* -
*
* PyTorch
: You can either specify the name and shape (NCHW format) of expected data inputs
* in order using a dictionary format for your trained model or you can specify the shape only using a
* list format. The dictionary formats required for the console and CLI are different. The list formats
* for the console and CLI are the same.
*
*
* -
*
* Examples for one input in dictionary format:
*
*
* -
*
* If using the console, {"input0":[1,3,224,224]}
*
*
* -
*
* If using the CLI, {\"input0\":[1,3,224,224]}
*
*
*
*
* -
*
* Example for one input in list format: [[1,3,224,224]]
*
*
* -
*
* Examples for two inputs in dictionary format:
*
*
* -
*
* If using the console, {"input0":[1,3,224,224], "input1":[1,3,224,224]}
*
*
* -
*
* If using the CLI, {\"input0\":[1,3,224,224], \"input1\":[1,3,224,224]}
*
*
*
*
* -
*
* Example for two inputs in list format: [[1,3,224,224], [1,3,224,224]]
*
*
*
*
* -
*
* XGBOOST
: input data name and shape are not needed.
*
*
*
*
* DataInputConfig
supports the following parameters for CoreML
* OutputConfig$TargetDevice (ML Model format):
*
*
* -
*
* shape
: Input shape, for example {"input_1": {"shape": [1,224,224,3]}}
. In
* addition to static input shapes, CoreML converter supports Flexible input shapes:
*
*
* -
*
* Range Dimension. You can use the Range Dimension feature if you know the input shape will be within
* some specific interval in that dimension, for example:
* {"input_1": {"shape": ["1..10", 224, 224, 3]}}
*
*
* -
*
* Enumerated shapes. Sometimes, the models are trained to work only on a select set of inputs. You can
* enumerate all supported input shapes, for example:
* {"input_1": {"shape": [[1, 224, 224, 3], [1, 160, 160, 3]]}}
*
*
*
*
* -
*
* default_shape
: Default input shape. You can set a default shape during conversion for
* both Range Dimension and Enumerated Shapes. For example
* {"input_1": {"shape": ["1..10", 224, 224, 3], "default_shape": [1, 224, 224, 3]}}
*
*
* -
*
* type
: Input type. Allowed values: Image
and Tensor
. By default,
* the converter generates an ML Model with inputs of type Tensor (MultiArray). User can set input type
* to be Image. Image input type requires additional input parameters such as bias
and
* scale
.
*
*
* -
*
* bias
: If the input type is an Image, you need to provide the bias vector.
*
*
* -
*
* scale
: If the input type is an Image, you need to provide a scale factor.
*
*
*
*
* CoreML ClassifierConfig
parameters can be specified using
* OutputConfig$CompilerOptions. CoreML converter supports Tensorflow and PyTorch models. CoreML
* conversion examples:
*
*
* -
*
* Tensor type input:
*
*
* -
*
* "DataInputConfig": {"input_1": {"shape": [[1,224,224,3], [1,160,160,3]], "default_shape": [1,224,224,3]}}
*
*
*
*
* -
*
* Tensor type input without input name (PyTorch):
*
*
* -
*
* "DataInputConfig": [{"shape": [[1,3,224,224], [1,3,160,160]], "default_shape": [1,3,224,224]}]
*
*
*
*
* -
*
* Image type input:
*
*
* -
*
* "DataInputConfig": {"input_1": {"shape": [[1,224,224,3], [1,160,160,3]], "default_shape": [1,224,224,3], "type": "Image", "bias": [-1,-1,-1], "scale": 0.007843137255}}
*
*
* -
*
* "CompilerOptions": {"class_labels": "imagenet_labels_1000.txt"}
*
*
*
*
* -
*
* Image type input without input name (PyTorch):
*
*
* -
*
* "DataInputConfig": [{"shape": [[1,3,224,224], [1,3,160,160]], "default_shape": [1,3,224,224], "type": "Image", "bias": [-1,-1,-1], "scale": 0.007843137255}]
*
*
* -
*
* "CompilerOptions": {"class_labels": "imagenet_labels_1000.txt"}
*
*
*
*
*
*
* Depending on the model format, DataInputConfig
requires the following parameters for
* ml_eia2
OutputConfig:TargetDevice.
*
*
* -
*
* For TensorFlow models saved in the SavedModel format, specify the input names from
* signature_def_key
and the input model shapes for DataInputConfig
. Specify
* the signature_def_key
in OutputConfig:CompilerOptions
if the model does not use TensorFlow's default
* signature def key. For example:
*
*
* -
*
* "DataInputConfig": {"inputs": [1, 224, 224, 3]}
*
*
* -
*
* "CompilerOptions": {"signature_def_key": "serving_custom"}
*
*
*
*
* -
*
* For TensorFlow models saved as a frozen graph, specify the input tensor names and shapes in
* DataInputConfig
and the output tensor names for output_names
in OutputConfig:CompilerOptions
. For example:
*
*
* -
*
* "DataInputConfig": {"input_tensor:0": [1, 224, 224, 3]}
*
*
* -
*
* "CompilerOptions": {"output_names": ["output_tensor:0"]}
*
*
*
*
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder dataInputConfig(String dataInputConfig);
/**
*
* Identifies the framework in which the model was trained. For example: TENSORFLOW.
*
*
* @param framework
* Identifies the framework in which the model was trained. For example: TENSORFLOW.
* @see Framework
* @return Returns a reference to this object so that method calls can be chained together.
* @see Framework
*/
Builder framework(String framework);
/**
*
* Identifies the framework in which the model was trained. For example: TENSORFLOW.
*
*
* @param framework
* Identifies the framework in which the model was trained. For example: TENSORFLOW.
* @see Framework
* @return Returns a reference to this object so that method calls can be chained together.
* @see Framework
*/
Builder framework(Framework framework);
/**
*
* Specifies the framework version to use.
*
*
* This API field is only supported for PyTorch framework versions 1.4
, 1.5
, and
* 1.6
for cloud instance target devices: ml_c4
, ml_c5
,
* ml_m4
, ml_m5
, ml_p2
, ml_p3
, and ml_g4dn
.
*
*
* @param frameworkVersion
* Specifies the framework version to use.
*
* This API field is only supported for PyTorch framework versions 1.4
, 1.5
,
* and 1.6
for cloud instance target devices: ml_c4
, ml_c5
,
* ml_m4
, ml_m5
, ml_p2
, ml_p3
, and
* ml_g4dn
.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder frameworkVersion(String frameworkVersion);
}
static final class BuilderImpl implements Builder {
private String s3Uri;
private String dataInputConfig;
private String framework;
private String frameworkVersion;
private BuilderImpl() {
}
private BuilderImpl(InputConfig model) {
s3Uri(model.s3Uri);
dataInputConfig(model.dataInputConfig);
framework(model.framework);
frameworkVersion(model.frameworkVersion);
}
public final String getS3Uri() {
return s3Uri;
}
@Override
public final Builder s3Uri(String s3Uri) {
this.s3Uri = s3Uri;
return this;
}
public final void setS3Uri(String s3Uri) {
this.s3Uri = s3Uri;
}
public final String getDataInputConfig() {
return dataInputConfig;
}
@Override
public final Builder dataInputConfig(String dataInputConfig) {
this.dataInputConfig = dataInputConfig;
return this;
}
public final void setDataInputConfig(String dataInputConfig) {
this.dataInputConfig = dataInputConfig;
}
public final String getFramework() {
return framework;
}
@Override
public final Builder framework(String framework) {
this.framework = framework;
return this;
}
@Override
public final Builder framework(Framework framework) {
this.framework(framework == null ? null : framework.toString());
return this;
}
public final void setFramework(String framework) {
this.framework = framework;
}
public final String getFrameworkVersion() {
return frameworkVersion;
}
@Override
public final Builder frameworkVersion(String frameworkVersion) {
this.frameworkVersion = frameworkVersion;
return this;
}
public final void setFrameworkVersion(String frameworkVersion) {
this.frameworkVersion = frameworkVersion;
}
@Override
public InputConfig build() {
return new InputConfig(this);
}
@Override
public List> sdkFields() {
return SDK_FIELDS;
}
}
}