Exemplo n.º 1
0
    def predict_proba(self, connector, batch_size=128):

        nclasses = self.service_parameters_mllib["nclasses"]
        self.predict_parameters_input = connector.predict_parameters_input

        self.predict_parameters_mllib = {
            "gpu": self.service_parameters_mllib["gpu"],
            "net": {"test_batch_size": batch_size}}
        if self.gpu:
            self.predict_parameters_mllib.update({"gpuid": self.gpuid})

        self.predict_parameters_output = {"best": nclasses}

        if connector.name == "svm":
            data = [connector.path]

        if connector.name == "lmdb":
            data = [connector.path]

        elif connector.name == "array":
            if type(connector.X) == np.ndarray:
                data = ndarray_to_sparse_strings(connector.X)
            elif sparse.issparse(connector.X):
                data = sparse_to_sparse_strings(connector.X)

        y_score = self._predict_proba(data,
                                      connector.predict_parameters_input,
                                      self.predict_parameters_mllib,
                                      self.predict_parameters_output)

        return y_score
Exemplo n.º 2
0
    def predict_proba(self, X):

        data = [X]
        if type(X) == np.ndarray:
            data = ndarray_to_sparse_strings(X)
        elif sparse.issparse(X):
            data = sparse_to_sparse_strings(X)

        nclasses = self.service_parameters_mllib['nclasses']
        self.predict_parameters_input = {}
        self.predict_parameters_mllib = {
            "gpu": self.service_parameters_mllib['gpu'],
            "gpuid ": self.service_parameters_mllib['gpuid']
        }
        self.predict_parameters_output = {'best': nclasses}

        json_dump = self.post_predict(self.sname, data,
                                      self.predict_parameters_input,
                                      self.predict_parameters_mllib,
                                      self.predict_parameters_output)

        self.answers.append(json_dump)
        with open("{}/model.json".format(self.model['repository'])) as f:
            self.calls = [json.loads(line, encoding='utf-8') for line in f]

        y_score = to_array(json_dump, nclasses)

        return y_score