These options are the same across all model types. They are not required, but may make it easier for others to use your model.
See the docs for specific frameworks for options specific to those frameworks.
Select a programming language:
model_name
The name of the model.
await carton.pack( # ... model_name = "super_awesome_test_model",)
short_description
A short description (should be 100 characters or less)
await carton.pack( # ... short_description = "A short description that should be less than or equal to 100 characters.",)
model_description
A detailed description that can contain markdown
MODEL_DESCRIPTION = """Some description of the model that can be as detailed as you want it to be
This can span multiple lines. It can use markdown, but shouldn't use arbitrary HTML(which will usually be treated as text instead of HTML when this is rendered)
You can use images and links, but the paths must either be complete httpsURLs (e.g. https://example.com/image.png) or must reference a file in the misc folder (e.g `@misc/file.png`).See the `misc_files` section of this document for more details"""
await carton.pack( # ... model_description = MODEL_DESCRIPTION,)
license
The name of the license for this model. This should be an SPDX license expression. See https://spdx.org/licenses/ for more details.
If the model is not licensed under an SPDX recognized license, this can be an arbitrary string.
await carton.pack( # ... license = "Apache-2.0",)
repository
A URL for a repository for this model.
Note: this should be the repository containing the Carton packing code for this model. If this is different from the original model repository, consider setting homepage
below to the original model repository.
await carton.pack( # ... repository = "https://github.com/VivekPanyam/carton",)
homepage
A URL for a website that is the homepage for this model.
await carton.pack( # ... homepage = "https://carton.run",)
required_platforms
A list of platforms this model supports. If empty or unspecified, all platforms are okay.
await carton.pack( # ...
# The contents of this list are target triples. For example: # x86_64-unknown-linux-gnu # aarch64-unknown-linux-gnu # x86_64-apple-darwin # aarch64-apple-darwin required_platforms = [],)
inputs
TensorSpec
A list of inputs for the model. Each item is a TensorSpec
.
A TensorSpec
describes an input or output tensor of a model. It provides a name, data type, and shape of an input/output.
Note: If you specify one input or output, you must specify all inputs and outputs
from cartonml import TensorSpec
input_x = TensorSpec( # The name of the input or output name="x",
# The datatype of the tensor. Valid values are # - float32 # - float64 # - string # - int8 # - int16 # - int32 # - int64 # - uint8 # - uint16 # - uint32 # - uint64 dtype = "float32",
# A shape of none means the tensor can be of any shape shape = None,
# A shape with 3 dims of any value # Note: this also supports ragged/nested tensors # shape = [None, None, None],
# A shape of an exact size # shape = [2, 3, 512, 512],
# A scalar # shape = [],
# A shape containing a "symbol" # shape = ["batch_size", 3, 512, 512],
# A symbol is an arbitrary string that should resolve to the same value each time it's used. # (i.e. at runtime, every dimension of size "batch_size" should # resolve to the same concrete value)
# A symbol for the overall shape: # shape = "input_shape",
# Optional description = "The input image as a NCHW tensor")
await carton.pack( # ... inputs = [input_x],)
outputs
TensorSpec
A list of outputs for the model. Each item is a TensorSpec
. See the inputs
section above for more details.
Note: If you specify one input or output, you must specify all inputs and outputs
await carton.pack( # ... outputs = [],)
self_tests
SelfTest
A list of self tests. A SelfTest
is a set of inputs (and optionally outputs) that are stored alongside the model and can be used to run a test.
Note: inputs
and outputs
above must be specified in order to specify test data.
from cartonml import SelfTestimport numpy as np
st = SelfTest( # Optional name = "a_self_test",
# Optional description = "A self test",
# A dict mapping input tensor names to values inputs = dict(x = np.ones(5, dtype=np.float32)),
# Optional # If specified, the output will be compared using # something conceptually similar to np.allclose # Note: this comparison is not currently implemented, but may be in the future expected_out = dict(out = np.ones(5, dtype=np.float32) * 2))
await carton.pack( # ... self_tests = [st],)
examples
Example
A list of examples. An Example
is like a self-test, but it does not need to be runnable. Examples can reference numpy arrays, images, audio, etc.
These may be rendered in model documentation. See the MiscFile
section below for mode details on allowable file types.
Note: inputs
and outputs
above must be specified in order to specify examples.
from cartonml import Exampleimport numpy as np
# Read an input imagewith open('/path/to/input.png', 'rb') as f: input_image = f.read()
e = Example( # Optional name = "an_optional_name",
# Optional description = "An example for classification of an image",
# A dict mapping input tensor names to values inputs = dict(x = input_image),
# A dict mapping output tensor names to values sample_out = dict(out = np.array(5)))
await carton.pack( # ... examples = [e],)
misc_files
MiscFile
MiscFile
s are files referenced by markdown in the model_description
. They don't affect model behavior, but may be rendered in generated model documentation.
The following file types are allowed:
# ...
MODEL_DESCRIPTION = """This model has an interesting architecture:
![Model Architecture](@misc/model_architecture.png)"""
async def main(): with open('/path/to/model_architecture.png', 'rb') as f: model_architecture = f.read()
await carton.pack( # ... model_description = MODEL_DESCRIPTION, misc_files = { "model_architecture.png": model_architecture } )