def __init__(self, model=None, model_id=None, name=None, version=None, experiment=None, labels='', verbose=False, create=True): if create: if isinstance(model, str) and os.path.isfile(model): model_file_name = model else: if hasattr(model, 'save'): model_file_name = 'temp_model.h5' if os.path.isfile(model_file_name): os.remove(model_file_name) model.save(model_file_name) else: raise Exception('Invalid model: ' + str(model)) if not experiment: self.skil = skil.Skil.from_config() self.work_space = skil.workspaces.WorkSpace(self.skil) self.experiment = skil.experiments.Experiment(self.work_space) else: self.experiment = experiment self.work_space = experiment.work_space self.skil = self.work_space.skil self.skil.upload_model(os.path.join(os.getcwd(), model_file_name)) self.model_path = self.skil.get_model_path(model_file_name) self.id = model_id if model_id else str(uuid.uuid1()) self.name = name if name else model_file_name self.version = version if version else 1 self.evaluations = {} self.deployment = None self.model_deployment = None add_model_instance_response = self.skil.api.add_model_instance( self.skil.server_id, skil_client.ModelInstanceEntity( uri=self.model_path, model_id=self.id, model_labels=labels, model_name=name, model_version=self.version, created=int(round(time.time() * 1000)), experiment_id=self.experiment.id ) ) if verbose: self.skil.printer.pprint(add_model_instance_response) else: self.experiment = experiment self.work_space = experiment.work_space self.skil = self.work_space.skil assert model_id is not None self.id = model_id model_entity = self.skil.api.get_model_instance(self.skil.server_id, self.id) self.name = model_entity.model_name self.version = model_entity.model_version self.model_path = model_entity.uri self.service = None
def __init__(self, model_file_name, id=None, name=None, version=None, experiment=None, labels='', verbose=False): if not experiment: self.skil = skil.Skil() self.work_space = skil.workspaces.WorkSpace(self.skil) self.experiment = skil.experiments.Experiment(self.work_space) else: self.experiment = experiment self.work_space = experiment.work_space self.skil = self.work_space.skil self.skil.upload_model(os.path.join(os.getcwd(), model_file_name)) self.model_name = model_file_name self.model_path = self.skil.get_model_path(model_file_name) self.id = id if id else uuid.uuid1() self.name = name if name else model_file_name self.version = version if version else 1 self.evaluations = {} add_model_instance_response = self.skil.api.add_model_instance( self.skil.server_id, skil_client.ModelInstanceEntity(uri=self.model_path, model_id=id, model_labels=labels, model_name=name, model_version=self.version, created=int( round(time.time() * 1000)), experiment_id=self.experiment.id)) if verbose: self.skil.printer.pprint(add_model_instance_response)
def __init__(self, transform=None, transform_type="CSV", transform_id=None, name=None, version=None, experiment=None, labels='', verbose=False, create=True): super(Transform, self).__init__() if create: if isinstance(transform, str) and os.path.isfile(transform): transform_file_name = transform else: if hasattr(transform, 'to_java'): transform_file_name = 'temp_transform.json' if os.path.isfile(transform_file_name): os.remove(transform_file_name) with open(transform_file_name, 'w') as f: f.write(transform.to_java().toJson()) else: raise Exception('Invalid TransformProcess: ' + str(transform)) if not experiment: self.skil = skil.Skil.from_config() self.work_space = skil.workspaces.WorkSpace(self.skil) self.experiment = skil.experiments.Experiment(self.work_space) else: self.experiment = experiment self.work_space = experiment.work_space self.skil = self.work_space.skil self.skil.upload_model( os.path.join(os.getcwd(), transform_file_name)) self.model_path = self.skil.get_model_path(transform_file_name) self.id = transform_id if transform_id else str(uuid.uuid1()) self.name = name if name else transform_file_name self.version = version if version else 1 self.evaluations = {} self.deployment = None self.model_deployment = None add_model_instance_response = self.skil.api.add_model_instance( self.skil.server_id, skil_client.ModelInstanceEntity( uri=self.model_path, model_id=self.id, model_labels=labels, model_name=name, model_version=self.version, created=int(round(time.time() * 1000)), experiment_id=self.experiment.id)) if verbose: self.skil.printer.pprint(add_model_instance_response) else: self.experiment = experiment self.work_space = experiment.work_space self.skil = self.work_space.skil assert transform_id is not None self.id = transform_id model_entity = self.skil.api.get_model_instance( self.skil.server_id, self.id) self.name = model_entity.model_name self.version = model_entity.model_version self.model_path = model_entity.uri self.transform_type = transform_type self.service = None