Inherits NetworkObject.
Represents a machine learning model object on Coretex.ai
Contains properties that describe the model
Properties
----------
name : str
model name
createdById : str
id of model
createdOn : datetime
date of model creation
datasetId : int
dataset id that is used for training the model
spaceId : int
space id that is used for training the model
projectId : int
project id that is used for training the model
isTrained : bool
True if model is trained, False otherwise
isDeleted : bool
True if model is deleted, False otherwise
accuracy : float
model accuracy
experimentId : int
experiment id of trained model
meta : Dict[str, Any]
model meta data
Definition at line 33 of file model.py.
Self coretex.coretex.model.model.Model.createModel |
( |
|
cls, |
|
|
str |
name, |
|
|
int |
experimentId, |
|
|
float |
accuracy, |
|
|
Dict[str, Any] |
meta |
|
) |
| |
Creates Model object of the provided experiment with specified properties
Parameters
----------
name : str
model name
experimentId : int
experiment id of model
accuracy : float
model accuracy
meta : Dict[str, Any]
model meta data
Returns
-------
Self -> Model object
Example
-------
>>> from coretex import Model, ExecutingExperiment
\b
>>> experiment = ExecutingExperiment.current()
>>> model = Model.createModel(
name = experiment.name,
experimentId = experiment.id,
accuracy = 0.87,
meta = {}
)
Definition at line 95 of file model.py.
95 def createModel(cls, name: str, experimentId: int, accuracy: float, meta: Dict[str, Any]) -> Self:
97 Creates Model object of the provided experiment with specified properties
104 experiment id of model
107 meta : Dict[str, Any]
116 >>> from coretex import Model, ExecutingExperiment
118 >>> experiment = ExecutingExperiment.current()
119 >>> model = Model.createModel(
120 name = experiment.name,
121 experimentId = experiment.id,
127 model = cls.create(parameters = {
129 "model_queue_id": experimentId,
130 "accuracy": accuracy,
135 raise ValueError(
">> [Coretex] Failed to create Model entity")
None coretex.coretex.model.model.Model.saveModelDescriptor |
( |
|
cls, |
|
|
str |
path, |
|
|
Dict[str, Any] |
contents |
|
) |
| |
Saves a model descriptor - a JSON file that provides a description of a
machine learning model. It includes information such as the model's
architecture, input and output shapes, labels, description and etc.
Example
-------
>>> from coretex import ExecutingExperiment, Model
>>> model = Model.createModel(experiment.name, experiment.id, accuracy, {})
>>> model.saveModelDescriptor(modelPath, {
"project_task": experiment.spaceTask,
"labels": labels,
"modelName": model.name,
"description": experiment.description,
"input_description":
Input shape is [x, y]
x is actually number of samples in dataset\n
y represents number of unique taxons for selected level in dataset,
"input_shape": [x, y],
"output_description":
Output shape - [x, z]
x is actually number of samples in dataset\n
z represents that output 2d array (table) is going to have only 1 column (1 prediction for each sample in dataset),
"output_shape": [x, z]
})
Definition at line 140 of file model.py.
140 def saveModelDescriptor(cls, path: str, contents: Dict[str, Any]) ->
None:
142 Saves a model descriptor - a JSON file that provides a description of a
143 machine learning model. It includes information such as the model's
144 architecture, input and output shapes, labels, description and etc.
148 >>> from coretex import ExecutingExperiment, Model
149 >>> model = Model.createModel(experiment.name, experiment.id, accuracy, {})
150 >>> model.saveModelDescriptor(modelPath, {
151 "project_task": experiment.spaceTask,
153 "modelName": model.name,
154 "description": experiment.description,
157 Input shape is [x, y]
159 x is actually number of samples in dataset\n
160 y represents number of unique taxons for selected level in dataset,
162 "input_shape": [x, y],
164 "output_description":
165 Output shape - [x, z]
167 x is actually number of samples in dataset\n
168 z represents that output 2d array (table) is going to have only 1 column (1 prediction for each sample in dataset),
170 "output_shape": [x, z]
174 modelDescriptorPath = os.path.join(path, cls.modelDescriptorFileName())
176 with open(modelDescriptorPath,
"w", encoding =
"utf-8")
as file:
177 json.dump(contents, file, ensure_ascii =
False, indent = 4)
bool coretex.coretex.model.model.Model.upload |
( |
|
self, |
|
|
str |
path |
|
) |
| |
Uploads the model zip file to Coretex.ai
Parameters
----------
path : str
Path to the saved model dir
Returns
-------
bool -> True if model data uploaded successfully, False if model data upload has failed
Example
-------
>>> from coretex import Model, ExecutingExperiment
\b
>>> experiment: ExecutingExperiment[NetworkDataset] = ExecutingExperiment.current()
>>> model = Model.createModel(
name = experiment.name,
experimentId = experiment.id,
accuracy = 0.87,
meta = {}
)
>>> if not model.upload("path/to/model-dir"):
print("Failed to upload model")
Definition at line 207 of file model.py.
207 def upload(self, path: str) -> bool:
209 Uploads the model zip file to Coretex.ai
214 Path to the saved model dir
218 bool -> True if model data uploaded successfully, False if model data upload has failed
223 >>> from coretex import Model, ExecutingExperiment
225 >>> experiment: ExecutingExperiment[NetworkDataset] = ExecutingExperiment.current()
226 >>> model = Model.createModel(
227 name = experiment.name,
228 experimentId = experiment.id,
232 >>> if not model.upload("path/to/model-dir"):
233 print("Failed to upload model")
239 logging.getLogger(
"coretexpylib").info(
">> [Coretex] Uploading model file...")
241 shutil.make_archive(path,
"zip", path)
244 (
"file", open(f
"{path}.zip",
"rb"))
251 response = networkManager.genericUpload(
"model/upload", files, parameters)
252 if response.hasFailed():
253 logging.getLogger(
"coretexpylib").info(
">> [Coretex] Failed to upload model file")
255 logging.getLogger(
"coretexpylib").info(
">> [Coretex] Uploaded model file")
257 return not response.hasFailed()