def predict(self, x: Tensor, device=None) -> PredictResults: if self._model is not None: if hasattr(self._model, "predict_proba"): proba = torch.as_tensor( # pyre-fixme[16]: `None` has no attribute `predict_proba`. self._model.predict_proba(x), dtype=torch.float, device=device, ) score = (proba * torch.arange(proba.shape[1])).sum(dim=1) return PredictResults(torch.argmax(proba, 1), score, proba) elif hasattr(self._model, "predict"): return PredictResults( None, torch.as_tensor( # pyre-fixme[16]: `None` has no attribute `predict`. self._model.predict(x), dtype=torch.float, device=device, ), None, ) else: raise AttributeError( "model doesn't have predict_proba or predict") else: raise Exception("model not trained")
def predict(self, x: Tensor, device=None) -> PredictResults: if self._model is not None: self._model.eval() proba = torch.as_tensor(self._model(x), dtype=torch.float, device=device) return PredictResults(torch.argmax(proba, 1), proba) else: raise Exception("mode not trained")
def predict(self, x: Tensor, device=None) -> PredictResults: if self._model is not None: # pyre-fixme[16]: `None` has no attribute `eval`. self._model.eval() # pyre-fixme[29]: `None` is not a function. proba = torch.as_tensor(self._model(x), dtype=torch.float, device=device) return PredictResults(torch.argmax(proba, 1), proba) else: raise Exception("mode not trained")