def load_model(self): """ Load a btree index from the configured cache element. This only occurs if there is a cache element configured and there are bytes there to read. """ with self._model_lock: if self.cache_element and not self.cache_element.is_empty(): self._log.debug("Loading model from cache: %s", self.cache_element) buff = BytesIO(self.cache_element.get_bytes()) # noinspection PyTypeChecker with np.load(buff, allow_pickle=True) as cache: tail = tuple(cache['tail']) s = [ cache['data_arr'], cache['idx_array_arr'], cache['node_data_arr'], cache['node_bounds_arr'] ] s.extend(tail) s[11] = DistanceMetric.get_metric('hamming') s = tuple(s) # noinspection PyTypeChecker #: :type: sklearn.neighbors.BallTree self.bt = BallTree.__new__(BallTree) self.bt.__setstate__(s) self._log.debug("Loading mode: Done")
def load_model(self): if self.file_cache and os.path.isfile(self.file_cache): self._log.debug("Loading mode: %s", self.file_cache) with numpy.load(self.file_cache) as cache: tail = tuple(cache['tail']) s = (cache['data_arr'], cache['idx_array_arr'], cache['node_data_arr'], cache['node_bounds_arr']) +\ tail + (DistanceMetric.get_metric('hamming'),) #: :type: sklearn.neighbors.BallTree self.bt = BallTree.__new__(BallTree) self.bt.__setstate__(s) self._log.debug("Loading mode: Done")
def load_model(self): """ Load a btree index from the configured cache element. This only occurs if there is a cache element configured and there are bytes there to read. """ if self.cache_element and not self.cache_element.is_empty(): self._log.debug("Loading model from cache: %s", self.cache_element) buff = StringIO(self.cache_element.get_bytes()) with numpy.load(buff) as cache: tail = tuple(cache['tail']) s = (cache['data_arr'], cache['idx_array_arr'], cache['node_data_arr'], cache['node_bounds_arr']) +\ tail + (DistanceMetric.get_metric('hamming'),) #: :type: sklearn.neighbors.BallTree self.bt = BallTree.__new__(BallTree) self.bt.__setstate__(s) self._log.debug("Loading mode: Done")