Get Model
-
get_model
(self, model_id: str) → Union[netspresso.compressor.core.model.Model, netspresso.compressor.core.model.CompressedModel] Get the model for a given model ID.
- Parameters
model_id (str) – The ID of the model.
- Raises
e – If an error occurs while getting the model.
- Returns
The retrieved model. If the model is compressed, CompressedModel will be returned. Otherwise, Model will be returned.
- Return type
Union[Model, CompressedModel]
Details of Returns
-
class
Model
(model_id: str, model_name: str, task: str, framework: str, model_size: float, flops: float, trainable_parameters: float, non_trainable_parameters: float, number_of_layers: int, input_shapes: List[netspresso.compressor.core.model.InputShape] = <factory>)[source] Represents a uploaded model.
-
model_id
The ID of the model.
- Type
str
-
model_name
The name of the model.
- Type
str
-
input_shapes
The input shapes of the model.
- InputShape Attributes:
batch (int): The batch size of the input tensor.
channel (int): The number of channels in the input tensor.
dimension (List[int]): The dimensions of the input tensor.
- Type
List[InputShape]
-
model_size
The size of the model.
- Type
float
-
flops
The FLOPs (floating point operations) of the model.
- Type
float
-
trainable_parameters
The number of trainable parameters in the model.
- Type
float
-
non_trainable_parameters
The number of non-trainable parameters in the model.
- Type
float
-
number_of_layers
The number of layers in the model.
- Type
float
-
-
class
CompressedModel
(model_id: str, model_name: str, task: str, framework: str, model_size: float, flops: float, trainable_parameters: float, non_trainable_parameters: float, number_of_layers: int, input_shapes: List[netspresso.compressor.core.model.InputShape] = <factory>, compression_id: str = '', original_model_id: str = '')[source] Bases:
netspresso.compressor.core.model.Model
Represents a compressed model.
-
compression_id
The ID of the compression.
- Type
str
-
original_model_id
The ID of the uploaded model.
- Type
str
-
Example
If the model is uploaded model
from netspresso.compressor import ModelCompressor
compressor = ModelCompressor(email="YOUR_EMAIL", password="YOUR_PASSWORD")
model = compressor.get_model(model_id="YOUR_UPLOADED_MODEL_ID")
Output
>>> model
Model(
model_id="YOUR_MODEL_ID",
model_name="YOUR_MODEL_NAME",
task="image_classification",
framework="tensorflow_keras",
input_shapes=[InputShape(batch=1, channel=3, dimension=[32, 32])],
model_size=12.9641,
flops=92.8979,
trainable_parameters=3.3095,
non_trainable_parameters=0.0219,
number_of_layers=0,
)
If the model is compressed model
from netspresso.compressor import ModelCompressor
compressor = ModelCompressor(email="YOUR_EMAIL", password="YOUR_PASSWORD")
model = compressor.get_model(model_id="YOUR_COMPRESSED_MODEL_ID")
Output
>>> model
CompressedModel(
model_id="YOUR_MODEL_ID",
model_name="YOUR_COMPRESSED_MODEL_NAME",
task="image_classification",
framework="tensorflow_keras",
input_shapes=[InputShape(batch=1, channel=3, dimension=[32, 32])],
model_size=2.9439,
flops=24.1811,
trainable_parameters=0.6933,
non_trainable_parameters=0.01,
number_of_layers=0,
compression_id="ce584e7f-b76e-43cc-83fe-d140fe476a58",
original_model_id="f482a0d3-0321-49a4-a8d2-bd88ac124230"
)