Текущая реализация:
Код: Выделить всё
def predict(self, x):
self.model.eval()
x_tensor = torch.as_tensor(x).float()
y_hat_tensor = self.model(x_tensor.to(self.device))
self.model.train()
return y_hat_tensor.detach().cpu().numpy()
Код: Выделить всё
def predict(self, x):
self.model.eval()
x_tensor = torch.as_tensor(x).float()
with torch.inference_mode():
y_hat_tensor = self.model(x_tensor.to(self.device))
self.model.train()
return y_hat_tensor.detach().cpu().numpy() # detach() is superfluous
Однако я не уверен, почему исходная реализация его не включает. Каковы здесь лучшие практики?
Подробнее здесь: https://stackoverflow.com/questions/798 ... sing-model
Мобильная версия