cascade.models#
- class cascade.models.BasicModel(*args: Any, meta_prefix: Optional[Union[List[Dict[Any, Any]], str]] = None, description: Optional[str] = None, tags: Optional[Iterable[str]] = None, **kwargs: Any)[source]#
-
Basic model is a more concrete version of an abstract Model class. It provides common interface for all ML solutions. For more flexible interface refer to Model class.
See also
- evaluate(x: Any, y: Any, metrics: List[Union[Metric, Callable[[Any, Any], SupportsFloat]]], *args: Any, **kwargs: Any) None[source]#
-
Receives x and y validation sequences. Passes x to the model’s predict method along with any args or kwargs needed. Then updates self.metrics with what objects in
metricsreturn.metricsshould contain Metric with compute() method or callables with the interface: f(true, predicted) -> metric_value, where metric_value is a scalar- Parameters:
-
-
x (Any) – Input of the model.
-
y (Any) – Desired output to compare with the values predicted.
-
metrics (List[Union[Metric, Callable[[Any, Any], MetricType]]]) – List of metrics or callables to compute metric values
-
- fit(x: Any, y: Any, *args: Any, **kwargs: Any) None[source]#
-
Method to encapsulate training loops. May be provided with any training-related arguments.
- classmethod load(path: str) BasicModel[source]#
-
Loads the model from path provided. Path should be a folder
- load_artifact(path: str, *args: Any, **kwargs: Any) None[source]#
-
BasicModel implements this for compatibility. This method does nothing since there are no internal artifacts in BasicModel
- predict(x: Any, *args: Any, **kwargs: Any) Any[source]#
-
Method to encapsulate inference. May include preprocessing steps to make model self-sufficient.
- class cascade.models.BasicModelModifier(model: Model, *args: Any, **kwargs: Any)[source]#
-
Interface to unify BasicModel and ModelModifier.
- class cascade.models.Model(*args: Any, meta_prefix: Optional[Union[List[Dict[Any, Any]], str]] = None, description: Optional[str] = None, tags: Optional[Iterable[str]] = None, **kwargs: Any)[source]#
-
Base class for any model. Used to provide unified interface to any model, store metadata including metrics.
- __init__(*args: Any, meta_prefix: Optional[Union[List[Dict[Any, Any]], str]] = None, description: Optional[str] = None, tags: Optional[Iterable[str]] = None, **kwargs: Any) None[source]#
-
Should be called in any successor - initializes default meta needed.
Successors may pass all of their parameters to superclass for it to be able to log them in meta. Everything that is worth to track about the model can be put in params using this constructor or put in meta directly using update_meta().
- add_config()[source]#
-
If called inside cascade run <script> command will add config files of the run to this model and save it when the model is saved to line
Will warn if called outside of cascade run
- add_file(path: str, missing_ok: bool = False) None[source]#
-
Add additional file artifact to the model Copy the file to the model folder when saving model.
- add_log()[source]#
-
If called inside cascade run <script> command will add log file of the run to this model and save it when the model is saved to line
Will warn if called outside of cascade run
- add_log_callback(callback: Callable[[Model], None]) None[source]#
-
Registers a callback to be executed while logging metrics. Usually is used internally and is not initially intended as a public method
- Parameters:
-
callback (Callable[[Model], None]) – A function that accepts a model
See also
- add_metric(metric: Union[str, Metric], value: Optional[SupportsFloat] = None, **kwargs: Any) None[source]#
-
Adds metric value to the model. If metric already exists in the list, updates its value.
- Parameters:
- Raises:
-
-
ValueError – If in either value or metric.value is None
-
TypeError – If metric is of inappropriate type
-
- add_run_script()[source]#
-
If called inside cascade run <script> command will add actual script after overrides to this model and save it when the model is saved to line
Will warn if called outside of cascade run
- evaluate(*args: Any, **kwargs: Any) None[source]#
-
Evaluates model against any metrics. Should not return any value, just populate self.metrics
- fit(*args: Any, **kwargs: Any) None[source]#
-
Method to encapsulate training loops. May be provided with any training-related arguments.
- get_meta() List[Dict[Any, Any]][source]#
-
- Returns:
-
meta – A list where first element is this object’s metadata. All other elements represent the other stages of pipeline if present.
Meta can be anything that is worth to document about the object and its properties.
Meta is a list (see Meta type alias) to allow the formation of pipelines.
- Return type:
-
Meta
- link_dataset(ds: Dataset, name: Optional[str] = None, split: Optional[str] = None, line: Optional[Any] = None) None[source]#
-
Convenience function for linking datasets. Produces more readable meta files and records useful info without much hassle
- Parameters:
-
-
ds (Dataset) – Dataset to link
-
name (Optional[str], optional) – Dataset name, by default None
-
split (Optional[str], optional) – Split if applicable, may be “train”, “test”, etc, by default None
-
line (Optional[DataLine], optional) – DataLine where this dataset is stored if applicable, by default None
-
- classmethod load(path: str, *args: Any, **kwargs: Any) Model[source]#
-
Loads model from provided path
- load_artifact(path: str, *args: Any, **kwargs: Any) None[source]#
-
Loads standalone model’s artifact using provided filepath and sets it inside the model
- log() None[source]#
-
Sequentially calls every log callback. Use this if you want to make a checkpoint of a model from inside the model. Callback should be a function that given the model saves it. For example ModelLine.save method. ModelLine.create_model registers callback with only_meta=True automatically when creating a new model using
create_model.See also
cascade.models.ModelLine.create_model,cascade.models.Model.add_log_callback
- predict(*args: Any, **kwargs: Any) Any[source]#
-
Method to encapsulate inference. May include preprocessing steps to make model self-sufficient.
- save(path: str, *args: Any, **kwargs: Any) None[source]#
-
Does additional saving routines. Call this if you call save() in any subclass.
Creates the folder, copies file artifacts added by add_file automatically
- Parameters:
-
path (str) – Path to the model folder
- Raises:
-
-
ValueError – If the path is not a folder
-
FileNotFoundError – If the file that should be copied does not exists and it is not ok. See
add_filefor more info.
-
See also
- class cascade.models.ModelModifier(model: Model, *args: Any, **kwargs: Any)[source]#
-
The Dataset’s Modifier for Models. Can be used to chain two models in one.
- __init__(model: Model, *args: Any, **kwargs: Any) None[source]#
-
- Parameters:
-
model (Model) – A model to modify.
- get_meta() List[Dict[Any, Any]][source]#
-
- Returns:
-
meta – A list where first element is this object’s metadata. All other elements represent the other stages of pipeline if present.
Meta can be anything that is worth to document about the object and its properties.
Meta is a list (see Meta type alias) to allow the formation of pipelines.
- Return type:
-
Meta