public class Model extends Resource
Resource based on the main model spec. This extends Resource to provide more information relevant for to machine learning models.
  • Constructor Details

    • Model

      public Model()
  • Method Details

    • setBaseURI

      public void setBaseURI(URI baseURI)
    • setUri

      public void setUri(URI uri)
    • parse

      public static Model parse(File file) throws IOException
      Parse a model from a file or directory. This can either be a yaml file, or a directory that contains a yaml file representing the model.
      Parameters:
      file - The file containing the YAML, or its parent directory.
      Returns:
      The parsed model.
      Throws:
      IOException - if the model cannot be found or parsed
    • parse

      public static Model parse(Path path) throws IOException
      Parse a model from a path. This can either represent a yaml file, or a directory that contains a yaml file representing the model.
      Parameters:
      path - The path to the file containing the YAML, or its parent directory.
      Returns:
      The parsed model.
      Throws:
      IOException - if the model cannot be found or parsed
    • parse

      public static Model parse(InputStream stream) throws IOException
      Parse a model from an input stream. Note that getBaseURI() will return null in this case, because the base URI is unknown.
      Parameters:
      stream - A stream of YAML.
      Returns:
      The parsed model.
      Throws:
      IOException - if the model cannot be found or parsed
    • getBaseURI

      public URI getBaseURI()
      Get the base URI, providing the location of the model. This is typically a URI representing the downloaded model directory (the parent of getURI()). This may also represent a zipped file, if the model is read without unzipping the contents.
      Returns:
      The URI to the model file.
    • getURI

      public URI getURI()
      Get the URI providing the location of the model. This is typically a URI representing the yaml file for the model.
      Returns:
      The URI to the model file.
    • getWeights

      public Map<String,Weights.ModelWeights> getWeights()
      Get a map view of the weights. It's generally better to use getWeights(Weights.WeightsEntry key).
      Returns:
      a map view of the weights.
    • getWeights

      public Weights.ModelWeights getWeights(Weights.WeightsEntry key)
      Alternative to getWeights() that corrects for keys that have been renamed.
      Parameters:
      key - The query key.
      Returns:
      The weights value, or null if not found.
    • getWeights

      public Weights.ModelWeights getWeights(String key)
      Alternative to getWeights()} using a string key.
      Parameters:
      key - The query key string.
      Returns:
      The weights value, or null if not found.
    • getParent

      public ModelParent getParent()
      The model from which this model is derived, e.g. by fine-tuning the weights.
      Returns:
      The parent model.
    • getTimestamp

      public String getTimestamp()
      Timestamp in #ISO 8601) format with a few restrictions listed in the python docs).
      Returns:
      The timestamp.
    • getConfig

      public Map<?,?> getConfig()
      A field for custom configuration that can contain any keys not present in the RDF spec. This means you should not store, for example, a GitHub repo URL in `config` since there is a `git_repo` field. Keys in `config` may be very specific to a tool or consumer software. To avoid conflicting definitions, it is recommended to wrap added configuration into a sub-field named with the specific domain or tool name, for example: ```yaml config: bioimageio: # here is the domain name my_custom_key: 3837283 another_key: nested: value imagej: # config specific to ImageJ macro_dir: path/to/macro/file ``` If possible, please use snake_case for keys in `config`. You may want to list linked files additionally under `attachments` to include them when packaging a resource. (Packaging a resource means downloading/copying important linked files and creating a ZIP archive that contains an altered rdf.yaml file with local references to the downloaded files.)
      Returns:
      the config
    • getInputs

      public List<InputTensor> getInputs()
      Get the input tensors
      Returns:
      the list of inputs
    • getOutputs

      public List<OutputTensor> getOutputs()
      Get the output tensors
      Returns:
      the list of output tensors
    • getTestInputs

      public List<String> getTestInputs()
      Test input tensors compatible with the `inputs` description for a **single test case**. This means if your model has more than one input, you should provide one URL/relative path for each input. Each test input should be a file with an ndarray in hnumpy.lib file format The extension must be '.npy'.
      Returns:
      The test inputs.
    • getTestOutputs

      public List<String> getTestOutputs()
      Test output tensors compatible with the `output` description for a **single test case**. This means if your model has more than one output, you should provide one URL/relative path for each output. Each test output should be a file with an ndarray in hnumpy.lib file format The extension must be '.npy'.
      Returns:
      The test outputs.
    • getSampleInputs

      public List<String> getSampleInputs()
      URLs/relative paths to sample outputs corresponding to the `sample_inputs`.
      Returns:
      the sample inputs.
    • getSampleOutputs

      public List<String> getSampleOutputs()
      URLs/relative paths to sample outputs corresponding to the `sample_outputs`.
      Returns:
      the sample outputs.
    • toUnmodifiableList

      public static <T> List<T> toUnmodifiableList(List<T> list)
      Ensure the input is an unmodifiable list, or empty list if null. Note that OpenJDK implementation is expected to return its input if already unmodifiable.
      Type Parameters:
      T - The type of list objects.
      Parameters:
      list - The input list.
      Returns:
      An unmodifiable list.
    • deserializeField

      public static <T> T deserializeField(com.google.gson.JsonDeserializationContext context, com.google.gson.JsonObject obj, String name, Type typeOfT, boolean doStrict) throws IllegalArgumentException
      Deserialize a field from a JSON object.
      Type Parameters:
      T - The type of the field.
      Parameters:
      context - The context used for deserialization.
      obj - The JSON object that contains the field.
      name - The name of the field.
      typeOfT - The type of the field.
      doStrict - if true, fail if the field is missing; otherwise, return null
      Returns:
      A parsed T object.
      Throws:
      IllegalArgumentException - if doStrict is true and the field is not found
    • deserializeField

      public static <T> T deserializeField(com.google.gson.JsonDeserializationContext context, com.google.gson.JsonObject obj, String name, Type typeOfT, T defaultValue)
      Deserialize a field from a JSON object.
      Type Parameters:
      T - The type of the field.
      Parameters:
      context - The context used for deserialization.
      obj - The JSON object that contains the field.
      name - The name of the field.
      typeOfT - The type of the field.
      Returns:
      A parsed T object.
      Throws:
      IllegalArgumentException - if doStrict is true and the field is not found