Model
Contents
Model#
A learnware is a well-performed trained model with a specification, where the model is an indispensable component of the learnware.
In this section, we will introduce the model module implemented within learnware
package. We will first introduce the BaseModel
, which defines the standard format for models in the learnware
package. Following that, we will introduce the ModelContainer
, which implements model deployment in conda virtual environments and Docker containers.
BaseModel#
The BaseModel
class is a fundamental component of the learnware package which provides standardized interface for model training, prediction and fine-tuning.
This class is created to make it easier for users to submit learnwares to the market.
It helps ensure that submitted models follow a clear set of rules and requirements.
All user models should inherit the BaseModel
class. Here’s a more detailed explanation of key components:
input_shape
: Specify the shape of the input features your model expects.output_shape
: Define the shape of the output predictions generated by your model.predict
: Implement the predict method to make predictions using your model.fit
(optional): Use the fit method for training a model with input data and labels.finetune
(optional): Utilize the finetune method for further adjusting pre-existing models sourced from the market.
By adhering to these standards, the compatibility and quality of submitted learnwares in the market are ensured.
ModelContainer#
The ModelContainer
class is an essential component of the learnware package, designed to facilitate the management, deployment, and execution of machine learning models within a containerized environment.
It inherits from the BaseModel
class and extends its functionality to encapsulate model deployment and execution.
ModelCondaContainer#
The ModelCondaContainer
class is an extension of the ModelContainer
class within the learnware package.
Its primary purpose is to enable the management, deployment, and execution of machine learning models in a containerized environment, with a specific focus on using Conda virtual environments.
This class inherits functionality from ModelContainer
while providing additional capabilities related to Conda-based model execution.
Specifically, the ModelCondaContainer
supports the automatic creation of new Conda virtual environments based on the requirements.txt
file (for pip installation) or environment.yaml
file (for Conda installation) included within the learnware itself.
It also installs the environment dependencies of the learnware, enabling it to run.
ModelDockerContainer#
The ModelDockerContainer
class is a specialized extension of the ModelContainer
class within the learnware package.
It is designed to manage, deploy, and execute machine learning models within a containerized environment, specifically using Docker containers.
This class inherits functionality from ModelContainer
and enhances it with features related to Docker-based model execution.
Compared to ModelCondaContainer
, ModelDockerContainer
confines the model’s execution within a Docker container.
It installs the learnware’s virtual environment inside the Docker container, isolating the learnware’s execution from the host machine, thus enhancing the security of the learnware.
Similar to the ModelCondaContainer
class, the ModelDockerContainer
class also supports both types of environment dependency files for learnware: requirements.txt
for pip-based installation and environment.yaml
for conda-based installation.
It automates the creation of Docker containers and the installation of learnware’s environment dependencies within the container, enabling the learnware to run.