java.lang.Object
qupath.bioimageio.spec.Resource
qupath.bioimageio.spec.Model
Resource based on the main model spec.
This extends
Resource to provide more information
relevant for to machine learning models.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TdeserializeField(com.google.gson.JsonDeserializationContext context, com.google.gson.JsonObject obj, String name, Type typeOfT, boolean doStrict) Deserialize a field from a JSON object.static <T> TdeserializeField(com.google.gson.JsonDeserializationContext context, com.google.gson.JsonObject obj, String name, Type typeOfT, T defaultValue) Deserialize a field from a JSON object.Get the base URI, providing the location of the model.Map<?,?> A field for custom configuration that can contain any keys not present in the RDF spec.Get the input tensorsGet the output tensorsThe model from which this model is derived, e.g.URLs/relative paths to sample outputs corresponding to the `sample_inputs`.URLs/relative paths to sample outputs corresponding to the `sample_outputs`.Test input tensors compatible with the `inputs` description for a **single test case**.Test output tensors compatible with the `output` description for a **single test case**.Timestamp in #ISO 8601) format with a few restrictions listed in the python docs).getURI()Get the URI providing the location of the model.Get a map view of the weights.getWeights(String key) Alternative togetWeights()} using a string key.Alternative togetWeights()that corrects for keys that have been renamed.static ModelParse a model from a file or directory.static Modelparse(InputStream stream) Parse a model from an input stream.static ModelParse a model from a path.voidsetBaseURI(URI baseURI) voidstatic <T> List<T>toUnmodifiableList(List<T> list) Ensure the input is an unmodifiable list, or empty list if null.Methods inherited from class qupath.bioimageio.spec.Resource
getAttachments, getAuthors, getBadges, getCite, getCovers, getDescription, getDocumentation, getFormatVersion, getGitRepo, getIcon, getID, getLicense, getLinks, getMaintainers, getName, getSource, getTags, getVersion, isFormatNewerThan
-
Constructor Details
-
Model
public Model()
-
-
Method Details
-
setBaseURI
-
setUri
-
parse
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
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
Parse a model from an input stream. Note thatgetBaseURI()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
Get the base URI, providing the location of the model. This is typically a URI representing the downloaded model directory (the parent ofgetURI()). This may also represent a zipped file, if the model is read without unzipping the contents.- Returns:
- The URI to the model file.
-
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
Get a map view of the weights. It's generally better to usegetWeights(Weights.WeightsEntry key).- Returns:
- a map view of the weights.
-
getWeights
Alternative togetWeights()that corrects for keys that have been renamed.- Parameters:
key- The query key.- Returns:
- The weights value, or null if not found.
-
getWeights
Alternative togetWeights()} using a string key.- Parameters:
key- The query key string.- Returns:
- The weights value, or null if not found.
-
getParent
The model from which this model is derived, e.g. by fine-tuning the weights.- Returns:
- The parent model.
-
getTimestamp
Timestamp in #ISO 8601) format with a few restrictions listed in the python docs).- Returns:
- The timestamp.
-
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
Get the input tensors- Returns:
- the list of inputs
-
getOutputs
Get the output tensors- Returns:
- the list of output tensors
-
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
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
URLs/relative paths to sample outputs corresponding to the `sample_inputs`.- Returns:
- the sample inputs.
-
getSampleOutputs
URLs/relative paths to sample outputs corresponding to the `sample_outputs`.- Returns:
- the sample outputs.
-
toUnmodifiableList
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
-