Beispiel #1
0
    def create(cls, exp_id, model_id):
        """Create :class:`Model` or :class:`MultiModel` depends on which
        instance type has called.

        Args:
            exp_id (str): The experiment ID of the model.
            model_id (str): ObjectId in 24 hex digits.

        Returns:
            :class:`~decanter.core.core_api.model.Model` or :class:`~decanter.\
            core.core_api.mode.MultiModel` object.

        Raises:
            AttributeError: Occurred when getting no results from decanter
                server when getting model's metadata.
        """
        model = cls()
        get_models_resp = check_response(model.get_model(exp_id,
                                                         model_id)).json()
        try:
            for attr, val in get_models_resp.items():
                if attr == CoreKeys.id.value:
                    attr = CoreKeys.id.name
                model.__dict__.update({attr: val})
        except AttributeError:
            logger.error('[Model] No result from decanter.core.')

        model.task_status = CoreStatus.DONE
        return model
Beispiel #2
0
    def show(self):
        """Show content of predict result.

        Returns:
            str: Content of PredictResult.
        """
        pred_txt = ''
        if self.is_success():
            pred_txt = check_response(
                self.core_service.get_data_file_by_id(self.id)).text
        else:
            logger.error('[%s] fail', self.__class__.__name__)
        return pred_txt
Beispiel #3
0
    def download_by_id(cls, model_id, model_path):
        """Download model file to local.

        Getting Mojo model zip file from decanter.core server and
        download to local.

        Args:
            model_id (str): ObjectId in 24 hex digits.
            model_path (str): Path to store zip mojo file.
        """
        resp = check_response(cls().download_model(model_id))
        zfile = open(model_path, 'wb')
        zfile.write(resp.content)
        zfile.close()
Beispiel #4
0
    def download(self, model_path):
        """Download model file to local.

        Download the trained mojo model from Model instance to
        local in the format of zip file.

        Args:
            model_path (str): Path to store zip mojo file.
        """
        if self.id is None:
            logger.info('[Model] %s model id is NoneType', self.name)
        resp = check_response(self.download_model(model_id=self.id))
        zfile = open(model_path, 'wb')
        zfile.write(resp.content)
        zfile.close()
Beispiel #5
0
    def show_df(self):
        """Show predict result in pandas dataframe.

        Returns:
            :class:`pandas.DataFrame`: Content of predict result.
        """
        pred_df = None
        if self.is_success():
            pred_csv = check_response(
                self.core_service.get_data_file_by_id(self.id))
            pred_csv = pred_csv.content.decode('utf-8')
            pred_df = pd.read_csv(io.StringIO(pred_csv))
        else:
            logger.error('[%s] fail', self.__class__.__name__)
        return pred_df
    def update(self, exp_id, model_id):
        """Update model attributes.

        Get and Set attributes from the response attribute from
        decanter server.
        """
        get_models_resp = check_response(
            self.get_model(exp_id, model_id)).json()
        try:
            for attr, val in get_models_resp.items():
                if attr == CoreKeys.id.value:
                    attr = CoreKeys.id.name
                self.__dict__.update({attr: val})
        except AttributeError:
            logger.error('[%s] No result from decanter.core.', self.__class__.__name__)

        self.task_status = CoreStatus.DONE
Beispiel #7
0
    def run_core_task(self, api_func, **kwargs):
        """Start running Decanter Core task by calling api_func.

        Args:
            api_func (func): CoreAPI function.
            kwargs: Parameters for api_func.
        """
        logger.debug('[%s] \'%s\' start.', self.__class__.__name__, self.name)
        self.response = check_response(api_func(**kwargs),
                                       key=CoreKeys.id.value)
        self.response = self.response.json()
        self.id = self.response[CoreKeys.id.value]
        self.pbar = tqdm(total=100,
                         position=CoreTask.BAR_CNT,
                         leave=True,
                         bar_format='{l_bar}{bar}',
                         desc='Progress %s' % self.name)
        CoreTask.BAR_CNT += 1

        self.status = CoreStatus.RUNNING